blob: 6fb9eca9a9ce6832c52fb438a4a139a992f4790b [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Eric Fiselierbee782b2017-04-03 19:21:00 +000017#include "CoroutineStmtBuilder.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000020#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000021#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000025#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000029#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000030#include "clang/Sema/Designator.h"
31#include "clang/Sema/Lookup.h"
32#include "clang/Sema/Ownership.h"
33#include "clang/Sema/ParsedTemplate.h"
34#include "clang/Sema/ScopeInfo.h"
35#include "clang/Sema/SemaDiagnostic.h"
36#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000037#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000038#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000039#include <algorithm>
40
41namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000042using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000043
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// \brief A semantic tree transformation that allows one to transform one
45/// abstract syntax tree into another.
46///
Mike Stump11289f42009-09-09 15:08:12 +000047/// A new tree transformation is defined by creating a new subclass \c X of
48/// \c TreeTransform<X> and then overriding certain operations to provide
49/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000050/// instantiation is implemented as a tree transformation where the
51/// transformation of TemplateTypeParmType nodes involves substituting the
52/// template arguments for their corresponding template parameters; a similar
53/// transformation is performed for non-type template parameters and
54/// template template parameters.
55///
56/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000057/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000058/// override any of the transformation or rebuild operators by providing an
59/// operation with the same signature as the default implementation. The
60/// overridding function should not be virtual.
61///
62/// Semantic tree transformations are split into two stages, either of which
63/// can be replaced by a subclass. The "transform" step transforms an AST node
64/// or the parts of an AST node using the various transformation functions,
65/// then passes the pieces on to the "rebuild" step, which constructs a new AST
66/// node of the appropriate kind from the pieces. The default transformation
67/// routines recursively transform the operands to composite AST nodes (e.g.,
68/// the pointee type of a PointerType node) and, if any of those operand nodes
69/// were changed by the transformation, invokes the rebuild operation to create
70/// a new AST node.
71///
Mike Stump11289f42009-09-09 15:08:12 +000072/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000073/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000074/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// TransformTemplateName(), or TransformTemplateArgument() with entirely
76/// new implementations.
77///
78/// For more fine-grained transformations, subclasses can replace any of the
79/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000080/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000082/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000083/// parameters. Additionally, subclasses can override the \c RebuildXXX
84/// functions to control how AST nodes are rebuilt when their operands change.
85/// By default, \c TreeTransform will invoke semantic analysis to rebuild
86/// AST nodes. However, certain other tree transformations (e.g, cloning) may
87/// be able to use more efficient rebuild steps.
88///
89/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000090/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000091/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
92/// operands have not changed (\c AlwaysRebuild()), and customize the
93/// default locations and entity names used for type-checking
94/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000095template<typename Derived>
96class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000097 /// \brief Private RAII object that helps us forget and then re-remember
98 /// the template argument corresponding to a partially-substituted parameter
99 /// pack.
100 class ForgetPartiallySubstitutedPackRAII {
101 Derived &Self;
102 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000103
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000104 public:
105 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
106 Old = Self.ForgetPartiallySubstitutedPack();
107 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000108
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000109 ~ForgetPartiallySubstitutedPackRAII() {
110 Self.RememberPartiallySubstitutedPack(Old);
111 }
112 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114protected:
115 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000116
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000117 /// \brief The set of local declarations that have been transformed, for
118 /// cases where we are forced to build new declarations within the transformer
119 /// rather than in the subclass (e.g., lambda closure types).
120 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000121
Mike Stump11289f42009-09-09 15:08:12 +0000122public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000124 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000125
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// \brief Retrieves a reference to the derived class.
127 Derived &getDerived() { return static_cast<Derived&>(*this); }
128
129 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000130 const Derived &getDerived() const {
131 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 }
133
John McCalldadc5752010-08-24 06:29:42 +0000134 static inline ExprResult Owned(Expr *E) { return E; }
135 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000136
Douglas Gregord6ff3322009-08-04 16:50:30 +0000137 /// \brief Retrieves a reference to the semantic analysis object used for
138 /// this tree transform.
139 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Whether the transformation should always rebuild AST nodes, even
142 /// if none of the children have changed.
143 ///
144 /// Subclasses may override this function to specify when the transformation
145 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000146 ///
147 /// We must always rebuild all AST nodes when performing variadic template
148 /// pack expansion, in order to avoid violating the AST invariant that each
149 /// statement node appears at most once in its containing declaration.
150 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000151
Douglas Gregord6ff3322009-08-04 16:50:30 +0000152 /// \brief Returns the location of the entity being transformed, if that
153 /// information was not available elsewhere in the AST.
154 ///
Mike Stump11289f42009-09-09 15:08:12 +0000155 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000156 /// provide an alternative implementation that provides better location
157 /// information.
158 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000159
Douglas Gregord6ff3322009-08-04 16:50:30 +0000160 /// \brief Returns the name of the entity being transformed, if that
161 /// information was not available elsewhere in the AST.
162 ///
163 /// By default, returns an empty name. Subclasses can provide an alternative
164 /// implementation with a more precise name.
165 DeclarationName getBaseEntity() { return DeclarationName(); }
166
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 /// \brief Sets the "base" location and entity when that
168 /// information is known based on another transformation.
169 ///
170 /// By default, the source location and entity are ignored. Subclasses can
171 /// override this function to provide a customized implementation.
172 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000173
Douglas Gregora16548e2009-08-11 05:31:07 +0000174 /// \brief RAII object that temporarily sets the base location and entity
175 /// used for reporting diagnostics in types.
176 class TemporaryBase {
177 TreeTransform &Self;
178 SourceLocation OldLocation;
179 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000180
Douglas Gregora16548e2009-08-11 05:31:07 +0000181 public:
182 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000183 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000184 OldLocation = Self.getDerived().getBaseLocation();
185 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000186
Douglas Gregora518d5b2011-01-25 17:51:48 +0000187 if (Location.isValid())
188 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 }
Mike Stump11289f42009-09-09 15:08:12 +0000190
Douglas Gregora16548e2009-08-11 05:31:07 +0000191 ~TemporaryBase() {
192 Self.getDerived().setBase(OldLocation, OldEntity);
193 }
194 };
Mike Stump11289f42009-09-09 15:08:12 +0000195
196 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000197 /// transformed.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000200 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000201 /// not change. For example, template instantiation need not traverse
202 /// non-dependent types.
203 bool AlreadyTransformed(QualType T) {
204 return T.isNull();
205 }
206
Douglas Gregord196a582009-12-14 19:27:10 +0000207 /// \brief Determine whether the given call argument should be dropped, e.g.,
208 /// because it is a default argument.
209 ///
210 /// Subclasses can provide an alternative implementation of this routine to
211 /// determine which kinds of call arguments get dropped. By default,
212 /// CXXDefaultArgument nodes are dropped (prior to transformation).
213 bool DropCallArgument(Expr *E) {
214 return E->isDefaultArgument();
215 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000216
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000217 /// \brief Determine whether we should expand a pack expansion with the
218 /// given set of parameter packs into separate arguments by repeatedly
219 /// transforming the pattern.
220 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000221 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000222 /// Subclasses can override this routine to provide different behavior.
223 ///
224 /// \param EllipsisLoc The location of the ellipsis that identifies the
225 /// pack expansion.
226 ///
227 /// \param PatternRange The source range that covers the entire pattern of
228 /// the pack expansion.
229 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000230 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// pattern.
232 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000233 /// \param ShouldExpand Will be set to \c true if the transformer should
234 /// expand the corresponding pack expansions into separate arguments. When
235 /// set, \c NumExpansions must also be set.
236 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000237 /// \param RetainExpansion Whether the caller should add an unexpanded
238 /// pack expansion after all of the expanded arguments. This is used
239 /// when extending explicitly-specified template argument packs per
240 /// C++0x [temp.arg.explicit]p9.
241 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000242 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000243 /// the expanded form of the corresponding pack expansion. This is both an
244 /// input and an output parameter, which can be set by the caller if the
245 /// number of expansions is known a priori (e.g., due to a prior substitution)
246 /// and will be set by the callee when the number of expansions is known.
247 /// The callee must set this value when \c ShouldExpand is \c true; it may
248 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000250 /// \returns true if an error occurred (e.g., because the parameter packs
251 /// are to be instantiated with arguments of different lengths), false
252 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000253 /// must be set.
254 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
255 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000256 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000257 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000258 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000259 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000260 ShouldExpand = false;
261 return false;
262 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000263
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000264 /// \brief "Forget" about the partially-substituted pack template argument,
265 /// when performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 TemplateArgument ForgetPartiallySubstitutedPack() {
270 return TemplateArgument();
271 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000272
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000273 /// \brief "Remember" the partially-substituted pack template argument
274 /// after performing an instantiation that must preserve the parameter pack
275 /// use.
276 ///
277 /// This routine is meant to be overridden by the template instantiator.
278 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000279
Douglas Gregorf3010112011-01-07 16:43:16 +0000280 /// \brief Note to the derived class when a function parameter pack is
281 /// being expanded.
282 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000283
Douglas Gregord6ff3322009-08-04 16:50:30 +0000284 /// \brief Transforms the given type into another type.
285 ///
John McCall550e0c22009-10-21 00:40:46 +0000286 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000287 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000288 /// function. This is expensive, but we don't mind, because
289 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000290 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 ///
292 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000293 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000294
John McCall550e0c22009-10-21 00:40:46 +0000295 /// \brief Transforms the given type-with-location into a new
296 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000297 ///
John McCall550e0c22009-10-21 00:40:46 +0000298 /// By default, this routine transforms a type by delegating to the
299 /// appropriate TransformXXXType to build a new type. Subclasses
300 /// may override this function (to take over all type
301 /// transformations) or some set of the TransformXXXType functions
302 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000303 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000304
305 /// \brief Transform the given type-with-location into a new
306 /// type, collecting location information in the given builder
307 /// as necessary.
308 ///
John McCall31f82722010-11-12 08:19:04 +0000309 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000310
Richard Smithee579842017-01-30 20:39:26 +0000311 /// \brief Transform a type that is permitted to produce a
312 /// DeducedTemplateSpecializationType.
313 ///
314 /// This is used in the (relatively rare) contexts where it is acceptable
315 /// for transformation to produce a class template type with deduced
316 /// template arguments.
317 /// @{
318 QualType TransformTypeWithDeducedTST(QualType T);
319 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
320 /// @}
321
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000322 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000323 ///
Mike Stump11289f42009-09-09 15:08:12 +0000324 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000325 /// appropriate TransformXXXStmt function to transform a specific kind of
326 /// statement or the TransformExpr() function to transform an expression.
327 /// Subclasses may override this function to transform statements using some
328 /// other mechanism.
329 ///
330 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000331 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000332
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000333 /// \brief Transform the given statement.
334 ///
335 /// By default, this routine transforms a statement by delegating to the
336 /// appropriate TransformOMPXXXClause function to transform a specific kind
337 /// of clause. Subclasses may override this function to transform statements
338 /// using some other mechanism.
339 ///
340 /// \returns the transformed OpenMP clause.
341 OMPClause *TransformOMPClause(OMPClause *S);
342
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000343 /// \brief Transform the given attribute.
344 ///
345 /// By default, this routine transforms a statement by delegating to the
346 /// appropriate TransformXXXAttr function to transform a specific kind
347 /// of attribute. Subclasses may override this function to transform
348 /// attributed statements using some other mechanism.
349 ///
350 /// \returns the transformed attribute
351 const Attr *TransformAttr(const Attr *S);
352
353/// \brief Transform the specified attribute.
354///
355/// Subclasses should override the transformation of attributes with a pragma
356/// spelling to transform expressions stored within the attribute.
357///
358/// \returns the transformed attribute.
359#define ATTR(X)
360#define PRAGMA_SPELLING_ATTR(X) \
361 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
362#include "clang/Basic/AttrList.inc"
363
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000364 /// \brief Transform the given expression.
365 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000366 /// By default, this routine transforms an expression by delegating to the
367 /// appropriate TransformXXXExpr function to build a new expression.
368 /// Subclasses may override this function to transform expressions using some
369 /// other mechanism.
370 ///
371 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000372 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Richard Smithd59b8322012-12-19 01:39:02 +0000374 /// \brief Transform the given initializer.
375 ///
376 /// By default, this routine transforms an initializer by stripping off the
377 /// semantic nodes added by initialization, then passing the result to
378 /// TransformExpr or TransformExprs.
379 ///
380 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000381 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000382
Douglas Gregora3efea12011-01-03 19:04:46 +0000383 /// \brief Transform the given list of expressions.
384 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000385 /// This routine transforms a list of expressions by invoking
386 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000387 /// support for variadic templates by expanding any pack expansions (if the
388 /// derived class permits such expansion) along the way. When pack expansions
389 /// are present, the number of outputs may not equal the number of inputs.
390 ///
391 /// \param Inputs The set of expressions to be transformed.
392 ///
393 /// \param NumInputs The number of expressions in \c Inputs.
394 ///
395 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000396 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000397 /// be.
398 ///
399 /// \param Outputs The transformed input expressions will be added to this
400 /// vector.
401 ///
402 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
403 /// due to transformation.
404 ///
405 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000406 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000407 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000408 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 /// \brief Transform the given declaration, which is referenced from a type
411 /// or expression.
412 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// By default, acts as the identity function on declarations, unless the
414 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000415 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000416 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000417 llvm::DenseMap<Decl *, Decl *>::iterator Known
418 = TransformedLocalDecls.find(D);
419 if (Known != TransformedLocalDecls.end())
420 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000421
422 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000424
Richard Smith03a4aa32016-06-23 19:02:52 +0000425 /// \brief Transform the specified condition.
426 ///
427 /// By default, this transforms the variable and expression and rebuilds
428 /// the condition.
429 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
430 Expr *Expr,
431 Sema::ConditionKind Kind);
432
Chad Rosier1dcde962012-08-08 18:46:20 +0000433 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000434 /// place them on the new declaration.
435 ///
436 /// By default, this operation does nothing. Subclasses may override this
437 /// behavior to transform attributes.
438 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000439
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000440 /// \brief Note that a local declaration has been transformed by this
441 /// transformer.
442 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000444 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
445 /// the transformer itself has to transform the declarations. This routine
446 /// can be overridden by a subclass that keeps track of such mappings.
447 void transformedLocalDecl(Decl *Old, Decl *New) {
448 TransformedLocalDecls[Old] = New;
449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregorebe10102009-08-20 07:17:43 +0000451 /// \brief Transform the definition of the given declaration.
452 ///
Mike Stump11289f42009-09-09 15:08:12 +0000453 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000454 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000455 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
456 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000457 }
Mike Stump11289f42009-09-09 15:08:12 +0000458
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000459 /// \brief Transform the given declaration, which was the first part of a
460 /// nested-name-specifier in a member access expression.
461 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000462 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000463 /// identifier in a nested-name-specifier of a member access expression, e.g.,
464 /// the \c T in \c x->T::member
465 ///
466 /// By default, invokes TransformDecl() to transform the declaration.
467 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000468 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
469 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000470 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000471
Richard Smith151c4562016-12-20 21:35:28 +0000472 /// Transform the set of declarations in an OverloadExpr.
473 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
474 LookupResult &R);
475
Douglas Gregor14454802011-02-25 02:25:35 +0000476 /// \brief Transform the given nested-name-specifier with source-location
477 /// information.
478 ///
479 /// By default, transforms all of the types and declarations within the
480 /// nested-name-specifier. Subclasses may override this function to provide
481 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000482 NestedNameSpecifierLoc
483 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
484 QualType ObjectType = QualType(),
485 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000486
Douglas Gregorf816bd72009-09-03 22:13:48 +0000487 /// \brief Transform the given declaration name.
488 ///
489 /// By default, transforms the types of conversion function, constructor,
490 /// and destructor names and then (if needed) rebuilds the declaration name.
491 /// Identifiers and selectors are returned unmodified. Sublcasses may
492 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000493 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000494 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000495
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000497 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000498 /// \param SS The nested-name-specifier that qualifies the template
499 /// name. This nested-name-specifier must already have been transformed.
500 ///
501 /// \param Name The template name to transform.
502 ///
503 /// \param NameLoc The source location of the template name.
504 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000505 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000506 /// access expression, this is the type of the object whose member template
507 /// is being referenced.
508 ///
509 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
510 /// also refers to a name within the current (lexical) scope, this is the
511 /// declaration it refers to.
512 ///
513 /// By default, transforms the template name by transforming the declarations
514 /// and nested-name-specifiers that occur within the template name.
515 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000516 TemplateName
517 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
518 SourceLocation NameLoc,
519 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000520 NamedDecl *FirstQualifierInScope = nullptr,
521 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000522
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523 /// \brief Transform the given template argument.
524 ///
Mike Stump11289f42009-09-09 15:08:12 +0000525 /// By default, this operation transforms the type, expression, or
526 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000527 /// new template argument from the transformed result. Subclasses may
528 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000529 ///
530 /// Returns true if there was an error.
531 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000532 TemplateArgumentLoc &Output,
533 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000534
Douglas Gregor62e06f22010-12-20 17:31:10 +0000535 /// \brief Transform the given set of template arguments.
536 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000537 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000538 /// in the input set using \c TransformTemplateArgument(), and appends
539 /// the transformed arguments to the output list.
540 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000541 /// Note that this overload of \c TransformTemplateArguments() is merely
542 /// a convenience function. Subclasses that wish to override this behavior
543 /// should override the iterator-based member template version.
544 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000545 /// \param Inputs The set of template arguments to be transformed.
546 ///
547 /// \param NumInputs The number of template arguments in \p Inputs.
548 ///
549 /// \param Outputs The set of transformed template arguments output by this
550 /// routine.
551 ///
552 /// Returns true if an error occurred.
553 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
554 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000555 TemplateArgumentListInfo &Outputs,
556 bool Uneval = false) {
557 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
558 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000559 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000560
561 /// \brief Transform the given set of template arguments.
562 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000564 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000565 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000566 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000567 /// \param First An iterator to the first template argument.
568 ///
569 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000570 ///
571 /// \param Outputs The set of transformed template arguments output by this
572 /// routine.
573 ///
574 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000575 template<typename InputIterator>
576 bool TransformTemplateArguments(InputIterator First,
577 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000578 TemplateArgumentListInfo &Outputs,
579 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000580
John McCall0ad16662009-10-29 08:12:44 +0000581 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
582 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
583 TemplateArgumentLoc &ArgLoc);
584
John McCallbcd03502009-12-07 02:54:59 +0000585 /// \brief Fakes up a TypeSourceInfo for a type.
586 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
587 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000588 getDerived().getBaseLocation());
589 }
Mike Stump11289f42009-09-09 15:08:12 +0000590
John McCall550e0c22009-10-21 00:40:46 +0000591#define ABSTRACT_TYPELOC(CLASS, PARENT)
592#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000593 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000594#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000595
Richard Smith2e321552014-11-12 02:00:47 +0000596 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000597 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
598 FunctionProtoTypeLoc TL,
599 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000600 unsigned ThisTypeQuals,
601 Fn TransformExceptionSpec);
602
603 bool TransformExceptionSpec(SourceLocation Loc,
604 FunctionProtoType::ExceptionSpecInfo &ESI,
605 SmallVectorImpl<QualType> &Exceptions,
606 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000607
David Majnemerfad8f482013-10-15 09:33:02 +0000608 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000609
Chad Rosier1dcde962012-08-08 18:46:20 +0000610 QualType
John McCall31f82722010-11-12 08:19:04 +0000611 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
612 TemplateSpecializationTypeLoc TL,
613 TemplateName Template);
614
Chad Rosier1dcde962012-08-08 18:46:20 +0000615 QualType
John McCall31f82722010-11-12 08:19:04 +0000616 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
617 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000618 TemplateName Template,
619 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000620
Nico Weberc153d242014-07-28 00:02:09 +0000621 QualType TransformDependentTemplateSpecializationType(
622 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
623 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000624
John McCall58f10c32010-03-11 09:03:00 +0000625 /// \brief Transforms the parameters of a function type into the
626 /// given vectors.
627 ///
628 /// The result vectors should be kept in sync; null entries in the
629 /// variables vector are acceptable.
630 ///
631 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000632 bool TransformFunctionTypeParams(
633 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
634 const QualType *ParamTypes,
635 const FunctionProtoType::ExtParameterInfo *ParamInfos,
636 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
637 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000638
639 /// \brief Transforms a single function-type parameter. Return null
640 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000641 ///
642 /// \param indexAdjustment - A number to add to the parameter's
643 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000644 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000645 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000646 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000647 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000648
John McCall31f82722010-11-12 08:19:04 +0000649 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000650
John McCalldadc5752010-08-24 06:29:42 +0000651 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
652 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000653
Faisal Vali2cba1332013-10-23 06:44:28 +0000654 TemplateParameterList *TransformTemplateParameterList(
655 TemplateParameterList *TPL) {
656 return TPL;
657 }
658
Richard Smithdb2630f2012-10-21 03:28:35 +0000659 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000660
Richard Smithdb2630f2012-10-21 03:28:35 +0000661 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000662 bool IsAddressOfOperand,
663 TypeSourceInfo **RecoveryTSI);
664
665 ExprResult TransformParenDependentScopeDeclRefExpr(
666 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
667 TypeSourceInfo **RecoveryTSI);
668
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000669 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000670
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000671// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
672// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000673#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000674 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000675 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000676#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000677 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000678 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000679#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000680#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000681
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000682#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000683 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000684 OMPClause *Transform ## Class(Class *S);
685#include "clang/Basic/OpenMPKinds.def"
686
Richard Smithee579842017-01-30 20:39:26 +0000687 /// \brief Build a new qualified type given its unqualified type and type
688 /// qualifiers.
689 ///
690 /// By default, this routine adds type qualifiers only to types that can
691 /// have qualifiers, and silently suppresses those qualifiers that are not
692 /// permitted. Subclasses may override this routine to provide different
693 /// behavior.
694 QualType RebuildQualifiedType(QualType T, SourceLocation Loc,
695 Qualifiers Quals);
696
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 /// \brief Build a new pointer type given its pointee type.
698 ///
699 /// By default, performs semantic analysis when building the pointer type.
700 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000701 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702
703 /// \brief Build a new block pointer type given its pointee type.
704 ///
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000707 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708
John McCall70dd5f62009-10-30 00:06:24 +0000709 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710 ///
John McCall70dd5f62009-10-30 00:06:24 +0000711 /// By default, performs semantic analysis when building the
712 /// reference type. Subclasses may override this routine to provide
713 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 ///
John McCall70dd5f62009-10-30 00:06:24 +0000715 /// \param LValue whether the type was written with an lvalue sigil
716 /// or an rvalue sigil.
717 QualType RebuildReferenceType(QualType ReferentType,
718 bool LValue,
719 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000720
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 /// \brief Build a new member pointer type given the pointee type and the
722 /// class type it refers into.
723 ///
724 /// By default, performs semantic analysis when building the member pointer
725 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000726 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
727 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000728
Manman Rene6be26c2016-09-13 17:25:08 +0000729 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
730 SourceLocation ProtocolLAngleLoc,
731 ArrayRef<ObjCProtocolDecl *> Protocols,
732 ArrayRef<SourceLocation> ProtocolLocs,
733 SourceLocation ProtocolRAngleLoc);
734
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000735 /// \brief Build an Objective-C object type.
736 ///
737 /// By default, performs semantic analysis when building the object type.
738 /// Subclasses may override this routine to provide different behavior.
739 QualType RebuildObjCObjectType(QualType BaseType,
740 SourceLocation Loc,
741 SourceLocation TypeArgsLAngleLoc,
742 ArrayRef<TypeSourceInfo *> TypeArgs,
743 SourceLocation TypeArgsRAngleLoc,
744 SourceLocation ProtocolLAngleLoc,
745 ArrayRef<ObjCProtocolDecl *> Protocols,
746 ArrayRef<SourceLocation> ProtocolLocs,
747 SourceLocation ProtocolRAngleLoc);
748
749 /// \brief Build a new Objective-C object pointer type given the pointee type.
750 ///
751 /// By default, directly builds the pointer type, with no additional semantic
752 /// analysis.
753 QualType RebuildObjCObjectPointerType(QualType PointeeType,
754 SourceLocation Star);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new array type given the element type, size
757 /// modifier, size of the array (if known), size expression, and index type
758 /// qualifiers.
759 ///
760 /// By default, performs semantic analysis when building the array type.
761 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000762 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 QualType RebuildArrayType(QualType ElementType,
764 ArrayType::ArraySizeModifier SizeMod,
765 const llvm::APInt *Size,
766 Expr *SizeExpr,
767 unsigned IndexTypeQuals,
768 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// \brief Build a new constant array type given the element type, size
771 /// modifier, (known) size of the array, and index type qualifiers.
772 ///
773 /// By default, performs semantic analysis when building the array type.
774 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000775 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 ArrayType::ArraySizeModifier SizeMod,
777 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000778 unsigned IndexTypeQuals,
779 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780
Douglas Gregord6ff3322009-08-04 16:50:30 +0000781 /// \brief Build a new incomplete array type given the element type, size
782 /// modifier, and index type qualifiers.
783 ///
784 /// By default, performs semantic analysis when building the array type.
785 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000786 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000788 unsigned IndexTypeQuals,
789 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790
Mike Stump11289f42009-09-09 15:08:12 +0000791 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000792 /// size modifier, size expression, and index type qualifiers.
793 ///
794 /// By default, performs semantic analysis when building the array type.
795 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000796 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000798 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000799 unsigned IndexTypeQuals,
800 SourceRange BracketsRange);
801
Mike Stump11289f42009-09-09 15:08:12 +0000802 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 /// size modifier, size expression, and index type qualifiers.
804 ///
805 /// By default, performs semantic analysis when building the array type.
806 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000807 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000808 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000809 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810 unsigned IndexTypeQuals,
811 SourceRange BracketsRange);
812
813 /// \brief Build a new vector type given the element type and
814 /// number of elements.
815 ///
816 /// By default, performs semantic analysis when building the vector type.
817 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000818 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000819 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new extended vector type given the element type and
822 /// number of elements.
823 ///
824 /// By default, performs semantic analysis when building the vector type.
825 /// Subclasses may override this routine to provide different behavior.
826 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
827 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000828
829 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000830 /// given the element type and number of elements.
831 ///
832 /// By default, performs semantic analysis when building the vector type.
833 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000834 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000835 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000836 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000837
Douglas Gregord6ff3322009-08-04 16:50:30 +0000838 /// \brief Build a new function type.
839 ///
840 /// By default, performs semantic analysis when building the function type.
841 /// Subclasses may override this routine to provide different behavior.
842 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000843 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000844 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000845
John McCall550e0c22009-10-21 00:40:46 +0000846 /// \brief Build a new unprototyped function type.
847 QualType RebuildFunctionNoProtoType(QualType ResultType);
848
John McCallb96ec562009-12-04 22:46:56 +0000849 /// \brief Rebuild an unresolved typename type, given the decl that
850 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000851 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000852
Douglas Gregord6ff3322009-08-04 16:50:30 +0000853 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000854 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000855 return SemaRef.Context.getTypeDeclType(Typedef);
856 }
857
858 /// \brief Build a new class/struct/union type.
859 QualType RebuildRecordType(RecordDecl *Record) {
860 return SemaRef.Context.getTypeDeclType(Record);
861 }
862
863 /// \brief Build a new Enum type.
864 QualType RebuildEnumType(EnumDecl *Enum) {
865 return SemaRef.Context.getTypeDeclType(Enum);
866 }
John McCallfcc33b02009-09-05 00:15:47 +0000867
Mike Stump11289f42009-09-09 15:08:12 +0000868 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000869 ///
870 /// By default, performs semantic analysis when building the typeof type.
871 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000872 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000873
Mike Stump11289f42009-09-09 15:08:12 +0000874 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000875 ///
876 /// By default, builds a new TypeOfType with the given underlying type.
877 QualType RebuildTypeOfType(QualType Underlying);
878
Alexis Hunte852b102011-05-24 22:41:36 +0000879 /// \brief Build a new unary transform type.
880 QualType RebuildUnaryTransformType(QualType BaseType,
881 UnaryTransformType::UTTKind UKind,
882 SourceLocation Loc);
883
Richard Smith74aeef52013-04-26 16:15:35 +0000884 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 ///
886 /// By default, performs semantic analysis when building the decltype type.
887 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000888 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000889
Richard Smith74aeef52013-04-26 16:15:35 +0000890 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000891 ///
892 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000893 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000894 // Note, IsDependent is always false here: we implicitly convert an 'auto'
895 // which has been deduced to a dependent type into an undeduced 'auto', so
896 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000897 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000898 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000899 }
900
Richard Smith600b5262017-01-26 20:40:47 +0000901 /// By default, builds a new DeducedTemplateSpecializationType with the given
902 /// deduced type.
903 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
904 QualType Deduced) {
905 return SemaRef.Context.getDeducedTemplateSpecializationType(
906 Template, Deduced, /*IsDependent*/ false);
907 }
908
Douglas Gregord6ff3322009-08-04 16:50:30 +0000909 /// \brief Build a new template specialization type.
910 ///
911 /// By default, performs semantic analysis when building the template
912 /// specialization type. Subclasses may override this routine to provide
913 /// different behavior.
914 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000915 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000916 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000917
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000918 /// \brief Build a new parenthesized type.
919 ///
920 /// By default, builds a new ParenType type from the inner type.
921 /// Subclasses may override this routine to provide different behavior.
922 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000923 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000924 }
925
Douglas Gregord6ff3322009-08-04 16:50:30 +0000926 /// \brief Build a new qualified name type.
927 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000928 /// By default, builds a new ElaboratedType type from the keyword,
929 /// the nested-name-specifier and the named type.
930 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000931 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
932 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000933 NestedNameSpecifierLoc QualifierLoc,
934 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000935 return SemaRef.Context.getElaboratedType(Keyword,
936 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000937 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000938 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000939
940 /// \brief Build a new typename type that refers to a template-id.
941 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 /// By default, builds a new DependentNameType type from the
943 /// nested-name-specifier and the given type. Subclasses may override
944 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000945 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000946 ElaboratedTypeKeyword Keyword,
947 NestedNameSpecifierLoc QualifierLoc,
948 const IdentifierInfo *Name,
949 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000950 TemplateArgumentListInfo &Args,
951 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000952 // Rebuild the template name.
953 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000954 CXXScopeSpec SS;
955 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000956 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000957 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000958 nullptr, AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000959
Douglas Gregora7a795b2011-03-01 20:11:18 +0000960 if (InstName.isNull())
961 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000962
Douglas Gregora7a795b2011-03-01 20:11:18 +0000963 // If it's still dependent, make a dependent specialization.
964 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000965 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
966 QualifierLoc.getNestedNameSpecifier(),
967 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000968 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000969
Douglas Gregora7a795b2011-03-01 20:11:18 +0000970 // Otherwise, make an elaborated type wrapping a non-dependent
971 // specialization.
972 QualType T =
973 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
974 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000975
Craig Topperc3ec1492014-05-26 06:22:03 +0000976 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000977 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000978
979 return SemaRef.Context.getElaboratedType(Keyword,
980 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000981 T);
982 }
983
Douglas Gregord6ff3322009-08-04 16:50:30 +0000984 /// \brief Build a new typename type that refers to an identifier.
985 ///
986 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000987 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000988 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000989 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000990 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000991 NestedNameSpecifierLoc QualifierLoc,
992 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +0000993 SourceLocation IdLoc,
994 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000995 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000996 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000997
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000998 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000999 // If the name is still dependent, just build a new dependent name type.
1000 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001001 return SemaRef.Context.getDependentNameType(Keyword,
1002 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001003 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001004 }
1005
Richard Smithee579842017-01-30 20:39:26 +00001006 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1007 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1008 *Id, IdLoc);
1009 // If a dependent name resolves to a deduced template specialization type,
1010 // check that we're in one of the syntactic contexts permitting it.
1011 if (!DeducedTSTContext) {
1012 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1013 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1014 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1015 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1016 Deduced->getTemplateName())
1017 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1018 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1019 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1020 return QualType();
1021 }
1022 }
1023 return T;
1024 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001025
1026 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1027
Abramo Bagnarad7548482010-05-19 21:37:53 +00001028 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001029 // into a non-dependent elaborated-type-specifier. Find the tag we're
1030 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001031 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001032 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1033 if (!DC)
1034 return QualType();
1035
John McCallbf8c5192010-05-27 06:40:31 +00001036 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1037 return QualType();
1038
Craig Topperc3ec1492014-05-26 06:22:03 +00001039 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001040 SemaRef.LookupQualifiedName(Result, DC);
1041 switch (Result.getResultKind()) {
1042 case LookupResult::NotFound:
1043 case LookupResult::NotFoundInCurrentInstantiation:
1044 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001045
Douglas Gregore677daf2010-03-31 22:19:08 +00001046 case LookupResult::Found:
1047 Tag = Result.getAsSingle<TagDecl>();
1048 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001049
Douglas Gregore677daf2010-03-31 22:19:08 +00001050 case LookupResult::FoundOverloaded:
1051 case LookupResult::FoundUnresolvedValue:
1052 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001053
Douglas Gregore677daf2010-03-31 22:19:08 +00001054 case LookupResult::Ambiguous:
1055 // Let the LookupResult structure handle ambiguities.
1056 return QualType();
1057 }
1058
1059 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001060 // Check where the name exists but isn't a tag type and use that to emit
1061 // better diagnostics.
1062 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1063 SemaRef.LookupQualifiedName(Result, DC);
1064 switch (Result.getResultKind()) {
1065 case LookupResult::Found:
1066 case LookupResult::FoundOverloaded:
1067 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001068 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001069 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1070 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1071 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001072 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1073 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001074 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001075 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001076 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001077 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001078 break;
1079 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001080 return QualType();
1081 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001082
Richard Trieucaa33d32011-06-10 03:11:26 +00001083 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001084 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001085 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001086 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1087 return QualType();
1088 }
1089
1090 // Build the elaborated-type-specifier type.
1091 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001092 return SemaRef.Context.getElaboratedType(Keyword,
1093 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001094 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregor822d0302011-01-12 17:07:58 +00001097 /// \brief Build a new pack expansion type.
1098 ///
1099 /// By default, builds a new PackExpansionType type from the given pattern.
1100 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001101 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001102 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001103 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001104 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001105 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1106 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001107 }
1108
Eli Friedman0dfb8892011-10-06 23:00:33 +00001109 /// \brief Build a new atomic type given its value type.
1110 ///
1111 /// By default, performs semantic analysis when building the atomic type.
1112 /// Subclasses may override this routine to provide different behavior.
1113 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1114
Xiuli Pan9c14e282016-01-09 12:53:17 +00001115 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001116 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1117 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001118
Douglas Gregor71dc5092009-08-06 06:41:21 +00001119 /// \brief Build a new template name given a nested name specifier, a flag
1120 /// indicating whether the "template" keyword was provided, and the template
1121 /// that the template name refers to.
1122 ///
1123 /// By default, builds the new template name directly. Subclasses may override
1124 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001125 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001126 bool TemplateKW,
1127 TemplateDecl *Template);
1128
Douglas Gregor71dc5092009-08-06 06:41:21 +00001129 /// \brief Build a new template name given a nested name specifier and the
1130 /// name that is referred to as a template.
1131 ///
1132 /// By default, performs semantic analysis to determine whether the name can
1133 /// be resolved to a specific template, then builds the appropriate kind of
1134 /// template name. Subclasses may override this routine to provide different
1135 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001136 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1137 const IdentifierInfo &Name,
1138 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001139 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001140 NamedDecl *FirstQualifierInScope,
1141 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregor71395fa2009-11-04 00:56:37 +00001143 /// \brief Build a new template name given a nested name specifier and the
1144 /// overloaded operator name that is referred to as a template.
1145 ///
1146 /// By default, performs semantic analysis to determine whether the name can
1147 /// be resolved to a specific template, then builds the appropriate kind of
1148 /// template name. Subclasses may override this routine to provide different
1149 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001150 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001151 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001152 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00001153 QualType ObjectType,
1154 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001155
1156 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001157 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001158 ///
1159 /// By default, performs semantic analysis to determine whether the name can
1160 /// be resolved to a specific template, then builds the appropriate kind of
1161 /// template name. Subclasses may override this routine to provide different
1162 /// behavior.
1163 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1164 const TemplateArgument &ArgPack) {
1165 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1166 }
1167
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 /// \brief Build a new compound statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001172 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 MultiStmtArg Statements,
1174 SourceLocation RBraceLoc,
1175 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001176 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001177 IsStmtExpr);
1178 }
1179
1180 /// \brief Build a new case statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001185 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001187 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001188 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 ColonLoc);
1191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Attach the body to a new case statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001198 getSema().ActOnCaseStmtBody(S, Body);
1199 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 }
Mike Stump11289f42009-09-09 15:08:12 +00001201
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 /// \brief Build a new default statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001206 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001208 Stmt *SubStmt) {
1209 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001210 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001211 }
Mike Stump11289f42009-09-09 15:08:12 +00001212
Douglas Gregorebe10102009-08-20 07:17:43 +00001213 /// \brief Build a new label statement.
1214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001217 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1218 SourceLocation ColonLoc, Stmt *SubStmt) {
1219 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Richard Smithc202b282012-04-14 00:33:13 +00001222 /// \brief Build a new label statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001226 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1227 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001228 Stmt *SubStmt) {
1229 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1230 }
1231
Douglas Gregorebe10102009-08-20 07:17:43 +00001232 /// \brief Build a new "if" statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001236 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001237 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001238 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001239 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001240 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 /// \brief Start building a new switch statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001247 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001248 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001249 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 /// \brief Attach the body to the switch statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001256 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001257 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001258 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 }
1260
1261 /// \brief Build a new while statement.
1262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001265 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1266 Sema::ConditionResult Cond, Stmt *Body) {
1267 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Douglas Gregorebe10102009-08-20 07:17:43 +00001270 /// \brief Build a new do-while statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001274 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001275 SourceLocation WhileLoc, SourceLocation LParenLoc,
1276 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001277 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1278 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 }
1280
1281 /// \brief Build a new for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001285 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001286 Stmt *Init, Sema::ConditionResult Cond,
1287 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1288 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001289 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001290 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001291 }
Mike Stump11289f42009-09-09 15:08:12 +00001292
Douglas Gregorebe10102009-08-20 07:17:43 +00001293 /// \brief Build a new goto statement.
1294 ///
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001297 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1298 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001299 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001300 }
1301
1302 /// \brief Build a new indirect goto statement.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001306 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001307 SourceLocation StarLoc,
1308 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001309 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001310 }
Mike Stump11289f42009-09-09 15:08:12 +00001311
Douglas Gregorebe10102009-08-20 07:17:43 +00001312 /// \brief Build a new return statement.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001316 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001317 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001318 }
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregorebe10102009-08-20 07:17:43 +00001320 /// \brief Build a new declaration statement.
1321 ///
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001324 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001325 SourceLocation StartLoc, SourceLocation EndLoc) {
1326 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001327 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Anders Carlssonaaeef072010-01-24 05:50:09 +00001330 /// \brief Build a new inline asm statement.
1331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001334 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1335 bool IsVolatile, unsigned NumOutputs,
1336 unsigned NumInputs, IdentifierInfo **Names,
1337 MultiExprArg Constraints, MultiExprArg Exprs,
1338 Expr *AsmString, MultiExprArg Clobbers,
1339 SourceLocation RParenLoc) {
1340 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1341 NumInputs, Names, Constraints, Exprs,
1342 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001343 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001344
Chad Rosier32503022012-06-11 20:47:18 +00001345 /// \brief Build a new MS style inline asm statement.
1346 ///
1347 /// By default, performs semantic analysis to build the new statement.
1348 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001349 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001350 ArrayRef<Token> AsmToks,
1351 StringRef AsmString,
1352 unsigned NumOutputs, unsigned NumInputs,
1353 ArrayRef<StringRef> Constraints,
1354 ArrayRef<StringRef> Clobbers,
1355 ArrayRef<Expr*> Exprs,
1356 SourceLocation EndLoc) {
1357 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1358 NumOutputs, NumInputs,
1359 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001360 }
1361
Richard Smith9f690bd2015-10-27 06:02:45 +00001362 /// \brief Build a new co_return statement.
1363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001366 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1367 bool IsImplicit) {
1368 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001369 }
1370
1371 /// \brief Build a new co_await expression.
1372 ///
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001375 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1376 bool IsImplicit) {
1377 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1378 }
1379
1380 /// \brief Build a new co_await expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
1384 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1385 Expr *Result,
1386 UnresolvedLookupExpr *Lookup) {
1387 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001388 }
1389
1390 /// \brief Build a new co_yield expression.
1391 ///
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
1394 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1395 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1396 }
1397
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001398 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1399 return getSema().BuildCoroutineBodyStmt(Args);
1400 }
1401
James Dennett2a4d13c2012-06-15 07:13:21 +00001402 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001406 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001407 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001408 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001409 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001410 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001411 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001412 }
1413
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001414 /// \brief Rebuild an Objective-C exception declaration.
1415 ///
1416 /// By default, performs semantic analysis to build the new declaration.
1417 /// Subclasses may override this routine to provide different behavior.
1418 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1419 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001420 return getSema().BuildObjCExceptionDecl(TInfo, T,
1421 ExceptionDecl->getInnerLocStart(),
1422 ExceptionDecl->getLocation(),
1423 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001425
James Dennett2a4d13c2012-06-15 07:13:21 +00001426 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001427 ///
1428 /// By default, performs semantic analysis to build the new statement.
1429 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001430 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001431 SourceLocation RParenLoc,
1432 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001433 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001434 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001435 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001437
James Dennett2a4d13c2012-06-15 07:13:21 +00001438 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001439 ///
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001442 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001443 Stmt *Body) {
1444 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001446
James Dennett2a4d13c2012-06-15 07:13:21 +00001447 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001452 Expr *Operand) {
1453 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001455
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001456 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001460 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001461 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001462 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001463 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001464 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001465 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001466 return getSema().ActOnOpenMPExecutableDirective(
1467 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001468 }
1469
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001470 /// \brief Build a new OpenMP 'if' clause.
1471 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001472 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001473 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001474 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1475 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001476 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001477 SourceLocation NameModifierLoc,
1478 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001479 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001480 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1481 LParenLoc, NameModifierLoc, ColonLoc,
1482 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001483 }
1484
Alexey Bataev3778b602014-07-17 07:32:53 +00001485 /// \brief Build a new OpenMP 'final' clause.
1486 ///
1487 /// By default, performs semantic analysis to build the new OpenMP clause.
1488 /// Subclasses may override this routine to provide different behavior.
1489 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1490 SourceLocation LParenLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1493 EndLoc);
1494 }
1495
Alexey Bataev568a8332014-03-06 06:15:19 +00001496 /// \brief Build a new OpenMP 'num_threads' clause.
1497 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001498 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1505 LParenLoc, EndLoc);
1506 }
1507
Alexey Bataev62c87d22014-03-21 04:51:18 +00001508 /// \brief Build a new OpenMP 'safelen' clause.
1509 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001510 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1516 }
1517
Alexey Bataev66b15b52015-08-21 11:14:16 +00001518 /// \brief Build a new OpenMP 'simdlen' clause.
1519 ///
1520 /// By default, performs semantic analysis to build the new OpenMP clause.
1521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1523 SourceLocation LParenLoc,
1524 SourceLocation EndLoc) {
1525 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1526 }
1527
Alexander Musman8bd31e62014-05-27 15:12:19 +00001528 /// \brief Build a new OpenMP 'collapse' clause.
1529 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001530 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1533 SourceLocation LParenLoc,
1534 SourceLocation EndLoc) {
1535 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1536 EndLoc);
1537 }
1538
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001539 /// \brief Build a new OpenMP 'default' clause.
1540 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001541 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001542 /// Subclasses may override this routine to provide different behavior.
1543 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1544 SourceLocation KindKwLoc,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1549 StartLoc, LParenLoc, EndLoc);
1550 }
1551
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001552 /// \brief Build a new OpenMP 'proc_bind' clause.
1553 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001554 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001555 /// Subclasses may override this routine to provide different behavior.
1556 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1557 SourceLocation KindKwLoc,
1558 SourceLocation StartLoc,
1559 SourceLocation LParenLoc,
1560 SourceLocation EndLoc) {
1561 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1562 StartLoc, LParenLoc, EndLoc);
1563 }
1564
Alexey Bataev56dafe82014-06-20 07:16:17 +00001565 /// \brief Build a new OpenMP 'schedule' clause.
1566 ///
1567 /// By default, performs semantic analysis to build the new OpenMP clause.
1568 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001569 OMPClause *RebuildOMPScheduleClause(
1570 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1571 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1572 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1573 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001574 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001575 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1576 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001577 }
1578
Alexey Bataev10e775f2015-07-30 11:36:16 +00001579 /// \brief Build a new OpenMP 'ordered' clause.
1580 ///
1581 /// By default, performs semantic analysis to build the new OpenMP clause.
1582 /// Subclasses may override this routine to provide different behavior.
1583 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1584 SourceLocation EndLoc,
1585 SourceLocation LParenLoc, Expr *Num) {
1586 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1587 }
1588
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001589 /// \brief Build a new OpenMP 'private' clause.
1590 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001591 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001592 /// Subclasses may override this routine to provide different behavior.
1593 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1594 SourceLocation StartLoc,
1595 SourceLocation LParenLoc,
1596 SourceLocation EndLoc) {
1597 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1598 EndLoc);
1599 }
1600
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001601 /// \brief Build a new OpenMP 'firstprivate' clause.
1602 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001603 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001604 /// Subclasses may override this routine to provide different behavior.
1605 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1606 SourceLocation StartLoc,
1607 SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1610 EndLoc);
1611 }
1612
Alexander Musman1bb328c2014-06-04 13:06:39 +00001613 /// \brief Build a new OpenMP 'lastprivate' clause.
1614 ///
1615 /// By default, performs semantic analysis to build the new OpenMP clause.
1616 /// Subclasses may override this routine to provide different behavior.
1617 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 SourceLocation EndLoc) {
1621 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1622 EndLoc);
1623 }
1624
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001625 /// \brief Build a new OpenMP 'shared' clause.
1626 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001627 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001628 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001629 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1630 SourceLocation StartLoc,
1631 SourceLocation LParenLoc,
1632 SourceLocation EndLoc) {
1633 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1634 EndLoc);
1635 }
1636
Alexey Bataevc5e02582014-06-16 07:08:35 +00001637 /// \brief Build a new OpenMP 'reduction' clause.
1638 ///
1639 /// By default, performs semantic analysis to build the new statement.
1640 /// Subclasses may override this routine to provide different behavior.
1641 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 SourceLocation ColonLoc,
1645 SourceLocation EndLoc,
1646 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001647 const DeclarationNameInfo &ReductionId,
1648 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001649 return getSema().ActOnOpenMPReductionClause(
1650 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001651 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001652 }
1653
Alexey Bataev169d96a2017-07-18 20:17:46 +00001654 /// Build a new OpenMP 'task_reduction' clause.
1655 ///
1656 /// By default, performs semantic analysis to build the new statement.
1657 /// Subclasses may override this routine to provide different behavior.
1658 OMPClause *RebuildOMPTaskReductionClause(
1659 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1660 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1661 CXXScopeSpec &ReductionIdScopeSpec,
1662 const DeclarationNameInfo &ReductionId,
1663 ArrayRef<Expr *> UnresolvedReductions) {
1664 return getSema().ActOnOpenMPTaskReductionClause(
1665 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1666 ReductionId, UnresolvedReductions);
1667 }
1668
Alexey Bataevfa312f32017-07-21 18:48:21 +00001669 /// Build a new OpenMP 'in_reduction' clause.
1670 ///
1671 /// By default, performs semantic analysis to build the new statement.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OMPClause *
1674 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1675 SourceLocation LParenLoc, SourceLocation ColonLoc,
1676 SourceLocation EndLoc,
1677 CXXScopeSpec &ReductionIdScopeSpec,
1678 const DeclarationNameInfo &ReductionId,
1679 ArrayRef<Expr *> UnresolvedReductions) {
1680 return getSema().ActOnOpenMPInReductionClause(
1681 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1682 ReductionId, UnresolvedReductions);
1683 }
1684
Alexander Musman8dba6642014-04-22 13:09:42 +00001685 /// \brief Build a new OpenMP 'linear' clause.
1686 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001687 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001688 /// Subclasses may override this routine to provide different behavior.
1689 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1690 SourceLocation StartLoc,
1691 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001692 OpenMPLinearClauseKind Modifier,
1693 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001694 SourceLocation ColonLoc,
1695 SourceLocation EndLoc) {
1696 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001697 Modifier, ModifierLoc, ColonLoc,
1698 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001699 }
1700
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001701 /// \brief Build a new OpenMP 'aligned' clause.
1702 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001703 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001704 /// Subclasses may override this routine to provide different behavior.
1705 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1706 SourceLocation StartLoc,
1707 SourceLocation LParenLoc,
1708 SourceLocation ColonLoc,
1709 SourceLocation EndLoc) {
1710 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1711 LParenLoc, ColonLoc, EndLoc);
1712 }
1713
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001714 /// \brief Build a new OpenMP 'copyin' clause.
1715 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001716 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001717 /// Subclasses may override this routine to provide different behavior.
1718 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1719 SourceLocation StartLoc,
1720 SourceLocation LParenLoc,
1721 SourceLocation EndLoc) {
1722 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1723 EndLoc);
1724 }
1725
Alexey Bataevbae9a792014-06-27 10:37:06 +00001726 /// \brief Build a new OpenMP 'copyprivate' clause.
1727 ///
1728 /// By default, performs semantic analysis to build the new OpenMP clause.
1729 /// Subclasses may override this routine to provide different behavior.
1730 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1731 SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1735 EndLoc);
1736 }
1737
Alexey Bataev6125da92014-07-21 11:26:11 +00001738 /// \brief Build a new OpenMP 'flush' pseudo 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 *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1743 SourceLocation StartLoc,
1744 SourceLocation LParenLoc,
1745 SourceLocation EndLoc) {
1746 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1747 EndLoc);
1748 }
1749
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001750 /// \brief Build a new OpenMP 'depend' 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 *
1755 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1756 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1757 SourceLocation StartLoc, SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1760 StartLoc, LParenLoc, EndLoc);
1761 }
1762
Michael Wonge710d542015-08-07 16:16:36 +00001763 /// \brief Build a new OpenMP 'device' clause.
1764 ///
1765 /// By default, performs semantic analysis to build the new statement.
1766 /// Subclasses may override this routine to provide different behavior.
1767 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1768 SourceLocation LParenLoc,
1769 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001770 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001771 EndLoc);
1772 }
1773
Kelvin Li0bff7af2015-11-23 05:32:03 +00001774 /// \brief Build a new OpenMP 'map' clause.
1775 ///
1776 /// By default, performs semantic analysis to build the new OpenMP clause.
1777 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001778 OMPClause *
1779 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1780 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1781 SourceLocation MapLoc, SourceLocation ColonLoc,
1782 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1783 SourceLocation LParenLoc, SourceLocation EndLoc) {
1784 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1785 IsMapTypeImplicit, MapLoc, ColonLoc,
1786 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001787 }
1788
Kelvin Li099bb8c2015-11-24 20:50:12 +00001789 /// \brief Build a new OpenMP 'num_teams' clause.
1790 ///
1791 /// By default, performs semantic analysis to build the new statement.
1792 /// Subclasses may override this routine to provide different behavior.
1793 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1794 SourceLocation LParenLoc,
1795 SourceLocation EndLoc) {
1796 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1797 EndLoc);
1798 }
1799
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001800 /// \brief Build a new OpenMP 'thread_limit' clause.
1801 ///
1802 /// By default, performs semantic analysis to build the new statement.
1803 /// Subclasses may override this routine to provide different behavior.
1804 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1805 SourceLocation StartLoc,
1806 SourceLocation LParenLoc,
1807 SourceLocation EndLoc) {
1808 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1809 LParenLoc, EndLoc);
1810 }
1811
Alexey Bataeva0569352015-12-01 10:17:31 +00001812 /// \brief Build a new OpenMP 'priority' 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 *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1817 SourceLocation LParenLoc,
1818 SourceLocation EndLoc) {
1819 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1820 EndLoc);
1821 }
1822
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001823 /// \brief Build a new OpenMP 'grainsize' clause.
1824 ///
1825 /// By default, performs semantic analysis to build the new statement.
1826 /// Subclasses may override this routine to provide different behavior.
1827 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1828 SourceLocation LParenLoc,
1829 SourceLocation EndLoc) {
1830 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1831 EndLoc);
1832 }
1833
Alexey Bataev382967a2015-12-08 12:06:20 +00001834 /// \brief Build a new OpenMP 'num_tasks' clause.
1835 ///
1836 /// By default, performs semantic analysis to build the new statement.
1837 /// Subclasses may override this routine to provide different behavior.
1838 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1839 SourceLocation LParenLoc,
1840 SourceLocation EndLoc) {
1841 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1842 EndLoc);
1843 }
1844
Alexey Bataev28c75412015-12-15 08:19:24 +00001845 /// \brief Build a new OpenMP 'hint' clause.
1846 ///
1847 /// By default, performs semantic analysis to build the new statement.
1848 /// Subclasses may override this routine to provide different behavior.
1849 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1850 SourceLocation LParenLoc,
1851 SourceLocation EndLoc) {
1852 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1853 }
1854
Carlo Bertollib4adf552016-01-15 18:50:31 +00001855 /// \brief Build a new OpenMP 'dist_schedule' clause.
1856 ///
1857 /// By default, performs semantic analysis to build the new OpenMP clause.
1858 /// Subclasses may override this routine to provide different behavior.
1859 OMPClause *
1860 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1861 Expr *ChunkSize, SourceLocation StartLoc,
1862 SourceLocation LParenLoc, SourceLocation KindLoc,
1863 SourceLocation CommaLoc, SourceLocation EndLoc) {
1864 return getSema().ActOnOpenMPDistScheduleClause(
1865 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1866 }
1867
Samuel Antao661c0902016-05-26 17:39:58 +00001868 /// \brief Build a new OpenMP 'to' clause.
1869 ///
1870 /// By default, performs semantic analysis to build the new statement.
1871 /// Subclasses may override this routine to provide different behavior.
1872 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1873 SourceLocation StartLoc,
1874 SourceLocation LParenLoc,
1875 SourceLocation EndLoc) {
1876 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1877 }
1878
Samuel Antaoec172c62016-05-26 17:49:04 +00001879 /// \brief Build a new OpenMP 'from' clause.
1880 ///
1881 /// By default, performs semantic analysis to build the new statement.
1882 /// Subclasses may override this routine to provide different behavior.
1883 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1884 SourceLocation StartLoc,
1885 SourceLocation LParenLoc,
1886 SourceLocation EndLoc) {
1887 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1888 EndLoc);
1889 }
1890
Carlo Bertolli2404b172016-07-13 15:37:16 +00001891 /// Build a new OpenMP 'use_device_ptr' clause.
1892 ///
1893 /// By default, performs semantic analysis to build the new OpenMP clause.
1894 /// Subclasses may override this routine to provide different behavior.
1895 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1896 SourceLocation StartLoc,
1897 SourceLocation LParenLoc,
1898 SourceLocation EndLoc) {
1899 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1900 EndLoc);
1901 }
1902
Carlo Bertolli70594e92016-07-13 17:16:49 +00001903 /// Build a new OpenMP 'is_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 *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1908 SourceLocation StartLoc,
1909 SourceLocation LParenLoc,
1910 SourceLocation EndLoc) {
1911 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1912 EndLoc);
1913 }
1914
James Dennett2a4d13c2012-06-15 07:13:21 +00001915 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001916 ///
1917 /// By default, performs semantic analysis to build the new statement.
1918 /// Subclasses may override this routine to provide different behavior.
1919 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1920 Expr *object) {
1921 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1922 }
1923
James Dennett2a4d13c2012-06-15 07:13:21 +00001924 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001925 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001926 /// By default, performs semantic analysis to build the new statement.
1927 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001928 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001929 Expr *Object, Stmt *Body) {
1930 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001931 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001932
James Dennett2a4d13c2012-06-15 07:13:21 +00001933 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001934 ///
1935 /// By default, performs semantic analysis to build the new statement.
1936 /// Subclasses may override this routine to provide different behavior.
1937 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1938 Stmt *Body) {
1939 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1940 }
John McCall53848232011-07-27 01:07:15 +00001941
Douglas Gregorf68a5082010-04-22 23:10:45 +00001942 /// \brief Build a new Objective-C fast enumeration statement.
1943 ///
1944 /// By default, performs semantic analysis to build the new statement.
1945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001946 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001947 Stmt *Element,
1948 Expr *Collection,
1949 SourceLocation RParenLoc,
1950 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001951 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001952 Element,
John McCallb268a282010-08-23 23:25:46 +00001953 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001954 RParenLoc);
1955 if (ForEachStmt.isInvalid())
1956 return StmtError();
1957
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001958 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001960
Douglas Gregorebe10102009-08-20 07:17:43 +00001961 /// \brief Build a new C++ exception declaration.
1962 ///
1963 /// By default, performs semantic analysis to build the new decaration.
1964 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001965 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001966 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001967 SourceLocation StartLoc,
1968 SourceLocation IdLoc,
1969 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001970 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001971 StartLoc, IdLoc, Id);
1972 if (Var)
1973 getSema().CurContext->addDecl(Var);
1974 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001975 }
1976
1977 /// \brief Build a new C++ catch statement.
1978 ///
1979 /// By default, performs semantic analysis to build the new statement.
1980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001981 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001982 VarDecl *ExceptionDecl,
1983 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001984 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1985 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001986 }
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregorebe10102009-08-20 07:17:43 +00001988 /// \brief Build a new C++ try statement.
1989 ///
1990 /// By default, performs semantic analysis to build the new statement.
1991 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001992 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1993 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001994 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001995 }
Mike Stump11289f42009-09-09 15:08:12 +00001996
Richard Smith02e85f32011-04-14 22:09:26 +00001997 /// \brief Build a new C++0x range-based for statement.
1998 ///
1999 /// By default, performs semantic analysis to build the new statement.
2000 /// Subclasses may override this routine to provide different behavior.
2001 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00002002 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00002003 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002004 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00002005 Expr *Cond, Expr *Inc,
2006 Stmt *LoopVar,
2007 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002008 // If we've just learned that the range is actually an Objective-C
2009 // collection, treat this as an Objective-C fast enumeration loop.
2010 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2011 if (RangeStmt->isSingleDecl()) {
2012 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002013 if (RangeVar->isInvalidDecl())
2014 return StmtError();
2015
Douglas Gregorf7106af2013-04-08 18:40:13 +00002016 Expr *RangeExpr = RangeVar->getInit();
2017 if (!RangeExpr->isTypeDependent() &&
2018 RangeExpr->getType()->isObjCObjectPointerType())
2019 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2020 RParenLoc);
2021 }
2022 }
2023 }
2024
Richard Smithcfd53b42015-10-22 06:13:50 +00002025 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002026 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00002027 Cond, Inc, LoopVar, RParenLoc,
2028 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002029 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002030
2031 /// \brief Build a new C++0x range-based for statement.
2032 ///
2033 /// By default, performs semantic analysis to build the new statement.
2034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002035 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002036 bool IsIfExists,
2037 NestedNameSpecifierLoc QualifierLoc,
2038 DeclarationNameInfo NameInfo,
2039 Stmt *Nested) {
2040 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2041 QualifierLoc, NameInfo, Nested);
2042 }
2043
Richard Smith02e85f32011-04-14 22:09:26 +00002044 /// \brief Attach body to a C++0x range-based for statement.
2045 ///
2046 /// By default, performs semantic analysis to finish the new statement.
2047 /// Subclasses may override this routine to provide different behavior.
2048 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2049 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002051
David Majnemerfad8f482013-10-15 09:33:02 +00002052 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002053 Stmt *TryBlock, Stmt *Handler) {
2054 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002055 }
2056
David Majnemerfad8f482013-10-15 09:33:02 +00002057 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002058 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002059 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002060 }
2061
David Majnemerfad8f482013-10-15 09:33:02 +00002062 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002063 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002064 }
2065
Alexey Bataevec474782014-10-09 08:45:04 +00002066 /// \brief Build a new predefined expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
2070 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2071 PredefinedExpr::IdentType IT) {
2072 return getSema().BuildPredefinedExpr(Loc, IT);
2073 }
2074
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 /// \brief Build a new expression that references a declaration.
2076 ///
2077 /// By default, performs semantic analysis to build the new expression.
2078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002079 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002080 LookupResult &R,
2081 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002082 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2083 }
2084
2085
2086 /// \brief Build a new expression that references a declaration.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002090 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002091 ValueDecl *VD,
2092 const DeclarationNameInfo &NameInfo,
2093 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002094 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002095 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002096
2097 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002098
2099 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 }
Mike Stump11289f42009-09-09 15:08:12 +00002101
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002106 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002108 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 }
2110
Douglas Gregorad8a3362009-09-04 17:36:40 +00002111 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002112 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002113 /// By default, performs semantic analysis to build the new expression.
2114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002115 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002116 SourceLocation OperatorLoc,
2117 bool isArrow,
2118 CXXScopeSpec &SS,
2119 TypeSourceInfo *ScopeType,
2120 SourceLocation CCLoc,
2121 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002122 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002123
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002129 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002130 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002131 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 }
Mike Stump11289f42009-09-09 15:08:12 +00002133
Douglas Gregor882211c2010-04-28 22:16:22 +00002134 /// \brief Build a new builtin offsetof expression.
2135 ///
2136 /// By default, performs semantic analysis to build the new expression.
2137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002138 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002139 TypeSourceInfo *Type,
2140 ArrayRef<Sema::OffsetOfComponent> Components,
2141 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002142 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002143 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002144 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002145
2146 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002147 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002148 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002149 /// By default, performs semantic analysis to build the new expression.
2150 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002151 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2152 SourceLocation OpLoc,
2153 UnaryExprOrTypeTrait ExprKind,
2154 SourceRange R) {
2155 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 }
2157
Peter Collingbournee190dee2011-03-11 19:24:49 +00002158 /// \brief Build a new sizeof, alignof or vec step expression with an
2159 /// expression 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(Expr *SubExpr, SourceLocation OpLoc,
2164 UnaryExprOrTypeTrait ExprKind,
2165 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002167 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002170
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002171 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 }
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002175 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 /// By default, performs semantic analysis to build the new expression.
2177 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002178 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002180 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002182 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002183 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 RBracketLoc);
2185 }
2186
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002187 /// \brief Build a new array section expression.
2188 ///
2189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
2191 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2192 Expr *LowerBound,
2193 SourceLocation ColonLoc, Expr *Length,
2194 SourceLocation RBracketLoc) {
2195 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2196 ColonLoc, Length, RBracketLoc);
2197 }
2198
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002200 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002203 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002205 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002206 Expr *ExecConfig = nullptr) {
2207 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002208 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
2210
2211 /// \brief Build a new member access 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002216 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002217 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002218 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002219 const DeclarationNameInfo &MemberNameInfo,
2220 ValueDecl *Member,
2221 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002222 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002223 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002224 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2225 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002226 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002227 // We have a reference to an unnamed field. This is always the
2228 // base of an anonymous struct/union member access, i.e. the
2229 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002230 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002231 assert(Member->getType()->isRecordType() &&
2232 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002233
Richard Smithcab9a7d2011-10-26 19:06:56 +00002234 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002235 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002236 QualifierLoc.getNestedNameSpecifier(),
2237 FoundDecl, Member);
2238 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002239 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002240 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002241 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002242 MemberExpr *ME = new (getSema().Context)
2243 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2244 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002245 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002246 }
Mike Stump11289f42009-09-09 15:08:12 +00002247
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002248 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002249 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002250
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002251 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002252 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002253
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002254 if (isArrow && !BaseType->isPointerType())
2255 return ExprError();
2256
John McCall16df1e52010-03-30 21:47:33 +00002257 // FIXME: this involves duplicating earlier analysis in a lot of
2258 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002259 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002260 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002261 R.resolveKind();
2262
John McCallb268a282010-08-23 23:25:46 +00002263 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002264 SS, TemplateKWLoc,
2265 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002266 R, ExplicitTemplateArgs,
2267 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
Mike Stump11289f42009-09-09 15:08:12 +00002269
Douglas Gregora16548e2009-08-11 05:31:07 +00002270 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002271 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002274 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002275 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002276 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002277 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 }
2279
2280 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002281 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002284 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002285 SourceLocation QuestionLoc,
2286 Expr *LHS,
2287 SourceLocation ColonLoc,
2288 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002289 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2290 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 }
2292
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002294 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 /// By default, performs semantic analysis to build the new expression.
2296 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002297 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002298 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002300 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002301 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002302 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 }
Mike Stump11289f42009-09-09 15:08:12 +00002304
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 /// \brief Build a new compound literal 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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002310 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002312 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002313 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002314 Init);
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 extended vector element access 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 RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 SourceLocation OpLoc,
2323 SourceLocation AccessorLoc,
2324 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002325
John McCall10eae182009-11-30 22:42:35 +00002326 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002327 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002328 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002329 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002330 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002331 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002332 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002333 /* TemplateArgs */ nullptr,
2334 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002338 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002341 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002342 MultiExprArg Inits,
2343 SourceLocation RBraceLoc,
2344 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002345 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002346 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002347 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002348 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002349
Douglas Gregord3d93062009-11-09 17:16:50 +00002350 // Patch in the result type we were given, which may have been computed
2351 // when the initial InitListExpr was built.
2352 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2353 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002354 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 }
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002358 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002361 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002362 MultiExprArg ArrayExprs,
2363 SourceLocation EqualOrColonLoc,
2364 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002365 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002366 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002368 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002370 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002371
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002372 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 }
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002376 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002377 /// By default, builds the implicit value initialization without performing
2378 /// any semantic analysis. Subclasses may override this routine to provide
2379 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002380 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002381 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 }
Mike Stump11289f42009-09-09 15:08:12 +00002383
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002385 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002388 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002389 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002390 SourceLocation RParenLoc) {
2391 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002392 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002393 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 }
2395
2396 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002397 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002400 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002401 MultiExprArg SubExprs,
2402 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002403 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
Mike Stump11289f42009-09-09 15:08:12 +00002405
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002407 ///
2408 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 /// rather than attempting to map the label statement itself.
2410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002411 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002412 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002413 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002414 }
Mike Stump11289f42009-09-09 15:08:12 +00002415
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002417 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 /// By default, performs semantic analysis to build the new expression.
2419 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002420 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002421 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002423 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 }
Mike Stump11289f42009-09-09 15:08:12 +00002425
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 /// \brief Build a new __builtin_choose_expr expression.
2427 ///
2428 /// By default, performs semantic analysis to build the new expression.
2429 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002430 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002431 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 SourceLocation RParenLoc) {
2433 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002434 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 RParenLoc);
2436 }
Mike Stump11289f42009-09-09 15:08:12 +00002437
Peter Collingbourne91147592011-04-15 00:35:48 +00002438 /// \brief Build a new generic selection expression.
2439 ///
2440 /// By default, performs semantic analysis to build the new expression.
2441 /// Subclasses may override this routine to provide different behavior.
2442 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2443 SourceLocation DefaultLoc,
2444 SourceLocation RParenLoc,
2445 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002446 ArrayRef<TypeSourceInfo *> Types,
2447 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002448 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002449 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002450 }
2451
Douglas Gregora16548e2009-08-11 05:31:07 +00002452 /// \brief Build a new overloaded operator call expression.
2453 ///
2454 /// By default, performs semantic analysis to build the new expression.
2455 /// The semantic analysis provides the behavior of template instantiation,
2456 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002457 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002458 /// argument-dependent lookup, etc. Subclasses may override this routine to
2459 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002460 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002462 Expr *Callee,
2463 Expr *First,
2464 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002465
2466 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 /// reinterpret_cast.
2468 ///
2469 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002470 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002472 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 Stmt::StmtClass Class,
2474 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002475 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 SourceLocation RAngleLoc,
2477 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002478 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002479 SourceLocation RParenLoc) {
2480 switch (Class) {
2481 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002482 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002483 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002484 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002485
2486 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002487 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002488 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002489 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002490
Douglas Gregora16548e2009-08-11 05:31:07 +00002491 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002492 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002493 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002494 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002496
Douglas Gregora16548e2009-08-11 05:31:07 +00002497 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002498 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002499 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002500 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002501
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002503 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002504 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002505 }
Mike Stump11289f42009-09-09 15:08:12 +00002506
Douglas Gregora16548e2009-08-11 05:31:07 +00002507 /// \brief Build a new C++ static_cast expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002511 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002513 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 SourceLocation RAngleLoc,
2515 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002516 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002517 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002518 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002519 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002520 SourceRange(LAngleLoc, RAngleLoc),
2521 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 }
2523
2524 /// \brief Build a new C++ dynamic_cast expression.
2525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002528 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002529 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002530 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 SourceLocation RAngleLoc,
2532 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002533 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002534 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002535 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002536 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002537 SourceRange(LAngleLoc, RAngleLoc),
2538 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 }
2540
2541 /// \brief Build a new C++ reinterpret_cast expression.
2542 ///
2543 /// By default, performs semantic analysis to build the new expression.
2544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002545 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002547 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 SourceLocation RAngleLoc,
2549 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002550 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002552 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002553 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002554 SourceRange(LAngleLoc, RAngleLoc),
2555 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002556 }
2557
2558 /// \brief Build a new C++ const_cast expression.
2559 ///
2560 /// By default, performs semantic analysis to build the new expression.
2561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002562 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002563 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002564 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002565 SourceLocation RAngleLoc,
2566 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002567 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002569 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002570 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002571 SourceRange(LAngleLoc, RAngleLoc),
2572 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 }
Mike Stump11289f42009-09-09 15:08:12 +00002574
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 /// \brief Build a new C++ functional-style cast expression.
2576 ///
2577 /// By default, performs semantic analysis to build the new expression.
2578 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002579 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2580 SourceLocation LParenLoc,
2581 Expr *Sub,
2582 SourceLocation RParenLoc) {
2583 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002584 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002585 RParenLoc);
2586 }
Mike Stump11289f42009-09-09 15:08:12 +00002587
Douglas Gregora16548e2009-08-11 05:31:07 +00002588 /// \brief Build a new C++ typeid(type) expression.
2589 ///
2590 /// By default, performs semantic analysis to build the new expression.
2591 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002592 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002593 SourceLocation TypeidLoc,
2594 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002595 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002596 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002597 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 }
Mike Stump11289f42009-09-09 15:08:12 +00002599
Francois Pichet9f4f2072010-09-08 12:20:18 +00002600
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 /// \brief Build a new C++ typeid(expr) expression.
2602 ///
2603 /// By default, performs semantic analysis to build the new expression.
2604 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002605 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002606 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002607 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002608 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002609 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002610 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002611 }
2612
Francois Pichet9f4f2072010-09-08 12:20:18 +00002613 /// \brief Build a new C++ __uuidof(type) expression.
2614 ///
2615 /// By default, performs semantic analysis to build the new expression.
2616 /// Subclasses may override this routine to provide different behavior.
2617 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2618 SourceLocation TypeidLoc,
2619 TypeSourceInfo *Operand,
2620 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002621 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002622 RParenLoc);
2623 }
2624
2625 /// \brief Build a new C++ __uuidof(expr) expression.
2626 ///
2627 /// By default, performs semantic analysis to build the new expression.
2628 /// Subclasses may override this routine to provide different behavior.
2629 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2630 SourceLocation TypeidLoc,
2631 Expr *Operand,
2632 SourceLocation RParenLoc) {
2633 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2634 RParenLoc);
2635 }
2636
Douglas Gregora16548e2009-08-11 05:31:07 +00002637 /// \brief Build a new C++ "this" expression.
2638 ///
2639 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002640 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002641 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002642 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002643 QualType ThisType,
2644 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002645 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002646 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002647 }
2648
2649 /// \brief Build a new C++ throw expression.
2650 ///
2651 /// By default, performs semantic analysis to build the new expression.
2652 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002653 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2654 bool IsThrownVariableInScope) {
2655 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002656 }
2657
2658 /// \brief Build a new C++ default-argument expression.
2659 ///
2660 /// By default, builds a new default-argument expression, which does not
2661 /// require any semantic analysis. Subclasses may override this routine to
2662 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002663 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002664 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002665 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002666 }
2667
Richard Smith852c9db2013-04-20 22:23:05 +00002668 /// \brief Build a new C++11 default-initialization expression.
2669 ///
2670 /// By default, builds a new default field initialization expression, which
2671 /// does not require any semantic analysis. Subclasses may override this
2672 /// routine to provide different behavior.
2673 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2674 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002675 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002676 }
2677
Douglas Gregora16548e2009-08-11 05:31:07 +00002678 /// \brief Build a new C++ zero-initialization expression.
2679 ///
2680 /// By default, performs semantic analysis to build the new expression.
2681 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002682 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2683 SourceLocation LParenLoc,
2684 SourceLocation RParenLoc) {
2685 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002686 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002687 }
Mike Stump11289f42009-09-09 15:08:12 +00002688
Douglas Gregora16548e2009-08-11 05:31:07 +00002689 /// \brief Build a new C++ "new" expression.
2690 ///
2691 /// By default, performs semantic analysis to build the new expression.
2692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002693 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002694 bool UseGlobal,
2695 SourceLocation PlacementLParen,
2696 MultiExprArg PlacementArgs,
2697 SourceLocation PlacementRParen,
2698 SourceRange TypeIdParens,
2699 QualType AllocatedType,
2700 TypeSourceInfo *AllocatedTypeInfo,
2701 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002702 SourceRange DirectInitRange,
2703 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002704 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002705 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002706 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002707 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002708 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002709 AllocatedType,
2710 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002711 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002712 DirectInitRange,
2713 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002714 }
Mike Stump11289f42009-09-09 15:08:12 +00002715
Douglas Gregora16548e2009-08-11 05:31:07 +00002716 /// \brief Build a new C++ "delete" expression.
2717 ///
2718 /// By default, performs semantic analysis to build the new expression.
2719 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002720 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002721 bool IsGlobalDelete,
2722 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002723 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002724 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002725 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002726 }
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregor29c42f22012-02-24 07:38:34 +00002728 /// \brief Build a new type trait expression.
2729 ///
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
2732 ExprResult RebuildTypeTrait(TypeTrait Trait,
2733 SourceLocation StartLoc,
2734 ArrayRef<TypeSourceInfo *> Args,
2735 SourceLocation RParenLoc) {
2736 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002738
John Wiegley6242b6a2011-04-28 00:16:57 +00002739 /// \brief Build a new array type trait expression.
2740 ///
2741 /// By default, performs semantic analysis to build the new expression.
2742 /// Subclasses may override this routine to provide different behavior.
2743 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2744 SourceLocation StartLoc,
2745 TypeSourceInfo *TSInfo,
2746 Expr *DimExpr,
2747 SourceLocation RParenLoc) {
2748 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2749 }
2750
John Wiegleyf9f65842011-04-25 06:54:41 +00002751 /// \brief Build a new expression trait expression.
2752 ///
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
2755 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2756 SourceLocation StartLoc,
2757 Expr *Queried,
2758 SourceLocation RParenLoc) {
2759 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2760 }
2761
Mike Stump11289f42009-09-09 15:08:12 +00002762 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002763 /// expression.
2764 ///
2765 /// By default, performs semantic analysis to build the new expression.
2766 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002767 ExprResult RebuildDependentScopeDeclRefExpr(
2768 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002769 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002770 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002771 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002772 bool IsAddressOfOperand,
2773 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002774 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002775 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002776
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002777 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002778 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2779 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002780
Reid Kleckner32506ed2014-06-12 23:03:48 +00002781 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002782 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002783 }
2784
2785 /// \brief Build a new template-id expression.
2786 ///
2787 /// By default, performs semantic analysis to build the new expression.
2788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002789 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002790 SourceLocation TemplateKWLoc,
2791 LookupResult &R,
2792 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002793 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002794 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2795 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002796 }
2797
2798 /// \brief Build a new object-construction expression.
2799 ///
2800 /// By default, performs semantic analysis to build the new expression.
2801 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002802 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002803 SourceLocation Loc,
2804 CXXConstructorDecl *Constructor,
2805 bool IsElidable,
2806 MultiExprArg Args,
2807 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002808 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002809 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002810 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002811 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002812 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002813 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002814 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002815 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002816 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002817
Richard Smithc83bf822016-06-10 00:58:19 +00002818 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002819 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002820 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002821 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002822 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002823 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002824 RequiresZeroInit, ConstructKind,
2825 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002826 }
2827
Richard Smith5179eb72016-06-28 19:03:57 +00002828 /// \brief Build a new implicit construction via inherited constructor
2829 /// expression.
2830 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2831 CXXConstructorDecl *Constructor,
2832 bool ConstructsVBase,
2833 bool InheritedFromVBase) {
2834 return new (getSema().Context) CXXInheritedCtorInitExpr(
2835 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2836 }
2837
Douglas Gregora16548e2009-08-11 05:31:07 +00002838 /// \brief Build a new object-construction expression.
2839 ///
2840 /// By default, performs semantic analysis to build the new expression.
2841 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002842 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2843 SourceLocation LParenLoc,
2844 MultiExprArg Args,
2845 SourceLocation RParenLoc) {
2846 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002847 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002848 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002849 RParenLoc);
2850 }
2851
2852 /// \brief Build a new object-construction expression.
2853 ///
2854 /// By default, performs semantic analysis to build the new expression.
2855 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002856 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2857 SourceLocation LParenLoc,
2858 MultiExprArg Args,
2859 SourceLocation RParenLoc) {
2860 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002861 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002862 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002863 RParenLoc);
2864 }
Mike Stump11289f42009-09-09 15:08:12 +00002865
Douglas Gregora16548e2009-08-11 05:31:07 +00002866 /// \brief Build a new member reference expression.
2867 ///
2868 /// By default, performs semantic analysis to build the new expression.
2869 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002870 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002871 QualType BaseType,
2872 bool IsArrow,
2873 SourceLocation OperatorLoc,
2874 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002875 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002876 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002877 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002878 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002879 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002880 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002881
John McCallb268a282010-08-23 23:25:46 +00002882 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002883 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002884 SS, TemplateKWLoc,
2885 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002886 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002887 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002888 }
2889
John McCall10eae182009-11-30 22:42:35 +00002890 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002891 ///
2892 /// By default, performs semantic analysis to build the new expression.
2893 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002894 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2895 SourceLocation OperatorLoc,
2896 bool IsArrow,
2897 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002898 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002899 NamedDecl *FirstQualifierInScope,
2900 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002901 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002902 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002903 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002904
John McCallb268a282010-08-23 23:25:46 +00002905 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002906 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002907 SS, TemplateKWLoc,
2908 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002909 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002910 }
Mike Stump11289f42009-09-09 15:08:12 +00002911
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002912 /// \brief Build a new noexcept expression.
2913 ///
2914 /// By default, performs semantic analysis to build the new expression.
2915 /// Subclasses may override this routine to provide different behavior.
2916 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2917 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2918 }
2919
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002920 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002921 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2922 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002923 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002924 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002925 Optional<unsigned> Length,
2926 ArrayRef<TemplateArgument> PartialArgs) {
2927 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2928 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002929 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002930
Patrick Beard0caa3942012-04-19 00:25:12 +00002931 /// \brief Build a new Objective-C boxed expression.
2932 ///
2933 /// By default, performs semantic analysis to build the new expression.
2934 /// Subclasses may override this routine to provide different behavior.
2935 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2936 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002938
Ted Kremeneke65b0862012-03-06 20:05:56 +00002939 /// \brief Build a new Objective-C array literal.
2940 ///
2941 /// By default, performs semantic analysis to build the new expression.
2942 /// Subclasses may override this routine to provide different behavior.
2943 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2944 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002945 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002946 MultiExprArg(Elements, NumElements));
2947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
2949 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002950 Expr *Base, Expr *Key,
2951 ObjCMethodDecl *getterMethod,
2952 ObjCMethodDecl *setterMethod) {
2953 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2954 getterMethod, setterMethod);
2955 }
2956
2957 /// \brief Build a new Objective-C dictionary literal.
2958 ///
2959 /// By default, performs semantic analysis to build the new expression.
2960 /// Subclasses may override this routine to provide different behavior.
2961 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002962 MutableArrayRef<ObjCDictionaryElement> Elements) {
2963 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002965
James Dennett2a4d13c2012-06-15 07:13:21 +00002966 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002967 ///
2968 /// By default, performs semantic analysis to build the new expression.
2969 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002970 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002971 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002972 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002973 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002974 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002975
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002976 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002977 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002978 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002979 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002980 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002981 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002982 MultiExprArg Args,
2983 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002984 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2985 ReceiverTypeInfo->getType(),
2986 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002987 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002988 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002989 }
2990
2991 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002992 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002993 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002994 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002995 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002996 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002997 MultiExprArg Args,
2998 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002999 return SemaRef.BuildInstanceMessage(Receiver,
3000 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003001 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003002 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003003 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003004 }
3005
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003006 /// \brief Build a new Objective-C instance/class message to 'super'.
3007 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3008 Selector Sel,
3009 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003010 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003011 ObjCMethodDecl *Method,
3012 SourceLocation LBracLoc,
3013 MultiExprArg Args,
3014 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003015 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003016 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003017 SuperLoc,
3018 Sel, Method, LBracLoc, SelectorLocs,
3019 RBracLoc, Args)
3020 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003021 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003022 SuperLoc,
3023 Sel, Method, LBracLoc, SelectorLocs,
3024 RBracLoc, Args);
3025
3026
3027 }
3028
Douglas Gregord51d90d2010-04-26 20:11:03 +00003029 /// \brief Build a new Objective-C ivar reference expression.
3030 ///
3031 /// By default, performs semantic analysis to build the new expression.
3032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003033 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003034 SourceLocation IvarLoc,
3035 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003036 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003037 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003038 ExprResult Result = getSema().BuildMemberReferenceExpr(
3039 BaseArg, BaseArg->getType(),
3040 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3041 /*FirstQualifierInScope=*/nullptr, NameInfo,
3042 /*TemplateArgs=*/nullptr,
3043 /*S=*/nullptr);
3044 if (IsFreeIvar && Result.isUsable())
3045 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3046 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003047 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003048
3049 /// \brief Build a new Objective-C property reference expression.
3050 ///
3051 /// By default, performs semantic analysis to build the new expression.
3052 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003053 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003054 ObjCPropertyDecl *Property,
3055 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003056 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003057 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3058 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3059 /*FIXME:*/PropertyLoc,
3060 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003061 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003062 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003063 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003064 /*TemplateArgs=*/nullptr,
3065 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003066 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003067
John McCallb7bd14f2010-12-02 01:19:52 +00003068 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003069 ///
3070 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003071 /// Subclasses may override this routine to provide different behavior.
3072 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3073 ObjCMethodDecl *Getter,
3074 ObjCMethodDecl *Setter,
3075 SourceLocation PropertyLoc) {
3076 // Since these expressions can only be value-dependent, we do not
3077 // need to perform semantic analysis again.
3078 return Owned(
3079 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3080 VK_LValue, OK_ObjCProperty,
3081 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003082 }
3083
Douglas Gregord51d90d2010-04-26 20:11:03 +00003084 /// \brief Build a new Objective-C "isa" expression.
3085 ///
3086 /// By default, performs semantic analysis to build the new expression.
3087 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003088 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003089 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003090 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003091 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3092 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003093 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003094 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003095 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003096 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003097 /*TemplateArgs=*/nullptr,
3098 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
Douglas Gregora16548e2009-08-11 05:31:07 +00003101 /// \brief Build a new shuffle vector expression.
3102 ///
3103 /// By default, performs semantic analysis to build the new expression.
3104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003105 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003106 MultiExprArg SubExprs,
3107 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003108 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003109 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003110 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3111 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3112 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003113 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003114
Douglas Gregora16548e2009-08-11 05:31:07 +00003115 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003116 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003117 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3118 SemaRef.Context.BuiltinFnTy,
3119 VK_RValue, BuiltinLoc);
3120 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3121 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003122 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003123
3124 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003125 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003126 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003127 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003128
Douglas Gregora16548e2009-08-11 05:31:07 +00003129 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003130 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003131 }
John McCall31f82722010-11-12 08:19:04 +00003132
Hal Finkelc4d7c822013-09-18 03:29:45 +00003133 /// \brief Build a new convert vector expression.
3134 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3135 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3136 SourceLocation RParenLoc) {
3137 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3138 BuiltinLoc, RParenLoc);
3139 }
3140
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003141 /// \brief Build a new template argument pack expansion.
3142 ///
3143 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003144 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003145 /// different behavior.
3146 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003147 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003148 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003149 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003150 case TemplateArgument::Expression: {
3151 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003152 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3153 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003154 if (Result.isInvalid())
3155 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003156
Douglas Gregor98318c22011-01-03 21:37:45 +00003157 return TemplateArgumentLoc(Result.get(), Result.get());
3158 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003159
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003160 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003161 return TemplateArgumentLoc(TemplateArgument(
3162 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003163 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003164 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003165 Pattern.getTemplateNameLoc(),
3166 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003167
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003168 case TemplateArgument::Null:
3169 case TemplateArgument::Integral:
3170 case TemplateArgument::Declaration:
3171 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003172 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003173 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003174 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003176 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003177 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003178 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003179 EllipsisLoc,
3180 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003181 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3182 Expansion);
3183 break;
3184 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003185
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003186 return TemplateArgumentLoc();
3187 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003188
Douglas Gregor968f23a2011-01-03 19:31:53 +00003189 /// \brief Build a new expression pack expansion.
3190 ///
3191 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003192 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003193 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003194 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003195 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003196 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003197 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003198
Richard Smith0f0af192014-11-08 05:07:16 +00003199 /// \brief Build a new C++1z fold-expression.
3200 ///
3201 /// By default, performs semantic analysis in order to build a new fold
3202 /// expression.
3203 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3204 BinaryOperatorKind Operator,
3205 SourceLocation EllipsisLoc, Expr *RHS,
3206 SourceLocation RParenLoc) {
3207 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3208 RHS, RParenLoc);
3209 }
3210
3211 /// \brief Build an empty C++1z fold-expression with the given operator.
3212 ///
3213 /// By default, produces the fallback value for the fold-expression, or
3214 /// produce an error if there is no fallback value.
3215 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3216 BinaryOperatorKind Operator) {
3217 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3218 }
3219
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003220 /// \brief Build a new atomic operation expression.
3221 ///
3222 /// By default, performs semantic analysis to build the new expression.
3223 /// Subclasses may override this routine to provide different behavior.
3224 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3225 MultiExprArg SubExprs,
3226 QualType RetTy,
3227 AtomicExpr::AtomicOp Op,
3228 SourceLocation RParenLoc) {
3229 // Just create the expression; there is not any interesting semantic
3230 // analysis here because we can't actually build an AtomicExpr until
3231 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003232 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003233 RParenLoc);
3234 }
3235
John McCall31f82722010-11-12 08:19:04 +00003236private:
Douglas Gregor14454802011-02-25 02:25:35 +00003237 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3238 QualType ObjectType,
3239 NamedDecl *FirstQualifierInScope,
3240 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003241
3242 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3243 QualType ObjectType,
3244 NamedDecl *FirstQualifierInScope,
3245 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003246
3247 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3248 NamedDecl *FirstQualifierInScope,
3249 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003250
3251 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3252 DependentNameTypeLoc TL,
3253 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003254};
Douglas Gregora16548e2009-08-11 05:31:07 +00003255
Douglas Gregorebe10102009-08-20 07:17:43 +00003256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003257StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003258 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003259 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003260
Douglas Gregorebe10102009-08-20 07:17:43 +00003261 switch (S->getStmtClass()) {
3262 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregorebe10102009-08-20 07:17:43 +00003264 // Transform individual statement nodes
3265#define STMT(Node, Parent) \
3266 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003267#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003268#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003269#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003270
Douglas Gregorebe10102009-08-20 07:17:43 +00003271 // Transform expressions by calling TransformExpr.
3272#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003273#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003274#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003275#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 {
John McCalldadc5752010-08-24 06:29:42 +00003277 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003278 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003279 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003280
Richard Smith945f8d32013-01-14 22:39:08 +00003281 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003282 }
Mike Stump11289f42009-09-09 15:08:12 +00003283 }
3284
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003285 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003286}
Mike Stump11289f42009-09-09 15:08:12 +00003287
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003288template<typename Derived>
3289OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3290 if (!S)
3291 return S;
3292
3293 switch (S->getClauseKind()) {
3294 default: break;
3295 // Transform individual clause nodes
3296#define OPENMP_CLAUSE(Name, Class) \
3297 case OMPC_ ## Name : \
3298 return getDerived().Transform ## Class(cast<Class>(S));
3299#include "clang/Basic/OpenMPKinds.def"
3300 }
3301
3302 return S;
3303}
3304
Mike Stump11289f42009-09-09 15:08:12 +00003305
Douglas Gregore922c772009-08-04 22:27:00 +00003306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003307ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003308 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003309 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003310
3311 switch (E->getStmtClass()) {
3312 case Stmt::NoStmtClass: break;
3313#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003314#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003315#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003316 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003317#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003318 }
3319
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003320 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003321}
3322
3323template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003324ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003325 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003326 // Initializers are instantiated like expressions, except that various outer
3327 // layers are stripped.
3328 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003329 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003330
3331 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3332 Init = ExprTemp->getSubExpr();
3333
Richard Smith410306b2016-12-12 02:53:20 +00003334 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3335 Init = AIL->getCommonExpr();
3336
Richard Smithe6ca4752013-05-30 22:40:16 +00003337 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3338 Init = MTE->GetTemporaryExpr();
3339
Richard Smithd59b8322012-12-19 01:39:02 +00003340 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3341 Init = Binder->getSubExpr();
3342
3343 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3344 Init = ICE->getSubExprAsWritten();
3345
Richard Smithcc1b96d2013-06-12 22:31:48 +00003346 if (CXXStdInitializerListExpr *ILE =
3347 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003348 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003349
Richard Smithc6abd962014-07-25 01:12:44 +00003350 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003351 // InitListExprs. Other forms of copy-initialization will be a no-op if
3352 // the initializer is already the right type.
3353 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003354 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003355 return getDerived().TransformExpr(Init);
3356
3357 // Revert value-initialization back to empty parens.
3358 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3359 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003360 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003361 Parens.getEnd());
3362 }
3363
3364 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3365 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003366 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003367 SourceLocation());
3368
3369 // Revert initialization by constructor back to a parenthesized or braced list
3370 // of expressions. Any other form of initializer can just be reused directly.
3371 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003372 return getDerived().TransformExpr(Init);
3373
Richard Smithf8adcdc2014-07-17 05:12:35 +00003374 // If the initialization implicitly converted an initializer list to a
3375 // std::initializer_list object, unwrap the std::initializer_list too.
3376 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003377 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003378
Richard Smithd59b8322012-12-19 01:39:02 +00003379 SmallVector<Expr*, 8> NewArgs;
3380 bool ArgChanged = false;
3381 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003382 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003383 return ExprError();
3384
3385 // If this was list initialization, revert to list form.
3386 if (Construct->isListInitialization())
3387 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3388 Construct->getLocEnd(),
3389 Construct->getType());
3390
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
4190 Qualifiers Quals;
4191 auto QTL = TL.getAs<QualifiedTypeLoc>();
4192 if (QTL)
4193 TL = QTL.getUnqualifiedLoc();
4194
4195 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4196
4197 QualType Result = getDerived().TransformDependentNameType(
4198 TLB, DNTL, /*DeducedTSTContext*/true);
4199 if (Result.isNull())
4200 return nullptr;
4201
4202 if (QTL) {
4203 Result = getDerived().RebuildQualifiedType(
4204 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4205 TLB.TypeWasModifiedSafely(Result);
4206 }
4207
4208 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4209}
4210
John McCall550e0c22009-10-21 00:40:46 +00004211template<typename Derived>
4212QualType
4213TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004214 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004215 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004216
John McCall31f82722010-11-12 08:19:04 +00004217 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004218 if (Result.isNull())
4219 return QualType();
4220
Richard Smithee579842017-01-30 20:39:26 +00004221 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4222
4223 // RebuildQualifiedType might have updated the type, but not in a way
4224 // that invalidates the TypeLoc. (There's no location information for
4225 // qualifiers.)
4226 TLB.TypeWasModifiedSafely(Result);
4227
4228 return Result;
4229}
4230
4231template<typename Derived>
4232QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4233 SourceLocation Loc,
4234 Qualifiers Quals) {
4235 // C++ [dcl.fct]p7:
4236 // [When] adding cv-qualifications on top of the function type [...] the
4237 // cv-qualifiers are ignored.
4238 // C++ [dcl.ref]p1:
4239 // when the cv-qualifiers are introduced through the use of a typedef-name
4240 // or decltype-specifier [...] the cv-qualifiers are ignored.
4241 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4242 // applied to a reference type.
4243 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4244 if (T->isFunctionType() || T->isReferenceType())
4245 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004246
John McCall31168b02011-06-15 23:02:42 +00004247 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004248 // resulting type.
4249 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004250 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004251 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004252 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004253 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004254 // A lifetime qualifier applied to a substituted template parameter
4255 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004256 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004257 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004258 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004259 QualType Replacement = SubstTypeParam->getReplacementType();
4260 Qualifiers Qs = Replacement.getQualifiers();
4261 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004262 Replacement = SemaRef.Context.getQualifiedType(
4263 Replacement.getUnqualifiedType(), Qs);
4264 T = SemaRef.Context.getSubstTemplateTypeParmType(
4265 SubstTypeParam->getReplacedParameter(), Replacement);
4266 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004267 // 'auto' types behave the same way as template parameters.
4268 QualType Deduced = AutoTy->getDeducedType();
4269 Qualifiers Qs = Deduced.getQualifiers();
4270 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004271 Deduced =
4272 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4273 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4274 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004275 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004276 // Otherwise, complain about the addition of a qualifier to an
4277 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004278 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4279 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004280 Quals.removeObjCLifetime();
4281 }
4282 }
4283 }
John McCall550e0c22009-10-21 00:40:46 +00004284
Richard Smithee579842017-01-30 20:39:26 +00004285 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004286}
4287
Douglas Gregor14454802011-02-25 02:25:35 +00004288template<typename Derived>
4289TypeLoc
4290TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4291 QualType ObjectType,
4292 NamedDecl *UnqualLookup,
4293 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004294 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004295 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004296
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004297 TypeSourceInfo *TSI =
4298 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4299 if (TSI)
4300 return TSI->getTypeLoc();
4301 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004302}
4303
Douglas Gregor579c15f2011-03-02 18:32:08 +00004304template<typename Derived>
4305TypeSourceInfo *
4306TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4307 QualType ObjectType,
4308 NamedDecl *UnqualLookup,
4309 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004310 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004311 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004312
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004313 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4314 UnqualLookup, SS);
4315}
4316
4317template <typename Derived>
4318TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4319 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4320 CXXScopeSpec &SS) {
4321 QualType T = TL.getType();
4322 assert(!getDerived().AlreadyTransformed(T));
4323
Douglas Gregor579c15f2011-03-02 18:32:08 +00004324 TypeLocBuilder TLB;
4325 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004326
Douglas Gregor579c15f2011-03-02 18:32:08 +00004327 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004328 TemplateSpecializationTypeLoc SpecTL =
4329 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004330
Richard Smithfd3dae02017-01-20 00:20:39 +00004331 TemplateName Template = getDerived().TransformTemplateName(
4332 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4333 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004334 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004335 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004336
4337 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004338 Template);
4339 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004340 DependentTemplateSpecializationTypeLoc SpecTL =
4341 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004342
Douglas Gregor579c15f2011-03-02 18:32:08 +00004343 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004344 = getDerived().RebuildTemplateName(SS,
4345 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004346 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004347 ObjectType, UnqualLookup,
4348 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004349 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004350 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004351
4352 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004353 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004354 Template,
4355 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004356 } else {
4357 // Nothing special needs to be done for these.
4358 Result = getDerived().TransformType(TLB, TL);
4359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004360
4361 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004362 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004363
Douglas Gregor579c15f2011-03-02 18:32:08 +00004364 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4365}
4366
John McCall550e0c22009-10-21 00:40:46 +00004367template <class TyLoc> static inline
4368QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4369 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4370 NewT.setNameLoc(T.getNameLoc());
4371 return T.getType();
4372}
4373
John McCall550e0c22009-10-21 00:40:46 +00004374template<typename Derived>
4375QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004376 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004377 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4378 NewT.setBuiltinLoc(T.getBuiltinLoc());
4379 if (T.needsExtraLocalData())
4380 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4381 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004382}
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregord6ff3322009-08-04 16:50:30 +00004384template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004385QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004386 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004387 // FIXME: recurse?
4388 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004389}
Mike Stump11289f42009-09-09 15:08:12 +00004390
Reid Kleckner0503a872013-12-05 01:23:43 +00004391template <typename Derived>
4392QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4393 AdjustedTypeLoc TL) {
4394 // Adjustments applied during transformation are handled elsewhere.
4395 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4396}
4397
Douglas Gregord6ff3322009-08-04 16:50:30 +00004398template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004399QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4400 DecayedTypeLoc TL) {
4401 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4402 if (OriginalType.isNull())
4403 return QualType();
4404
4405 QualType Result = TL.getType();
4406 if (getDerived().AlwaysRebuild() ||
4407 OriginalType != TL.getOriginalLoc().getType())
4408 Result = SemaRef.Context.getDecayedType(OriginalType);
4409 TLB.push<DecayedTypeLoc>(Result);
4410 // Nothing to set for DecayedTypeLoc.
4411 return Result;
4412}
4413
4414template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004415QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004416 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004417 QualType PointeeType
4418 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004419 if (PointeeType.isNull())
4420 return QualType();
4421
4422 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004423 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004424 // A dependent pointer type 'T *' has is being transformed such
4425 // that an Objective-C class type is being replaced for 'T'. The
4426 // resulting pointer type is an ObjCObjectPointerType, not a
4427 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004428 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004429
John McCall8b07ec22010-05-15 11:32:37 +00004430 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4431 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004432 return Result;
4433 }
John McCall31f82722010-11-12 08:19:04 +00004434
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004435 if (getDerived().AlwaysRebuild() ||
4436 PointeeType != TL.getPointeeLoc().getType()) {
4437 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4438 if (Result.isNull())
4439 return QualType();
4440 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004441
John McCall31168b02011-06-15 23:02:42 +00004442 // Objective-C ARC can add lifetime qualifiers to the type that we're
4443 // pointing to.
4444 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004445
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004446 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4447 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004448 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004449}
Mike Stump11289f42009-09-09 15:08:12 +00004450
4451template<typename Derived>
4452QualType
John McCall550e0c22009-10-21 00:40:46 +00004453TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004454 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004455 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004456 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4457 if (PointeeType.isNull())
4458 return QualType();
4459
4460 QualType Result = TL.getType();
4461 if (getDerived().AlwaysRebuild() ||
4462 PointeeType != TL.getPointeeLoc().getType()) {
4463 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004464 TL.getSigilLoc());
4465 if (Result.isNull())
4466 return QualType();
4467 }
4468
Douglas Gregor049211a2010-04-22 16:50:51 +00004469 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004470 NewT.setSigilLoc(TL.getSigilLoc());
4471 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004472}
4473
John McCall70dd5f62009-10-30 00:06:24 +00004474/// Transforms a reference type. Note that somewhat paradoxically we
4475/// don't care whether the type itself is an l-value type or an r-value
4476/// type; we only care if the type was *written* as an l-value type
4477/// or an r-value type.
4478template<typename Derived>
4479QualType
4480TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004481 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004482 const ReferenceType *T = TL.getTypePtr();
4483
4484 // Note that this works with the pointee-as-written.
4485 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4486 if (PointeeType.isNull())
4487 return QualType();
4488
4489 QualType Result = TL.getType();
4490 if (getDerived().AlwaysRebuild() ||
4491 PointeeType != T->getPointeeTypeAsWritten()) {
4492 Result = getDerived().RebuildReferenceType(PointeeType,
4493 T->isSpelledAsLValue(),
4494 TL.getSigilLoc());
4495 if (Result.isNull())
4496 return QualType();
4497 }
4498
John McCall31168b02011-06-15 23:02:42 +00004499 // Objective-C ARC can add lifetime qualifiers to the type that we're
4500 // referring to.
4501 TLB.TypeWasModifiedSafely(
4502 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4503
John McCall70dd5f62009-10-30 00:06:24 +00004504 // r-value references can be rebuilt as l-value references.
4505 ReferenceTypeLoc NewTL;
4506 if (isa<LValueReferenceType>(Result))
4507 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4508 else
4509 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4510 NewTL.setSigilLoc(TL.getSigilLoc());
4511
4512 return Result;
4513}
4514
Mike Stump11289f42009-09-09 15:08:12 +00004515template<typename Derived>
4516QualType
John McCall550e0c22009-10-21 00:40:46 +00004517TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004518 LValueReferenceTypeLoc TL) {
4519 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004520}
4521
Mike Stump11289f42009-09-09 15:08:12 +00004522template<typename Derived>
4523QualType
John McCall550e0c22009-10-21 00:40:46 +00004524TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004525 RValueReferenceTypeLoc TL) {
4526 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004527}
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004530QualType
John McCall550e0c22009-10-21 00:40:46 +00004531TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004532 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004533 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004534 if (PointeeType.isNull())
4535 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004536
Abramo Bagnara509357842011-03-05 14:42:21 +00004537 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004538 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004539 if (OldClsTInfo) {
4540 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4541 if (!NewClsTInfo)
4542 return QualType();
4543 }
4544
4545 const MemberPointerType *T = TL.getTypePtr();
4546 QualType OldClsType = QualType(T->getClass(), 0);
4547 QualType NewClsType;
4548 if (NewClsTInfo)
4549 NewClsType = NewClsTInfo->getType();
4550 else {
4551 NewClsType = getDerived().TransformType(OldClsType);
4552 if (NewClsType.isNull())
4553 return QualType();
4554 }
Mike Stump11289f42009-09-09 15:08:12 +00004555
John McCall550e0c22009-10-21 00:40:46 +00004556 QualType Result = TL.getType();
4557 if (getDerived().AlwaysRebuild() ||
4558 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004559 NewClsType != OldClsType) {
4560 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004561 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004562 if (Result.isNull())
4563 return QualType();
4564 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004565
Reid Kleckner0503a872013-12-05 01:23:43 +00004566 // If we had to adjust the pointee type when building a member pointer, make
4567 // sure to push TypeLoc info for it.
4568 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4569 if (MPT && PointeeType != MPT->getPointeeType()) {
4570 assert(isa<AdjustedType>(MPT->getPointeeType()));
4571 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4572 }
4573
John McCall550e0c22009-10-21 00:40:46 +00004574 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4575 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004576 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004577
4578 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004579}
4580
Mike Stump11289f42009-09-09 15:08:12 +00004581template<typename Derived>
4582QualType
John McCall550e0c22009-10-21 00:40:46 +00004583TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004584 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004585 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004586 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004587 if (ElementType.isNull())
4588 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004589
John McCall550e0c22009-10-21 00:40:46 +00004590 QualType Result = TL.getType();
4591 if (getDerived().AlwaysRebuild() ||
4592 ElementType != T->getElementType()) {
4593 Result = getDerived().RebuildConstantArrayType(ElementType,
4594 T->getSizeModifier(),
4595 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004596 T->getIndexTypeCVRQualifiers(),
4597 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004598 if (Result.isNull())
4599 return QualType();
4600 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004601
4602 // We might have either a ConstantArrayType or a VariableArrayType now:
4603 // a ConstantArrayType is allowed to have an element type which is a
4604 // VariableArrayType if the type is dependent. Fortunately, all array
4605 // types have the same location layout.
4606 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004607 NewTL.setLBracketLoc(TL.getLBracketLoc());
4608 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004609
John McCall550e0c22009-10-21 00:40:46 +00004610 Expr *Size = TL.getSizeExpr();
4611 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004612 EnterExpressionEvaluationContext Unevaluated(
4613 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004614 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4615 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004616 }
4617 NewTL.setSizeExpr(Size);
4618
4619 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004620}
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregord6ff3322009-08-04 16:50:30 +00004622template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004623QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004624 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004625 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004626 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004627 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004628 if (ElementType.isNull())
4629 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004630
John McCall550e0c22009-10-21 00:40:46 +00004631 QualType Result = TL.getType();
4632 if (getDerived().AlwaysRebuild() ||
4633 ElementType != T->getElementType()) {
4634 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004635 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004636 T->getIndexTypeCVRQualifiers(),
4637 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004638 if (Result.isNull())
4639 return QualType();
4640 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004641
John McCall550e0c22009-10-21 00:40:46 +00004642 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4643 NewTL.setLBracketLoc(TL.getLBracketLoc());
4644 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004645 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004646
4647 return Result;
4648}
4649
4650template<typename Derived>
4651QualType
4652TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004653 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004654 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004655 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4656 if (ElementType.isNull())
4657 return QualType();
4658
Tim Shenb34d0ef2017-02-14 23:46:37 +00004659 ExprResult SizeResult;
4660 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004661 EnterExpressionEvaluationContext Context(
4662 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004663 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4664 }
4665 if (SizeResult.isInvalid())
4666 return QualType();
4667 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004668 if (SizeResult.isInvalid())
4669 return QualType();
4670
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004671 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004672
4673 QualType Result = TL.getType();
4674 if (getDerived().AlwaysRebuild() ||
4675 ElementType != T->getElementType() ||
4676 Size != T->getSizeExpr()) {
4677 Result = getDerived().RebuildVariableArrayType(ElementType,
4678 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004679 Size,
John McCall550e0c22009-10-21 00:40:46 +00004680 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004681 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004682 if (Result.isNull())
4683 return QualType();
4684 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004685
Serge Pavlov774c6d02014-02-06 03:49:11 +00004686 // We might have constant size array now, but fortunately it has the same
4687 // location layout.
4688 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004689 NewTL.setLBracketLoc(TL.getLBracketLoc());
4690 NewTL.setRBracketLoc(TL.getRBracketLoc());
4691 NewTL.setSizeExpr(Size);
4692
4693 return Result;
4694}
4695
4696template<typename Derived>
4697QualType
4698TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004699 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004700 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004701 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4702 if (ElementType.isNull())
4703 return QualType();
4704
Richard Smith764d2fe2011-12-20 02:08:33 +00004705 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004706 EnterExpressionEvaluationContext Unevaluated(
4707 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004708
John McCall33ddac02011-01-19 10:06:00 +00004709 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4710 Expr *origSize = TL.getSizeExpr();
4711 if (!origSize) origSize = T->getSizeExpr();
4712
4713 ExprResult sizeResult
4714 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004715 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004716 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004717 return QualType();
4718
John McCall33ddac02011-01-19 10:06:00 +00004719 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004720
4721 QualType Result = TL.getType();
4722 if (getDerived().AlwaysRebuild() ||
4723 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004724 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004725 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4726 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004727 size,
John McCall550e0c22009-10-21 00:40:46 +00004728 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004729 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004730 if (Result.isNull())
4731 return QualType();
4732 }
John McCall550e0c22009-10-21 00:40:46 +00004733
4734 // We might have any sort of array type now, but fortunately they
4735 // all have the same location layout.
4736 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4737 NewTL.setLBracketLoc(TL.getLBracketLoc());
4738 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004739 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004740
4741 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004742}
Mike Stump11289f42009-09-09 15:08:12 +00004743
4744template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004745QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004746 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004747 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004748 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004749
4750 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004751 QualType ElementType = getDerived().TransformType(T->getElementType());
4752 if (ElementType.isNull())
4753 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004754
Richard Smith764d2fe2011-12-20 02:08:33 +00004755 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004756 EnterExpressionEvaluationContext Unevaluated(
4757 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004758
John McCalldadc5752010-08-24 06:29:42 +00004759 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004760 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004761 if (Size.isInvalid())
4762 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004763
John McCall550e0c22009-10-21 00:40:46 +00004764 QualType Result = TL.getType();
4765 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004766 ElementType != T->getElementType() ||
4767 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004768 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004769 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004770 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004771 if (Result.isNull())
4772 return QualType();
4773 }
John McCall550e0c22009-10-21 00:40:46 +00004774
4775 // Result might be dependent or not.
4776 if (isa<DependentSizedExtVectorType>(Result)) {
4777 DependentSizedExtVectorTypeLoc NewTL
4778 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4779 NewTL.setNameLoc(TL.getNameLoc());
4780 } else {
4781 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4782 NewTL.setNameLoc(TL.getNameLoc());
4783 }
4784
4785 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004786}
Mike Stump11289f42009-09-09 15:08:12 +00004787
4788template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004789QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004790 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004791 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004792 QualType ElementType = getDerived().TransformType(T->getElementType());
4793 if (ElementType.isNull())
4794 return QualType();
4795
John McCall550e0c22009-10-21 00:40:46 +00004796 QualType Result = TL.getType();
4797 if (getDerived().AlwaysRebuild() ||
4798 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004799 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004800 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004801 if (Result.isNull())
4802 return QualType();
4803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004804
John McCall550e0c22009-10-21 00:40:46 +00004805 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4806 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004807
John McCall550e0c22009-10-21 00:40:46 +00004808 return Result;
4809}
4810
4811template<typename Derived>
4812QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004813 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004814 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004815 QualType ElementType = getDerived().TransformType(T->getElementType());
4816 if (ElementType.isNull())
4817 return QualType();
4818
4819 QualType Result = TL.getType();
4820 if (getDerived().AlwaysRebuild() ||
4821 ElementType != T->getElementType()) {
4822 Result = getDerived().RebuildExtVectorType(ElementType,
4823 T->getNumElements(),
4824 /*FIXME*/ SourceLocation());
4825 if (Result.isNull())
4826 return QualType();
4827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004828
John McCall550e0c22009-10-21 00:40:46 +00004829 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4830 NewTL.setNameLoc(TL.getNameLoc());
4831
4832 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004833}
Mike Stump11289f42009-09-09 15:08:12 +00004834
David Blaikie05785d12013-02-20 22:23:23 +00004835template <typename Derived>
4836ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4837 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4838 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004839 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004840 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004841
Douglas Gregor715e4612011-01-14 22:40:04 +00004842 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004843 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004844 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004845 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004846 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004847
Douglas Gregor715e4612011-01-14 22:40:04 +00004848 TypeLocBuilder TLB;
4849 TypeLoc NewTL = OldDI->getTypeLoc();
4850 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004851
4852 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004853 OldExpansionTL.getPatternLoc());
4854 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004855 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004856
4857 Result = RebuildPackExpansionType(Result,
4858 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004859 OldExpansionTL.getEllipsisLoc(),
4860 NumExpansions);
4861 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004862 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004863
Douglas Gregor715e4612011-01-14 22:40:04 +00004864 PackExpansionTypeLoc NewExpansionTL
4865 = TLB.push<PackExpansionTypeLoc>(Result);
4866 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4867 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4868 } else
4869 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004870 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004871 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004872
John McCall8fb0d9d2011-05-01 22:35:37 +00004873 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004874 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004875
4876 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4877 OldParm->getDeclContext(),
4878 OldParm->getInnerLocStart(),
4879 OldParm->getLocation(),
4880 OldParm->getIdentifier(),
4881 NewDI->getType(),
4882 NewDI,
4883 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004884 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004885 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4886 OldParm->getFunctionScopeIndex() + indexAdjustment);
4887 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004888}
4889
David Majnemer59f77922016-06-24 04:05:48 +00004890template <typename Derived>
4891bool TreeTransform<Derived>::TransformFunctionTypeParams(
4892 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4893 const QualType *ParamTypes,
4894 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4895 SmallVectorImpl<QualType> &OutParamTypes,
4896 SmallVectorImpl<ParmVarDecl *> *PVars,
4897 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004898 int indexAdjustment = 0;
4899
David Majnemer59f77922016-06-24 04:05:48 +00004900 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004901 for (unsigned i = 0; i != NumParams; ++i) {
4902 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004903 assert(OldParm->getFunctionScopeIndex() == i);
4904
David Blaikie05785d12013-02-20 22:23:23 +00004905 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004906 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004907 if (OldParm->isParameterPack()) {
4908 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004909 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004910
Douglas Gregor5499af42011-01-05 23:12:31 +00004911 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004912 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004913 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004914 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4915 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004916 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4917
Douglas Gregor5499af42011-01-05 23:12:31 +00004918 // Determine whether we should expand the parameter packs.
4919 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004920 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004921 Optional<unsigned> OrigNumExpansions =
4922 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004923 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004924 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4925 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004926 Unexpanded,
4927 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004928 RetainExpansion,
4929 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004930 return true;
4931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004932
Douglas Gregor5499af42011-01-05 23:12:31 +00004933 if (ShouldExpand) {
4934 // Expand the function parameter pack into multiple, separate
4935 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004936 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004937 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004938 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004939 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004940 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004941 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004942 OrigNumExpansions,
4943 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004944 if (!NewParm)
4945 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004946
John McCallc8e321d2016-03-01 02:09:25 +00004947 if (ParamInfos)
4948 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004949 OutParamTypes.push_back(NewParm->getType());
4950 if (PVars)
4951 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004952 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004953
4954 // If we're supposed to retain a pack expansion, do so by temporarily
4955 // forgetting the partially-substituted parameter pack.
4956 if (RetainExpansion) {
4957 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004958 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004959 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004960 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004961 OrigNumExpansions,
4962 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004963 if (!NewParm)
4964 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004965
John McCallc8e321d2016-03-01 02:09:25 +00004966 if (ParamInfos)
4967 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004968 OutParamTypes.push_back(NewParm->getType());
4969 if (PVars)
4970 PVars->push_back(NewParm);
4971 }
4972
John McCall8fb0d9d2011-05-01 22:35:37 +00004973 // The next parameter should have the same adjustment as the
4974 // last thing we pushed, but we post-incremented indexAdjustment
4975 // on every push. Also, if we push nothing, the adjustment should
4976 // go down by one.
4977 indexAdjustment--;
4978
Douglas Gregor5499af42011-01-05 23:12:31 +00004979 // We're done with the pack expansion.
4980 continue;
4981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004982
4983 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004984 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004985 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4986 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004987 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004988 NumExpansions,
4989 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004990 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004991 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004992 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004993 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004994
John McCall58f10c32010-03-11 09:03:00 +00004995 if (!NewParm)
4996 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004997
John McCallc8e321d2016-03-01 02:09:25 +00004998 if (ParamInfos)
4999 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005000 OutParamTypes.push_back(NewParm->getType());
5001 if (PVars)
5002 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005003 continue;
5004 }
John McCall58f10c32010-03-11 09:03:00 +00005005
5006 // Deal with the possibility that we don't have a parameter
5007 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005008 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005009 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005010 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005011 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005012 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005013 = dyn_cast<PackExpansionType>(OldType)) {
5014 // We have a function parameter pack that may need to be expanded.
5015 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005016 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005017 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005018
Douglas Gregor5499af42011-01-05 23:12:31 +00005019 // Determine whether we should expand the parameter packs.
5020 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005021 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005022 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005023 Unexpanded,
5024 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005025 RetainExpansion,
5026 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005027 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005029
Douglas Gregor5499af42011-01-05 23:12:31 +00005030 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005031 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005032 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005033 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005034 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5035 QualType NewType = getDerived().TransformType(Pattern);
5036 if (NewType.isNull())
5037 return true;
John McCall58f10c32010-03-11 09:03:00 +00005038
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005039 if (NewType->containsUnexpandedParameterPack()) {
5040 NewType =
5041 getSema().getASTContext().getPackExpansionType(NewType, None);
5042
5043 if (NewType.isNull())
5044 return true;
5045 }
5046
John McCallc8e321d2016-03-01 02:09:25 +00005047 if (ParamInfos)
5048 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005049 OutParamTypes.push_back(NewType);
5050 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005051 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005053
Douglas Gregor5499af42011-01-05 23:12:31 +00005054 // We're done with the pack expansion.
5055 continue;
5056 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005057
Douglas Gregor48d24112011-01-10 20:53:55 +00005058 // If we're supposed to retain a pack expansion, do so by temporarily
5059 // forgetting the partially-substituted parameter pack.
5060 if (RetainExpansion) {
5061 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5062 QualType NewType = getDerived().TransformType(Pattern);
5063 if (NewType.isNull())
5064 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005065
John McCallc8e321d2016-03-01 02:09:25 +00005066 if (ParamInfos)
5067 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005068 OutParamTypes.push_back(NewType);
5069 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005070 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005071 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005072
Chad Rosier1dcde962012-08-08 18:46:20 +00005073 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005074 // expansion.
5075 OldType = Expansion->getPattern();
5076 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005077 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5078 NewType = getDerived().TransformType(OldType);
5079 } else {
5080 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005081 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005082
Douglas Gregor5499af42011-01-05 23:12:31 +00005083 if (NewType.isNull())
5084 return true;
5085
5086 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005087 NewType = getSema().Context.getPackExpansionType(NewType,
5088 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005089
John McCallc8e321d2016-03-01 02:09:25 +00005090 if (ParamInfos)
5091 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005092 OutParamTypes.push_back(NewType);
5093 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005094 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005095 }
5096
John McCall8fb0d9d2011-05-01 22:35:37 +00005097#ifndef NDEBUG
5098 if (PVars) {
5099 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5100 if (ParmVarDecl *parm = (*PVars)[i])
5101 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005102 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005103#endif
5104
5105 return false;
5106}
John McCall58f10c32010-03-11 09:03:00 +00005107
5108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005109QualType
John McCall550e0c22009-10-21 00:40:46 +00005110TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005111 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005112 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005113 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005114 return getDerived().TransformFunctionProtoType(
5115 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005116 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5117 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5118 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005119 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005120}
5121
Richard Smith2e321552014-11-12 02:00:47 +00005122template<typename Derived> template<typename Fn>
5123QualType TreeTransform<Derived>::TransformFunctionProtoType(
5124 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5125 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005126
Douglas Gregor4afc2362010-08-31 00:26:14 +00005127 // Transform the parameters and return type.
5128 //
Richard Smithf623c962012-04-17 00:58:00 +00005129 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005130 // When the function has a trailing return type, we instantiate the
5131 // parameters before the return type, since the return type can then refer
5132 // to the parameters themselves (via decltype, sizeof, etc.).
5133 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005134 SmallVector<QualType, 4> ParamTypes;
5135 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005136 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005137 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005138
Douglas Gregor7fb25412010-10-01 18:44:50 +00005139 QualType ResultType;
5140
Richard Smith1226c602012-08-14 22:51:13 +00005141 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005142 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005143 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005144 TL.getTypePtr()->param_type_begin(),
5145 T->getExtParameterInfosOrNull(),
5146 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005147 return QualType();
5148
Douglas Gregor3024f072012-04-16 07:05:22 +00005149 {
5150 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005151 // If a declaration declares a member function or member function
5152 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005153 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005154 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005155 // declarator.
5156 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005157
Alp Toker42a16a62014-01-25 23:51:36 +00005158 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005159 if (ResultType.isNull())
5160 return QualType();
5161 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005162 }
5163 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005164 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005165 if (ResultType.isNull())
5166 return QualType();
5167
Alp Toker9cacbab2014-01-20 20:26:09 +00005168 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005169 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005170 TL.getTypePtr()->param_type_begin(),
5171 T->getExtParameterInfosOrNull(),
5172 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005173 return QualType();
5174 }
5175
Richard Smith2e321552014-11-12 02:00:47 +00005176 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5177
5178 bool EPIChanged = false;
5179 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5180 return QualType();
5181
John McCallc8e321d2016-03-01 02:09:25 +00005182 // Handle extended parameter information.
5183 if (auto NewExtParamInfos =
5184 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5185 if (!EPI.ExtParameterInfos ||
5186 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5187 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5188 EPIChanged = true;
5189 }
5190 EPI.ExtParameterInfos = NewExtParamInfos;
5191 } else if (EPI.ExtParameterInfos) {
5192 EPIChanged = true;
5193 EPI.ExtParameterInfos = nullptr;
5194 }
Richard Smithf623c962012-04-17 00:58:00 +00005195
John McCall550e0c22009-10-21 00:40:46 +00005196 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005197 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005198 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005199 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005200 if (Result.isNull())
5201 return QualType();
5202 }
Mike Stump11289f42009-09-09 15:08:12 +00005203
John McCall550e0c22009-10-21 00:40:46 +00005204 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005205 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005206 NewTL.setLParenLoc(TL.getLParenLoc());
5207 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005208 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005209 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005210 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5211 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005212
5213 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214}
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregord6ff3322009-08-04 16:50:30 +00005216template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005217bool TreeTransform<Derived>::TransformExceptionSpec(
5218 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5219 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5220 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5221
5222 // Instantiate a dynamic noexcept expression, if any.
5223 if (ESI.Type == EST_ComputedNoexcept) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005224 EnterExpressionEvaluationContext Unevaluated(
5225 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005226 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5227 if (NoexceptExpr.isInvalid())
5228 return true;
5229
Richard Smith03a4aa32016-06-23 19:02:52 +00005230 // FIXME: This is bogus, a noexcept expression is not a condition.
5231 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005232 if (NoexceptExpr.isInvalid())
5233 return true;
5234
5235 if (!NoexceptExpr.get()->isValueDependent()) {
5236 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5237 NoexceptExpr.get(), nullptr,
5238 diag::err_noexcept_needs_constant_expression,
5239 /*AllowFold*/false);
5240 if (NoexceptExpr.isInvalid())
5241 return true;
5242 }
5243
5244 if (ESI.NoexceptExpr != NoexceptExpr.get())
5245 Changed = true;
5246 ESI.NoexceptExpr = NoexceptExpr.get();
5247 }
5248
5249 if (ESI.Type != EST_Dynamic)
5250 return false;
5251
5252 // Instantiate a dynamic exception specification's type.
5253 for (QualType T : ESI.Exceptions) {
5254 if (const PackExpansionType *PackExpansion =
5255 T->getAs<PackExpansionType>()) {
5256 Changed = true;
5257
5258 // We have a pack expansion. Instantiate it.
5259 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5260 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5261 Unexpanded);
5262 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5263
5264 // Determine whether the set of unexpanded parameter packs can and
5265 // should
5266 // be expanded.
5267 bool Expand = false;
5268 bool RetainExpansion = false;
5269 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5270 // FIXME: Track the location of the ellipsis (and track source location
5271 // information for the types in the exception specification in general).
5272 if (getDerived().TryExpandParameterPacks(
5273 Loc, SourceRange(), Unexpanded, Expand,
5274 RetainExpansion, NumExpansions))
5275 return true;
5276
5277 if (!Expand) {
5278 // We can't expand this pack expansion into separate arguments yet;
5279 // just substitute into the pattern and create a new pack expansion
5280 // type.
5281 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5282 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5283 if (U.isNull())
5284 return true;
5285
5286 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5287 Exceptions.push_back(U);
5288 continue;
5289 }
5290
5291 // Substitute into the pack expansion pattern for each slice of the
5292 // pack.
5293 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5294 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5295
5296 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5297 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5298 return true;
5299
5300 Exceptions.push_back(U);
5301 }
5302 } else {
5303 QualType U = getDerived().TransformType(T);
5304 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5305 return true;
5306 if (T != U)
5307 Changed = true;
5308
5309 Exceptions.push_back(U);
5310 }
5311 }
5312
5313 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005314 if (ESI.Exceptions.empty())
5315 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005316 return false;
5317}
5318
5319template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005320QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005321 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005322 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005323 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005324 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005325 if (ResultType.isNull())
5326 return QualType();
5327
5328 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005329 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005330 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5331
5332 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005333 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005334 NewTL.setLParenLoc(TL.getLParenLoc());
5335 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005336 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005337
5338 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
John McCallb96ec562009-12-04 22:46:56 +00005341template<typename Derived> QualType
5342TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005343 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005344 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005345 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005346 if (!D)
5347 return QualType();
5348
5349 QualType Result = TL.getType();
5350 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005351 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005352 if (Result.isNull())
5353 return QualType();
5354 }
5355
5356 // We might get an arbitrary type spec type back. We should at
5357 // least always get a type spec type, though.
5358 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5359 NewTL.setNameLoc(TL.getNameLoc());
5360
5361 return Result;
5362}
5363
Douglas Gregord6ff3322009-08-04 16:50:30 +00005364template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005365QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005366 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005367 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005368 TypedefNameDecl *Typedef
5369 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5370 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005371 if (!Typedef)
5372 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005373
John McCall550e0c22009-10-21 00:40:46 +00005374 QualType Result = TL.getType();
5375 if (getDerived().AlwaysRebuild() ||
5376 Typedef != T->getDecl()) {
5377 Result = getDerived().RebuildTypedefType(Typedef);
5378 if (Result.isNull())
5379 return QualType();
5380 }
Mike Stump11289f42009-09-09 15:08:12 +00005381
John McCall550e0c22009-10-21 00:40:46 +00005382 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5383 NewTL.setNameLoc(TL.getNameLoc());
5384
5385 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005386}
Mike Stump11289f42009-09-09 15:08:12 +00005387
Douglas Gregord6ff3322009-08-04 16:50:30 +00005388template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005389QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005390 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005391 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005392 EnterExpressionEvaluationContext Unevaluated(
5393 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5394 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005395
John McCalldadc5752010-08-24 06:29:42 +00005396 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005397 if (E.isInvalid())
5398 return QualType();
5399
Eli Friedmane4f22df2012-02-29 04:03:55 +00005400 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5401 if (E.isInvalid())
5402 return QualType();
5403
John McCall550e0c22009-10-21 00:40:46 +00005404 QualType Result = TL.getType();
5405 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005406 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005407 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005408 if (Result.isNull())
5409 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005410 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005411 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005412
John McCall550e0c22009-10-21 00:40:46 +00005413 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005414 NewTL.setTypeofLoc(TL.getTypeofLoc());
5415 NewTL.setLParenLoc(TL.getLParenLoc());
5416 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005417
5418 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005419}
Mike Stump11289f42009-09-09 15:08:12 +00005420
5421template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005422QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005423 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005424 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5425 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5426 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005427 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005428
John McCall550e0c22009-10-21 00:40:46 +00005429 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005430 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5431 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005432 if (Result.isNull())
5433 return QualType();
5434 }
Mike Stump11289f42009-09-09 15:08:12 +00005435
John McCall550e0c22009-10-21 00:40:46 +00005436 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005437 NewTL.setTypeofLoc(TL.getTypeofLoc());
5438 NewTL.setLParenLoc(TL.getLParenLoc());
5439 NewTL.setRParenLoc(TL.getRParenLoc());
5440 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005441
5442 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443}
Mike Stump11289f42009-09-09 15:08:12 +00005444
5445template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005446QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005447 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005448 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005449
Douglas Gregore922c772009-08-04 22:27:00 +00005450 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005451 EnterExpressionEvaluationContext Unevaluated(
5452 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5453 /*IsDecltype=*/true);
Mike Stump11289f42009-09-09 15:08:12 +00005454
John McCalldadc5752010-08-24 06:29:42 +00005455 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005456 if (E.isInvalid())
5457 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005458
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005459 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005460 if (E.isInvalid())
5461 return QualType();
5462
John McCall550e0c22009-10-21 00:40:46 +00005463 QualType Result = TL.getType();
5464 if (getDerived().AlwaysRebuild() ||
5465 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005466 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005467 if (Result.isNull())
5468 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005469 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005470 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005471
John McCall550e0c22009-10-21 00:40:46 +00005472 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5473 NewTL.setNameLoc(TL.getNameLoc());
5474
5475 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005476}
5477
5478template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005479QualType TreeTransform<Derived>::TransformUnaryTransformType(
5480 TypeLocBuilder &TLB,
5481 UnaryTransformTypeLoc TL) {
5482 QualType Result = TL.getType();
5483 if (Result->isDependentType()) {
5484 const UnaryTransformType *T = TL.getTypePtr();
5485 QualType NewBase =
5486 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5487 Result = getDerived().RebuildUnaryTransformType(NewBase,
5488 T->getUTTKind(),
5489 TL.getKWLoc());
5490 if (Result.isNull())
5491 return QualType();
5492 }
5493
5494 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5495 NewTL.setKWLoc(TL.getKWLoc());
5496 NewTL.setParensRange(TL.getParensRange());
5497 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5498 return Result;
5499}
5500
5501template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005502QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5503 AutoTypeLoc TL) {
5504 const AutoType *T = TL.getTypePtr();
5505 QualType OldDeduced = T->getDeducedType();
5506 QualType NewDeduced;
5507 if (!OldDeduced.isNull()) {
5508 NewDeduced = getDerived().TransformType(OldDeduced);
5509 if (NewDeduced.isNull())
5510 return QualType();
5511 }
5512
5513 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005514 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5515 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005516 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005517 if (Result.isNull())
5518 return QualType();
5519 }
5520
5521 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5522 NewTL.setNameLoc(TL.getNameLoc());
5523
5524 return Result;
5525}
5526
5527template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005528QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5529 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5530 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5531
5532 CXXScopeSpec SS;
5533 TemplateName TemplateName = getDerived().TransformTemplateName(
5534 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5535 if (TemplateName.isNull())
5536 return QualType();
5537
5538 QualType OldDeduced = T->getDeducedType();
5539 QualType NewDeduced;
5540 if (!OldDeduced.isNull()) {
5541 NewDeduced = getDerived().TransformType(OldDeduced);
5542 if (NewDeduced.isNull())
5543 return QualType();
5544 }
5545
5546 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5547 TemplateName, NewDeduced);
5548 if (Result.isNull())
5549 return QualType();
5550
5551 DeducedTemplateSpecializationTypeLoc NewTL =
5552 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5553 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5554
5555 return Result;
5556}
5557
5558template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005559QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005560 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005561 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005562 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005563 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5564 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005565 if (!Record)
5566 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005567
John McCall550e0c22009-10-21 00:40:46 +00005568 QualType Result = TL.getType();
5569 if (getDerived().AlwaysRebuild() ||
5570 Record != T->getDecl()) {
5571 Result = getDerived().RebuildRecordType(Record);
5572 if (Result.isNull())
5573 return QualType();
5574 }
Mike Stump11289f42009-09-09 15:08:12 +00005575
John McCall550e0c22009-10-21 00:40:46 +00005576 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5577 NewTL.setNameLoc(TL.getNameLoc());
5578
5579 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005580}
Mike Stump11289f42009-09-09 15:08:12 +00005581
5582template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005583QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005584 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005585 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005586 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005587 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5588 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005589 if (!Enum)
5590 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005591
John McCall550e0c22009-10-21 00:40:46 +00005592 QualType Result = TL.getType();
5593 if (getDerived().AlwaysRebuild() ||
5594 Enum != T->getDecl()) {
5595 Result = getDerived().RebuildEnumType(Enum);
5596 if (Result.isNull())
5597 return QualType();
5598 }
Mike Stump11289f42009-09-09 15:08:12 +00005599
John McCall550e0c22009-10-21 00:40:46 +00005600 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5601 NewTL.setNameLoc(TL.getNameLoc());
5602
5603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005604}
John McCallfcc33b02009-09-05 00:15:47 +00005605
John McCalle78aac42010-03-10 03:28:59 +00005606template<typename Derived>
5607QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5608 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005609 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005610 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5611 TL.getTypePtr()->getDecl());
5612 if (!D) return QualType();
5613
5614 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5615 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5616 return T;
5617}
5618
Douglas Gregord6ff3322009-08-04 16:50:30 +00005619template<typename Derived>
5620QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005621 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005622 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005623 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005624}
5625
Mike Stump11289f42009-09-09 15:08:12 +00005626template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005627QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005628 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005629 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005630 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005631
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005632 // Substitute into the replacement type, which itself might involve something
5633 // that needs to be transformed. This only tends to occur with default
5634 // template arguments of template template parameters.
5635 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5636 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5637 if (Replacement.isNull())
5638 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005639
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005640 // Always canonicalize the replacement type.
5641 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5642 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005643 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005644 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005645
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005646 // Propagate type-source information.
5647 SubstTemplateTypeParmTypeLoc NewTL
5648 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5649 NewTL.setNameLoc(TL.getNameLoc());
5650 return Result;
5651
John McCallcebee162009-10-18 09:09:24 +00005652}
5653
5654template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005655QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5656 TypeLocBuilder &TLB,
5657 SubstTemplateTypeParmPackTypeLoc TL) {
5658 return TransformTypeSpecType(TLB, TL);
5659}
5660
5661template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005662QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005663 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005664 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005665 const TemplateSpecializationType *T = TL.getTypePtr();
5666
Douglas Gregordf846d12011-03-02 18:46:51 +00005667 // The nested-name-specifier never matters in a TemplateSpecializationType,
5668 // because we can't have a dependent nested-name-specifier anyway.
5669 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005670 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005671 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5672 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005673 if (Template.isNull())
5674 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005675
John McCall31f82722010-11-12 08:19:04 +00005676 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5677}
5678
Eli Friedman0dfb8892011-10-06 23:00:33 +00005679template<typename Derived>
5680QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5681 AtomicTypeLoc TL) {
5682 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5683 if (ValueType.isNull())
5684 return QualType();
5685
5686 QualType Result = TL.getType();
5687 if (getDerived().AlwaysRebuild() ||
5688 ValueType != TL.getValueLoc().getType()) {
5689 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5690 if (Result.isNull())
5691 return QualType();
5692 }
5693
5694 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5695 NewTL.setKWLoc(TL.getKWLoc());
5696 NewTL.setLParenLoc(TL.getLParenLoc());
5697 NewTL.setRParenLoc(TL.getRParenLoc());
5698
5699 return Result;
5700}
5701
Xiuli Pan9c14e282016-01-09 12:53:17 +00005702template <typename Derived>
5703QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5704 PipeTypeLoc TL) {
5705 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5706 if (ValueType.isNull())
5707 return QualType();
5708
5709 QualType Result = TL.getType();
5710 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005711 const PipeType *PT = Result->getAs<PipeType>();
5712 bool isReadPipe = PT->isReadOnly();
5713 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005714 if (Result.isNull())
5715 return QualType();
5716 }
5717
5718 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5719 NewTL.setKWLoc(TL.getKWLoc());
5720
5721 return Result;
5722}
5723
Chad Rosier1dcde962012-08-08 18:46:20 +00005724 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005725 /// container that provides a \c getArgLoc() member function.
5726 ///
5727 /// This iterator is intended to be used with the iterator form of
5728 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5729 template<typename ArgLocContainer>
5730 class TemplateArgumentLocContainerIterator {
5731 ArgLocContainer *Container;
5732 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005733
Douglas Gregorfe921a72010-12-20 23:36:19 +00005734 public:
5735 typedef TemplateArgumentLoc value_type;
5736 typedef TemplateArgumentLoc reference;
5737 typedef int difference_type;
5738 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005739
Douglas Gregorfe921a72010-12-20 23:36:19 +00005740 class pointer {
5741 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005742
Douglas Gregorfe921a72010-12-20 23:36:19 +00005743 public:
5744 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005745
Douglas Gregorfe921a72010-12-20 23:36:19 +00005746 const TemplateArgumentLoc *operator->() const {
5747 return &Arg;
5748 }
5749 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005750
5751
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005752 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005753
Douglas Gregorfe921a72010-12-20 23:36:19 +00005754 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5755 unsigned Index)
5756 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005757
Douglas Gregorfe921a72010-12-20 23:36:19 +00005758 TemplateArgumentLocContainerIterator &operator++() {
5759 ++Index;
5760 return *this;
5761 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005762
Douglas Gregorfe921a72010-12-20 23:36:19 +00005763 TemplateArgumentLocContainerIterator operator++(int) {
5764 TemplateArgumentLocContainerIterator Old(*this);
5765 ++(*this);
5766 return Old;
5767 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005768
Douglas Gregorfe921a72010-12-20 23:36:19 +00005769 TemplateArgumentLoc operator*() const {
5770 return Container->getArgLoc(Index);
5771 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005772
Douglas Gregorfe921a72010-12-20 23:36:19 +00005773 pointer operator->() const {
5774 return pointer(Container->getArgLoc(Index));
5775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005776
Douglas Gregorfe921a72010-12-20 23:36:19 +00005777 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005778 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005779 return X.Container == Y.Container && X.Index == Y.Index;
5780 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005781
Douglas Gregorfe921a72010-12-20 23:36:19 +00005782 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005783 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005784 return !(X == Y);
5785 }
5786 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005787
5788
John McCall31f82722010-11-12 08:19:04 +00005789template <typename Derived>
5790QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5791 TypeLocBuilder &TLB,
5792 TemplateSpecializationTypeLoc TL,
5793 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005794 TemplateArgumentListInfo NewTemplateArgs;
5795 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5796 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005797 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5798 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005799 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005800 ArgIterator(TL, TL.getNumArgs()),
5801 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005802 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005803
John McCall0ad16662009-10-29 08:12:44 +00005804 // FIXME: maybe don't rebuild if all the template arguments are the same.
5805
5806 QualType Result =
5807 getDerived().RebuildTemplateSpecializationType(Template,
5808 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005809 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005810
5811 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005812 // Specializations of template template parameters are represented as
5813 // TemplateSpecializationTypes, and substitution of type alias templates
5814 // within a dependent context can transform them into
5815 // DependentTemplateSpecializationTypes.
5816 if (isa<DependentTemplateSpecializationType>(Result)) {
5817 DependentTemplateSpecializationTypeLoc NewTL
5818 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005819 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005820 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005821 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005822 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005823 NewTL.setLAngleLoc(TL.getLAngleLoc());
5824 NewTL.setRAngleLoc(TL.getRAngleLoc());
5825 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5826 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5827 return Result;
5828 }
5829
John McCall0ad16662009-10-29 08:12:44 +00005830 TemplateSpecializationTypeLoc NewTL
5831 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005832 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005833 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5834 NewTL.setLAngleLoc(TL.getLAngleLoc());
5835 NewTL.setRAngleLoc(TL.getRAngleLoc());
5836 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5837 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005838 }
Mike Stump11289f42009-09-09 15:08:12 +00005839
John McCall0ad16662009-10-29 08:12:44 +00005840 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005841}
Mike Stump11289f42009-09-09 15:08:12 +00005842
Douglas Gregor5a064722011-02-28 17:23:35 +00005843template <typename Derived>
5844QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5845 TypeLocBuilder &TLB,
5846 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005847 TemplateName Template,
5848 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005849 TemplateArgumentListInfo NewTemplateArgs;
5850 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5851 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5852 typedef TemplateArgumentLocContainerIterator<
5853 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005854 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005855 ArgIterator(TL, TL.getNumArgs()),
5856 NewTemplateArgs))
5857 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Douglas Gregor5a064722011-02-28 17:23:35 +00005859 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005860
Douglas Gregor5a064722011-02-28 17:23:35 +00005861 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5862 QualType Result
5863 = getSema().Context.getDependentTemplateSpecializationType(
5864 TL.getTypePtr()->getKeyword(),
5865 DTN->getQualifier(),
5866 DTN->getIdentifier(),
5867 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Douglas Gregor5a064722011-02-28 17:23:35 +00005869 DependentTemplateSpecializationTypeLoc NewTL
5870 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005871 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005872 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005873 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005874 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005875 NewTL.setLAngleLoc(TL.getLAngleLoc());
5876 NewTL.setRAngleLoc(TL.getRAngleLoc());
5877 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5878 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5879 return Result;
5880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005881
5882 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005883 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005884 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005885 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005886
Douglas Gregor5a064722011-02-28 17:23:35 +00005887 if (!Result.isNull()) {
5888 /// FIXME: Wrap this in an elaborated-type-specifier?
5889 TemplateSpecializationTypeLoc NewTL
5890 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005891 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005892 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005893 NewTL.setLAngleLoc(TL.getLAngleLoc());
5894 NewTL.setRAngleLoc(TL.getRAngleLoc());
5895 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5896 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5897 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005898
Douglas Gregor5a064722011-02-28 17:23:35 +00005899 return Result;
5900}
5901
Mike Stump11289f42009-09-09 15:08:12 +00005902template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005903QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005904TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005905 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005906 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005907
Douglas Gregor844cb502011-03-01 18:12:44 +00005908 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005909 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005910 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005911 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005912 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5913 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005914 return QualType();
5915 }
Mike Stump11289f42009-09-09 15:08:12 +00005916
John McCall31f82722010-11-12 08:19:04 +00005917 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5918 if (NamedT.isNull())
5919 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005920
Richard Smith3f1b5d02011-05-05 21:57:07 +00005921 // C++0x [dcl.type.elab]p2:
5922 // If the identifier resolves to a typedef-name or the simple-template-id
5923 // resolves to an alias template specialization, the
5924 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005925 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5926 if (const TemplateSpecializationType *TST =
5927 NamedT->getAs<TemplateSpecializationType>()) {
5928 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005929 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5930 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005931 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005932 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005933 << TAT << Sema::NTK_TypeAliasTemplate
5934 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005935 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5936 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005937 }
5938 }
5939
John McCall550e0c22009-10-21 00:40:46 +00005940 QualType Result = TL.getType();
5941 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005942 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005943 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005944 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005945 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005946 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005947 if (Result.isNull())
5948 return QualType();
5949 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005950
Abramo Bagnara6150c882010-05-11 21:36:43 +00005951 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005952 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005953 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005954 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005955}
Mike Stump11289f42009-09-09 15:08:12 +00005956
5957template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005958QualType TreeTransform<Derived>::TransformAttributedType(
5959 TypeLocBuilder &TLB,
5960 AttributedTypeLoc TL) {
5961 const AttributedType *oldType = TL.getTypePtr();
5962 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5963 if (modifiedType.isNull())
5964 return QualType();
5965
5966 QualType result = TL.getType();
5967
5968 // FIXME: dependent operand expressions?
5969 if (getDerived().AlwaysRebuild() ||
5970 modifiedType != oldType->getModifiedType()) {
5971 // TODO: this is really lame; we should really be rebuilding the
5972 // equivalent type from first principles.
5973 QualType equivalentType
5974 = getDerived().TransformType(oldType->getEquivalentType());
5975 if (equivalentType.isNull())
5976 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005977
5978 // Check whether we can add nullability; it is only represented as
5979 // type sugar, and therefore cannot be diagnosed in any other way.
5980 if (auto nullability = oldType->getImmediateNullability()) {
5981 if (!modifiedType->canHaveNullability()) {
5982 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005983 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005984 return QualType();
5985 }
5986 }
5987
John McCall81904512011-01-06 01:58:22 +00005988 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5989 modifiedType,
5990 equivalentType);
5991 }
5992
5993 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5994 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5995 if (TL.hasAttrOperand())
5996 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5997 if (TL.hasAttrExprOperand())
5998 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5999 else if (TL.hasAttrEnumOperand())
6000 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
6001
6002 return result;
6003}
6004
6005template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006006QualType
6007TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6008 ParenTypeLoc TL) {
6009 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6010 if (Inner.isNull())
6011 return QualType();
6012
6013 QualType Result = TL.getType();
6014 if (getDerived().AlwaysRebuild() ||
6015 Inner != TL.getInnerLoc().getType()) {
6016 Result = getDerived().RebuildParenType(Inner);
6017 if (Result.isNull())
6018 return QualType();
6019 }
6020
6021 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6022 NewTL.setLParenLoc(TL.getLParenLoc());
6023 NewTL.setRParenLoc(TL.getRParenLoc());
6024 return Result;
6025}
6026
6027template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006028QualType TreeTransform<Derived>::TransformDependentNameType(
6029 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6030 return TransformDependentNameType(TLB, TL, false);
6031}
6032
6033template<typename Derived>
6034QualType TreeTransform<Derived>::TransformDependentNameType(
6035 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006036 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006037
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006038 NestedNameSpecifierLoc QualifierLoc
6039 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6040 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006041 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006042
John McCallc392f372010-06-11 00:33:02 +00006043 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006044 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006045 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006046 QualifierLoc,
6047 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006048 TL.getNameLoc(),
6049 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006050 if (Result.isNull())
6051 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006052
Abramo Bagnarad7548482010-05-19 21:37:53 +00006053 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6054 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006055 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6056
Abramo Bagnarad7548482010-05-19 21:37:53 +00006057 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006058 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006059 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006060 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006061 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006062 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006063 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006064 NewTL.setNameLoc(TL.getNameLoc());
6065 }
John McCall550e0c22009-10-21 00:40:46 +00006066 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006067}
Mike Stump11289f42009-09-09 15:08:12 +00006068
Douglas Gregord6ff3322009-08-04 16:50:30 +00006069template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006070QualType TreeTransform<Derived>::
6071 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006072 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006073 NestedNameSpecifierLoc QualifierLoc;
6074 if (TL.getQualifierLoc()) {
6075 QualifierLoc
6076 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6077 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006078 return QualType();
6079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006080
John McCall31f82722010-11-12 08:19:04 +00006081 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006082 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006083}
6084
6085template<typename Derived>
6086QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006087TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6088 DependentTemplateSpecializationTypeLoc TL,
6089 NestedNameSpecifierLoc QualifierLoc) {
6090 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006091
Douglas Gregora7a795b2011-03-01 20:11:18 +00006092 TemplateArgumentListInfo NewTemplateArgs;
6093 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6094 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006095
Douglas Gregora7a795b2011-03-01 20:11:18 +00006096 typedef TemplateArgumentLocContainerIterator<
6097 DependentTemplateSpecializationTypeLoc> ArgIterator;
6098 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6099 ArgIterator(TL, TL.getNumArgs()),
6100 NewTemplateArgs))
6101 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006102
Richard Smithfd3dae02017-01-20 00:20:39 +00006103 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6104 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6105 TL.getTemplateNameLoc(), NewTemplateArgs,
6106 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006107 if (Result.isNull())
6108 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006109
Douglas Gregora7a795b2011-03-01 20:11:18 +00006110 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6111 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006112
Douglas Gregora7a795b2011-03-01 20:11:18 +00006113 // Copy information relevant to the template specialization.
6114 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006115 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006116 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006117 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006118 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6119 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006120 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006121 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006122
Douglas Gregora7a795b2011-03-01 20:11:18 +00006123 // Copy information relevant to the elaborated type.
6124 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006125 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006126 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006127 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6128 DependentTemplateSpecializationTypeLoc SpecTL
6129 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006130 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006131 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006132 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006133 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006134 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6135 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006136 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006137 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006138 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006139 TemplateSpecializationTypeLoc SpecTL
6140 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006141 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006142 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006143 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6144 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006145 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006146 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006147 }
6148 return Result;
6149}
6150
6151template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006152QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6153 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006154 QualType Pattern
6155 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006156 if (Pattern.isNull())
6157 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006158
6159 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006160 if (getDerived().AlwaysRebuild() ||
6161 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006162 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006163 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006164 TL.getEllipsisLoc(),
6165 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006166 if (Result.isNull())
6167 return QualType();
6168 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006169
Douglas Gregor822d0302011-01-12 17:07:58 +00006170 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6171 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6172 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006173}
6174
6175template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006176QualType
6177TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006178 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006179 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006180 TLB.pushFullCopy(TL);
6181 return TL.getType();
6182}
6183
6184template<typename Derived>
6185QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006186TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6187 ObjCTypeParamTypeLoc TL) {
6188 const ObjCTypeParamType *T = TL.getTypePtr();
6189 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6190 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6191 if (!OTP)
6192 return QualType();
6193
6194 QualType Result = TL.getType();
6195 if (getDerived().AlwaysRebuild() ||
6196 OTP != T->getDecl()) {
6197 Result = getDerived().RebuildObjCTypeParamType(OTP,
6198 TL.getProtocolLAngleLoc(),
6199 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6200 TL.getNumProtocols()),
6201 TL.getProtocolLocs(),
6202 TL.getProtocolRAngleLoc());
6203 if (Result.isNull())
6204 return QualType();
6205 }
6206
6207 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6208 if (TL.getNumProtocols()) {
6209 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6210 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6211 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6212 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6213 }
6214 return Result;
6215}
6216
6217template<typename Derived>
6218QualType
John McCall8b07ec22010-05-15 11:32:37 +00006219TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006220 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006221 // Transform base type.
6222 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6223 if (BaseType.isNull())
6224 return QualType();
6225
6226 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6227
6228 // Transform type arguments.
6229 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6230 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6231 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6232 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6233 QualType TypeArg = TypeArgInfo->getType();
6234 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6235 AnyChanged = true;
6236
6237 // We have a pack expansion. Instantiate it.
6238 const auto *PackExpansion = PackExpansionLoc.getType()
6239 ->castAs<PackExpansionType>();
6240 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6241 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6242 Unexpanded);
6243 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6244
6245 // Determine whether the set of unexpanded parameter packs can
6246 // and should be expanded.
6247 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6248 bool Expand = false;
6249 bool RetainExpansion = false;
6250 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6251 if (getDerived().TryExpandParameterPacks(
6252 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6253 Unexpanded, Expand, RetainExpansion, NumExpansions))
6254 return QualType();
6255
6256 if (!Expand) {
6257 // We can't expand this pack expansion into separate arguments yet;
6258 // just substitute into the pattern and create a new pack expansion
6259 // type.
6260 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6261
6262 TypeLocBuilder TypeArgBuilder;
6263 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6264 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6265 PatternLoc);
6266 if (NewPatternType.isNull())
6267 return QualType();
6268
6269 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6270 NewPatternType, NumExpansions);
6271 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6272 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6273 NewTypeArgInfos.push_back(
6274 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6275 continue;
6276 }
6277
6278 // Substitute into the pack expansion pattern for each slice of the
6279 // pack.
6280 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6281 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6282
6283 TypeLocBuilder TypeArgBuilder;
6284 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6285
6286 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6287 PatternLoc);
6288 if (NewTypeArg.isNull())
6289 return QualType();
6290
6291 NewTypeArgInfos.push_back(
6292 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6293 }
6294
6295 continue;
6296 }
6297
6298 TypeLocBuilder TypeArgBuilder;
6299 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6300 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6301 if (NewTypeArg.isNull())
6302 return QualType();
6303
6304 // If nothing changed, just keep the old TypeSourceInfo.
6305 if (NewTypeArg == TypeArg) {
6306 NewTypeArgInfos.push_back(TypeArgInfo);
6307 continue;
6308 }
6309
6310 NewTypeArgInfos.push_back(
6311 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6312 AnyChanged = true;
6313 }
6314
6315 QualType Result = TL.getType();
6316 if (getDerived().AlwaysRebuild() || AnyChanged) {
6317 // Rebuild the type.
6318 Result = getDerived().RebuildObjCObjectType(
6319 BaseType,
6320 TL.getLocStart(),
6321 TL.getTypeArgsLAngleLoc(),
6322 NewTypeArgInfos,
6323 TL.getTypeArgsRAngleLoc(),
6324 TL.getProtocolLAngleLoc(),
6325 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6326 TL.getNumProtocols()),
6327 TL.getProtocolLocs(),
6328 TL.getProtocolRAngleLoc());
6329
6330 if (Result.isNull())
6331 return QualType();
6332 }
6333
6334 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006335 NewT.setHasBaseTypeAsWritten(true);
6336 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6337 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6338 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6339 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6340 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6341 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6342 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6343 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6344 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006345}
Mike Stump11289f42009-09-09 15:08:12 +00006346
6347template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006348QualType
6349TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006350 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006351 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6352 if (PointeeType.isNull())
6353 return QualType();
6354
6355 QualType Result = TL.getType();
6356 if (getDerived().AlwaysRebuild() ||
6357 PointeeType != TL.getPointeeLoc().getType()) {
6358 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6359 TL.getStarLoc());
6360 if (Result.isNull())
6361 return QualType();
6362 }
6363
6364 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6365 NewT.setStarLoc(TL.getStarLoc());
6366 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006367}
6368
Douglas Gregord6ff3322009-08-04 16:50:30 +00006369//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006370// Statement transformation
6371//===----------------------------------------------------------------------===//
6372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006373StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006374TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006375 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006376}
6377
6378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006379StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006380TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6381 return getDerived().TransformCompoundStmt(S, false);
6382}
6383
6384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006385StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006386TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006387 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006388 Sema::CompoundScopeRAII CompoundScope(getSema());
6389
John McCall1ababa62010-08-27 19:56:05 +00006390 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006391 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006392 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006393 for (auto *B : S->body()) {
6394 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006395 if (Result.isInvalid()) {
6396 // Immediately fail if this was a DeclStmt, since it's very
6397 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006398 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006399 return StmtError();
6400
6401 // Otherwise, just keep processing substatements and fail later.
6402 SubStmtInvalid = true;
6403 continue;
6404 }
Mike Stump11289f42009-09-09 15:08:12 +00006405
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006406 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006407 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 }
Mike Stump11289f42009-09-09 15:08:12 +00006409
John McCall1ababa62010-08-27 19:56:05 +00006410 if (SubStmtInvalid)
6411 return StmtError();
6412
Douglas Gregorebe10102009-08-20 07:17:43 +00006413 if (!getDerived().AlwaysRebuild() &&
6414 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006415 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006416
6417 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006418 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006419 S->getRBracLoc(),
6420 IsStmtExpr);
6421}
Mike Stump11289f42009-09-09 15:08:12 +00006422
Douglas Gregorebe10102009-08-20 07:17:43 +00006423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006424StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006425TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006426 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006427 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006428 EnterExpressionEvaluationContext Unevaluated(
6429 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006430
Eli Friedman06577382009-11-19 03:14:00 +00006431 // Transform the left-hand case value.
6432 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006433 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006434 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006436
Eli Friedman06577382009-11-19 03:14:00 +00006437 // Transform the right-hand case value (for the GNU case-range extension).
6438 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006439 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006440 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006441 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006442 }
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregorebe10102009-08-20 07:17:43 +00006444 // Build the case statement.
6445 // Case statements are always rebuilt so that they will attached to their
6446 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006447 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006448 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006449 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006450 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006451 S->getColonLoc());
6452 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006453 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006454
Douglas Gregorebe10102009-08-20 07:17:43 +00006455 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006456 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006457 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006458 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006459
Douglas Gregorebe10102009-08-20 07:17:43 +00006460 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006461 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006462}
6463
6464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006465StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006466TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006467 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006468 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006469 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006470 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006471
Douglas Gregorebe10102009-08-20 07:17:43 +00006472 // Default statements are always rebuilt
6473 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006474 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006475}
Mike Stump11289f42009-09-09 15:08:12 +00006476
Douglas Gregorebe10102009-08-20 07:17:43 +00006477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006478StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006479TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006480 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006481 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006482 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006483
Chris Lattnercab02a62011-02-17 20:34:02 +00006484 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6485 S->getDecl());
6486 if (!LD)
6487 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006488
6489
Douglas Gregorebe10102009-08-20 07:17:43 +00006490 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006491 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006492 cast<LabelDecl>(LD), SourceLocation(),
6493 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006494}
Mike Stump11289f42009-09-09 15:08:12 +00006495
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006496template <typename Derived>
6497const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6498 if (!R)
6499 return R;
6500
6501 switch (R->getKind()) {
6502// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6503#define ATTR(X)
6504#define PRAGMA_SPELLING_ATTR(X) \
6505 case attr::X: \
6506 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6507#include "clang/Basic/AttrList.inc"
6508 default:
6509 return R;
6510 }
6511}
6512
6513template <typename Derived>
6514StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6515 bool AttrsChanged = false;
6516 SmallVector<const Attr *, 1> Attrs;
6517
6518 // Visit attributes and keep track if any are transformed.
6519 for (const auto *I : S->getAttrs()) {
6520 const Attr *R = getDerived().TransformAttr(I);
6521 AttrsChanged |= (I != R);
6522 Attrs.push_back(R);
6523 }
6524
Richard Smithc202b282012-04-14 00:33:13 +00006525 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6526 if (SubStmt.isInvalid())
6527 return StmtError();
6528
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006529 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006530 return S;
6531
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006532 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006533 SubStmt.get());
6534}
6535
6536template<typename Derived>
6537StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006538TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006539 // Transform the initialization statement
6540 StmtResult Init = getDerived().TransformStmt(S->getInit());
6541 if (Init.isInvalid())
6542 return StmtError();
6543
Douglas Gregorebe10102009-08-20 07:17:43 +00006544 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006545 Sema::ConditionResult Cond = getDerived().TransformCondition(
6546 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006547 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6548 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006549 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006550 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006551
Richard Smithb130fe72016-06-23 19:16:49 +00006552 // If this is a constexpr if, determine which arm we should instantiate.
6553 llvm::Optional<bool> ConstexprConditionValue;
6554 if (S->isConstexpr())
6555 ConstexprConditionValue = Cond.getKnownValue();
6556
Douglas Gregorebe10102009-08-20 07:17:43 +00006557 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006558 StmtResult Then;
6559 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6560 Then = getDerived().TransformStmt(S->getThen());
6561 if (Then.isInvalid())
6562 return StmtError();
6563 } else {
6564 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6565 }
Mike Stump11289f42009-09-09 15:08:12 +00006566
Douglas Gregorebe10102009-08-20 07:17:43 +00006567 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006568 StmtResult Else;
6569 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6570 Else = getDerived().TransformStmt(S->getElse());
6571 if (Else.isInvalid())
6572 return StmtError();
6573 }
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregorebe10102009-08-20 07:17:43 +00006575 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006576 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006577 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006578 Then.get() == S->getThen() &&
6579 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006580 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006581
Richard Smithb130fe72016-06-23 19:16:49 +00006582 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006583 Init.get(), Then.get(), S->getElseLoc(),
6584 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006585}
6586
6587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006589TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006590 // Transform the initialization statement
6591 StmtResult Init = getDerived().TransformStmt(S->getInit());
6592 if (Init.isInvalid())
6593 return StmtError();
6594
Douglas Gregorebe10102009-08-20 07:17:43 +00006595 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006596 Sema::ConditionResult Cond = getDerived().TransformCondition(
6597 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6598 Sema::ConditionKind::Switch);
6599 if (Cond.isInvalid())
6600 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006601
Douglas Gregorebe10102009-08-20 07:17:43 +00006602 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006603 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006604 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006605 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006607
Douglas Gregorebe10102009-08-20 07:17:43 +00006608 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006609 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006610 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006611 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006612
Douglas Gregorebe10102009-08-20 07:17:43 +00006613 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006614 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6615 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006616}
Mike Stump11289f42009-09-09 15:08:12 +00006617
Douglas Gregorebe10102009-08-20 07:17:43 +00006618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006619StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006620TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006621 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006622 Sema::ConditionResult Cond = getDerived().TransformCondition(
6623 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6624 Sema::ConditionKind::Boolean);
6625 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006626 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006627
Douglas Gregorebe10102009-08-20 07:17:43 +00006628 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006629 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006630 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006631 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006632
Douglas Gregorebe10102009-08-20 07:17:43 +00006633 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006634 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006635 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006636 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006637
Richard Smith03a4aa32016-06-23 19:02:52 +00006638 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006639}
Mike Stump11289f42009-09-09 15:08:12 +00006640
Douglas Gregorebe10102009-08-20 07:17:43 +00006641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006642StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006643TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006644 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006645 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006646 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006647 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006649 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006650 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006651 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006652 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006653
Douglas Gregorebe10102009-08-20 07:17:43 +00006654 if (!getDerived().AlwaysRebuild() &&
6655 Cond.get() == S->getCond() &&
6656 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006657 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006658
John McCallb268a282010-08-23 23:25:46 +00006659 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6660 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006661 S->getRParenLoc());
6662}
Mike Stump11289f42009-09-09 15:08:12 +00006663
Douglas Gregorebe10102009-08-20 07:17:43 +00006664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006665StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006666TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006667 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006668 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006669 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006670 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006671
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006672 // In OpenMP loop region loop control variable must be captured and be
6673 // private. Perform analysis of first part (if any).
6674 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6675 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6676
Douglas Gregorebe10102009-08-20 07:17:43 +00006677 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006678 Sema::ConditionResult Cond = getDerived().TransformCondition(
6679 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6680 Sema::ConditionKind::Boolean);
6681 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006682 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006683
Douglas Gregorebe10102009-08-20 07:17:43 +00006684 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006685 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006686 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006688
Richard Smith945f8d32013-01-14 22:39:08 +00006689 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006690 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006691 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006692
Douglas Gregorebe10102009-08-20 07:17:43 +00006693 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006694 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006695 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006696 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregorebe10102009-08-20 07:17:43 +00006698 if (!getDerived().AlwaysRebuild() &&
6699 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006700 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006701 Inc.get() == S->getInc() &&
6702 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006703 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregorebe10102009-08-20 07:17:43 +00006705 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006706 Init.get(), Cond, FullInc,
6707 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006708}
6709
6710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006711StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006712TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006713 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6714 S->getLabel());
6715 if (!LD)
6716 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
Douglas Gregorebe10102009-08-20 07:17:43 +00006718 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006719 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006720 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006721}
6722
6723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006724StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006725TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006726 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006727 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006729 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006730
Douglas Gregorebe10102009-08-20 07:17:43 +00006731 if (!getDerived().AlwaysRebuild() &&
6732 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006733 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006734
6735 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006736 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006737}
6738
6739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006740StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006741TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006742 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006743}
Mike Stump11289f42009-09-09 15:08:12 +00006744
Douglas Gregorebe10102009-08-20 07:17:43 +00006745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006746StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006747TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006748 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006749}
Mike Stump11289f42009-09-09 15:08:12 +00006750
Douglas Gregorebe10102009-08-20 07:17:43 +00006751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006752StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006753TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006754 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6755 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006756 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006757 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006758
Mike Stump11289f42009-09-09 15:08:12 +00006759 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006760 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006761 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006762}
Mike Stump11289f42009-09-09 15:08:12 +00006763
Douglas Gregorebe10102009-08-20 07:17:43 +00006764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006765StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006766TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006767 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006768 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006769 for (auto *D : S->decls()) {
6770 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006771 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006772 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006773
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006774 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006775 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006776
Douglas Gregorebe10102009-08-20 07:17:43 +00006777 Decls.push_back(Transformed);
6778 }
Mike Stump11289f42009-09-09 15:08:12 +00006779
Douglas Gregorebe10102009-08-20 07:17:43 +00006780 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006781 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006782
Rafael Espindolaab417692013-07-09 12:05:01 +00006783 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006784}
Mike Stump11289f42009-09-09 15:08:12 +00006785
Douglas Gregorebe10102009-08-20 07:17:43 +00006786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006787StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006788TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006789
Benjamin Kramerf0623432012-08-23 22:51:59 +00006790 SmallVector<Expr*, 8> Constraints;
6791 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006792 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006793
John McCalldadc5752010-08-24 06:29:42 +00006794 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006795 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006796
6797 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006798
Anders Carlssonaaeef072010-01-24 05:50:09 +00006799 // Go through the outputs.
6800 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006801 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006802
Anders Carlssonaaeef072010-01-24 05:50:09 +00006803 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006804 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006805
Anders Carlssonaaeef072010-01-24 05:50:09 +00006806 // Transform the output expr.
6807 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006808 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006809 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006811
Anders Carlssonaaeef072010-01-24 05:50:09 +00006812 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006813
John McCallb268a282010-08-23 23:25:46 +00006814 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006816
Anders Carlssonaaeef072010-01-24 05:50:09 +00006817 // Go through the inputs.
6818 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006819 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006820
Anders Carlssonaaeef072010-01-24 05:50:09 +00006821 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006822 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006823
Anders Carlssonaaeef072010-01-24 05:50:09 +00006824 // Transform the input expr.
6825 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006826 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006827 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006828 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006829
Anders Carlssonaaeef072010-01-24 05:50:09 +00006830 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006831
John McCallb268a282010-08-23 23:25:46 +00006832 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006833 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006834
Anders Carlssonaaeef072010-01-24 05:50:09 +00006835 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006836 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006837
6838 // Go through the clobbers.
6839 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006840 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006841
6842 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006843 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006844 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6845 S->isVolatile(), S->getNumOutputs(),
6846 S->getNumInputs(), Names.data(),
6847 Constraints, Exprs, AsmString.get(),
6848 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006849}
6850
Chad Rosier32503022012-06-11 20:47:18 +00006851template<typename Derived>
6852StmtResult
6853TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006854 ArrayRef<Token> AsmToks =
6855 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006856
John McCallf413f5e2013-05-03 00:10:13 +00006857 bool HadError = false, HadChange = false;
6858
6859 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6860 SmallVector<Expr*, 8> TransformedExprs;
6861 TransformedExprs.reserve(SrcExprs.size());
6862 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6863 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6864 if (!Result.isUsable()) {
6865 HadError = true;
6866 } else {
6867 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006868 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006869 }
6870 }
6871
6872 if (HadError) return StmtError();
6873 if (!HadChange && !getDerived().AlwaysRebuild())
6874 return Owned(S);
6875
Chad Rosierb6f46c12012-08-15 16:53:30 +00006876 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006877 AsmToks, S->getAsmString(),
6878 S->getNumOutputs(), S->getNumInputs(),
6879 S->getAllConstraints(), S->getClobbers(),
6880 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006881}
Douglas Gregorebe10102009-08-20 07:17:43 +00006882
Richard Smith9f690bd2015-10-27 06:02:45 +00006883// C++ Coroutines TS
6884
6885template<typename Derived>
6886StmtResult
6887TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006888 auto *ScopeInfo = SemaRef.getCurFunction();
6889 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00006890 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006891 ScopeInfo->NeedsCoroutineSuspends &&
6892 ScopeInfo->CoroutineSuspends.first == nullptr &&
6893 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00006894 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006895
6896 // Set that we have (possibly-invalid) suspend points before we do anything
6897 // that may fail.
6898 ScopeInfo->setNeedsCoroutineSuspends(false);
6899
6900 // The new CoroutinePromise object needs to be built and put into the current
6901 // FunctionScopeInfo before any transformations or rebuilding occurs.
Eric Fiselierbee782b2017-04-03 19:21:00 +00006902 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6903 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006904 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006905 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6906 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006907
6908 // Transform the implicit coroutine statements we built during the initial
6909 // parse.
6910 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6911 if (InitSuspend.isInvalid())
6912 return StmtError();
6913 StmtResult FinalSuspend =
6914 getDerived().TransformStmt(S->getFinalSuspendStmt());
6915 if (FinalSuspend.isInvalid())
6916 return StmtError();
6917 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6918 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006919
6920 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6921 if (BodyRes.isInvalid())
6922 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006923
Eric Fiselierbee782b2017-04-03 19:21:00 +00006924 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6925 if (Builder.isInvalid())
6926 return StmtError();
6927
6928 Expr *ReturnObject = S->getReturnValueInit();
6929 assert(ReturnObject && "the return object is expected to be valid");
6930 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6931 /*NoCopyInit*/ false);
6932 if (Res.isInvalid())
6933 return StmtError();
6934 Builder.ReturnValue = Res.get();
6935
6936 if (S->hasDependentPromiseType()) {
6937 assert(!Promise->getType()->isDependentType() &&
6938 "the promise type must no longer be dependent");
6939 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6940 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6941 "these nodes should not have been built yet");
6942 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006943 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006944 } else {
6945 if (auto *OnFallthrough = S->getFallthroughHandler()) {
6946 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
6947 if (Res.isInvalid())
6948 return StmtError();
6949 Builder.OnFallthrough = Res.get();
6950 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006951
Eric Fiselierbee782b2017-04-03 19:21:00 +00006952 if (auto *OnException = S->getExceptionHandler()) {
6953 StmtResult Res = getDerived().TransformStmt(OnException);
6954 if (Res.isInvalid())
6955 return StmtError();
6956 Builder.OnException = Res.get();
6957 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006958
Eric Fiselierbee782b2017-04-03 19:21:00 +00006959 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
6960 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
6961 if (Res.isInvalid())
6962 return StmtError();
6963 Builder.ReturnStmtOnAllocFailure = Res.get();
6964 }
6965
6966 // Transform any additional statements we may have already built
6967 assert(S->getAllocate() && S->getDeallocate() &&
6968 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006969 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
6970 if (AllocRes.isInvalid())
6971 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006972 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006973
6974 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
6975 if (DeallocRes.isInvalid())
6976 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006977 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00006978
6979 assert(S->getResultDecl() && "ResultDecl must already be built");
6980 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
6981 if (ResultDecl.isInvalid())
6982 return StmtError();
6983 Builder.ResultDecl = ResultDecl.get();
6984
6985 if (auto *ReturnStmt = S->getReturnStmt()) {
6986 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
6987 if (Res.isInvalid())
6988 return StmtError();
6989 Builder.ReturnStmt = Res.get();
6990 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006991 }
Eric Fiselierde7943b2017-06-03 00:22:18 +00006992 if (!Builder.buildParameterMoves())
6993 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006994
Eric Fiselierbee782b2017-04-03 19:21:00 +00006995 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00006996}
6997
6998template<typename Derived>
6999StmtResult
7000TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7001 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7002 /*NotCopyInit*/false);
7003 if (Result.isInvalid())
7004 return StmtError();
7005
7006 // Always rebuild; we don't know if this needs to be injected into a new
7007 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007008 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7009 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007010}
7011
7012template<typename Derived>
7013ExprResult
7014TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7015 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7016 /*NotCopyInit*/false);
7017 if (Result.isInvalid())
7018 return ExprError();
7019
7020 // Always rebuild; we don't know if this needs to be injected into a new
7021 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007022 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7023 E->isImplicit());
7024}
7025
7026template <typename Derived>
7027ExprResult
7028TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7029 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7030 /*NotCopyInit*/ false);
7031 if (OperandResult.isInvalid())
7032 return ExprError();
7033
7034 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7035 E->getOperatorCoawaitLookup());
7036
7037 if (LookupResult.isInvalid())
7038 return ExprError();
7039
7040 // Always rebuild; we don't know if this needs to be injected into a new
7041 // context or if the promise type has changed.
7042 return getDerived().RebuildDependentCoawaitExpr(
7043 E->getKeywordLoc(), OperandResult.get(),
7044 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007045}
7046
7047template<typename Derived>
7048ExprResult
7049TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7050 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7051 /*NotCopyInit*/false);
7052 if (Result.isInvalid())
7053 return ExprError();
7054
7055 // Always rebuild; we don't know if this needs to be injected into a new
7056 // context or if the promise type has changed.
7057 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7058}
7059
7060// Objective-C Statements.
7061
Douglas Gregorebe10102009-08-20 07:17:43 +00007062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007063StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007064TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007065 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007066 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007067 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007068 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007069
Douglas Gregor96c79492010-04-23 22:50:49 +00007070 // Transform the @catch statements (if present).
7071 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007072 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007073 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007074 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007075 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007076 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007077 if (Catch.get() != S->getCatchStmt(I))
7078 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007079 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007081
Douglas Gregor306de2f2010-04-22 23:59:56 +00007082 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007083 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007084 if (S->getFinallyStmt()) {
7085 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7086 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007087 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007088 }
7089
7090 // If nothing changed, just retain this statement.
7091 if (!getDerived().AlwaysRebuild() &&
7092 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007093 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007094 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007095 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007096
Douglas Gregor306de2f2010-04-22 23:59:56 +00007097 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007098 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007099 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007100}
Mike Stump11289f42009-09-09 15:08:12 +00007101
Douglas Gregorebe10102009-08-20 07:17:43 +00007102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007103StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007104TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007105 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007106 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007107 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007108 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007109 if (FromVar->getTypeSourceInfo()) {
7110 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7111 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007112 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007114
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007115 QualType T;
7116 if (TSInfo)
7117 T = TSInfo->getType();
7118 else {
7119 T = getDerived().TransformType(FromVar->getType());
7120 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007121 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007123
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007124 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7125 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007126 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007128
John McCalldadc5752010-08-24 06:29:42 +00007129 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007130 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007131 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007132
7133 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007134 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007135 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007136}
Mike Stump11289f42009-09-09 15:08:12 +00007137
Douglas Gregorebe10102009-08-20 07:17:43 +00007138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007139StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007140TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007141 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007142 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007143 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007144 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007145
Douglas Gregor306de2f2010-04-22 23:59:56 +00007146 // If nothing changed, just retain this statement.
7147 if (!getDerived().AlwaysRebuild() &&
7148 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007149 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007150
7151 // Build a new statement.
7152 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007153 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007154}
Mike Stump11289f42009-09-09 15:08:12 +00007155
Douglas Gregorebe10102009-08-20 07:17:43 +00007156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007157StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007158TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007159 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007160 if (S->getThrowExpr()) {
7161 Operand = getDerived().TransformExpr(S->getThrowExpr());
7162 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007163 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007164 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007165
Douglas Gregor2900c162010-04-22 21:44:01 +00007166 if (!getDerived().AlwaysRebuild() &&
7167 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007168 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007169
John McCallb268a282010-08-23 23:25:46 +00007170 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007171}
Mike Stump11289f42009-09-09 15:08:12 +00007172
Douglas Gregorebe10102009-08-20 07:17:43 +00007173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007174StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007175TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007176 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007177 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007178 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007179 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007180 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007181 Object =
7182 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7183 Object.get());
7184 if (Object.isInvalid())
7185 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007186
Douglas Gregor6148de72010-04-22 22:01:21 +00007187 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007188 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007189 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007190 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007191
Douglas Gregor6148de72010-04-22 22:01:21 +00007192 // If nothing change, just retain the current statement.
7193 if (!getDerived().AlwaysRebuild() &&
7194 Object.get() == S->getSynchExpr() &&
7195 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007196 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007197
7198 // Build a new statement.
7199 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007200 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007201}
7202
7203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007204StmtResult
John McCall31168b02011-06-15 23:02:42 +00007205TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7206 ObjCAutoreleasePoolStmt *S) {
7207 // Transform the body.
7208 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7209 if (Body.isInvalid())
7210 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007211
John McCall31168b02011-06-15 23:02:42 +00007212 // If nothing changed, just retain this statement.
7213 if (!getDerived().AlwaysRebuild() &&
7214 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007215 return S;
John McCall31168b02011-06-15 23:02:42 +00007216
7217 // Build a new statement.
7218 return getDerived().RebuildObjCAutoreleasePoolStmt(
7219 S->getAtLoc(), Body.get());
7220}
7221
7222template<typename Derived>
7223StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007224TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007225 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007226 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007227 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007228 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007229 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007230
Douglas Gregorf68a5082010-04-22 23:10:45 +00007231 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007232 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007233 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007234 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007235
Douglas Gregorf68a5082010-04-22 23:10:45 +00007236 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007237 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007238 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007239 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007240
Douglas Gregorf68a5082010-04-22 23:10:45 +00007241 // If nothing changed, just retain this statement.
7242 if (!getDerived().AlwaysRebuild() &&
7243 Element.get() == S->getElement() &&
7244 Collection.get() == S->getCollection() &&
7245 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007246 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007247
Douglas Gregorf68a5082010-04-22 23:10:45 +00007248 // Build a new statement.
7249 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007250 Element.get(),
7251 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007252 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007253 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007254}
7255
David Majnemer5f7efef2013-10-15 09:50:08 +00007256template <typename Derived>
7257StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007258 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007259 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007260 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7261 TypeSourceInfo *T =
7262 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007263 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007264 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007265
David Majnemer5f7efef2013-10-15 09:50:08 +00007266 Var = getDerived().RebuildExceptionDecl(
7267 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7268 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007269 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007270 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007271 }
Mike Stump11289f42009-09-09 15:08:12 +00007272
Douglas Gregorebe10102009-08-20 07:17:43 +00007273 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007274 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007275 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007276 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007277
David Majnemer5f7efef2013-10-15 09:50:08 +00007278 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007279 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007280 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007281
David Majnemer5f7efef2013-10-15 09:50:08 +00007282 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007283}
Mike Stump11289f42009-09-09 15:08:12 +00007284
David Majnemer5f7efef2013-10-15 09:50:08 +00007285template <typename Derived>
7286StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007287 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007288 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007289 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007290 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007291
Douglas Gregorebe10102009-08-20 07:17:43 +00007292 // Transform the handlers.
7293 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007294 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007295 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007296 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007297 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007298 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007299
Douglas Gregorebe10102009-08-20 07:17:43 +00007300 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007301 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007302 }
Mike Stump11289f42009-09-09 15:08:12 +00007303
David Majnemer5f7efef2013-10-15 09:50:08 +00007304 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007305 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007306 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007307
John McCallb268a282010-08-23 23:25:46 +00007308 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007309 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007310}
Mike Stump11289f42009-09-09 15:08:12 +00007311
Richard Smith02e85f32011-04-14 22:09:26 +00007312template<typename Derived>
7313StmtResult
7314TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7315 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7316 if (Range.isInvalid())
7317 return StmtError();
7318
Richard Smith01694c32016-03-20 10:33:40 +00007319 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7320 if (Begin.isInvalid())
7321 return StmtError();
7322 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7323 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007324 return StmtError();
7325
7326 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7327 if (Cond.isInvalid())
7328 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007329 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007330 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007331 if (Cond.isInvalid())
7332 return StmtError();
7333 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007334 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007335
7336 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7337 if (Inc.isInvalid())
7338 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007339 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007340 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007341
7342 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7343 if (LoopVar.isInvalid())
7344 return StmtError();
7345
7346 StmtResult NewStmt = S;
7347 if (getDerived().AlwaysRebuild() ||
7348 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007349 Begin.get() != S->getBeginStmt() ||
7350 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007351 Cond.get() != S->getCond() ||
7352 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007353 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007354 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007355 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007356 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007357 Begin.get(), End.get(),
7358 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007359 Inc.get(), LoopVar.get(),
7360 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007361 if (NewStmt.isInvalid())
7362 return StmtError();
7363 }
Richard Smith02e85f32011-04-14 22:09:26 +00007364
7365 StmtResult Body = getDerived().TransformStmt(S->getBody());
7366 if (Body.isInvalid())
7367 return StmtError();
7368
7369 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7370 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007371 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007372 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007373 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007374 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007375 Begin.get(), End.get(),
7376 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007377 Inc.get(), LoopVar.get(),
7378 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007379 if (NewStmt.isInvalid())
7380 return StmtError();
7381 }
Richard Smith02e85f32011-04-14 22:09:26 +00007382
7383 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007384 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007385
7386 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7387}
7388
John Wiegley1c0675e2011-04-28 01:08:34 +00007389template<typename Derived>
7390StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007391TreeTransform<Derived>::TransformMSDependentExistsStmt(
7392 MSDependentExistsStmt *S) {
7393 // Transform the nested-name-specifier, if any.
7394 NestedNameSpecifierLoc QualifierLoc;
7395 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007396 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007397 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7398 if (!QualifierLoc)
7399 return StmtError();
7400 }
7401
7402 // Transform the declaration name.
7403 DeclarationNameInfo NameInfo = S->getNameInfo();
7404 if (NameInfo.getName()) {
7405 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7406 if (!NameInfo.getName())
7407 return StmtError();
7408 }
7409
7410 // Check whether anything changed.
7411 if (!getDerived().AlwaysRebuild() &&
7412 QualifierLoc == S->getQualifierLoc() &&
7413 NameInfo.getName() == S->getNameInfo().getName())
7414 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007415
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007416 // Determine whether this name exists, if we can.
7417 CXXScopeSpec SS;
7418 SS.Adopt(QualifierLoc);
7419 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007420 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007421 case Sema::IER_Exists:
7422 if (S->isIfExists())
7423 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007424
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007425 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7426
7427 case Sema::IER_DoesNotExist:
7428 if (S->isIfNotExists())
7429 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007430
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007431 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007432
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007433 case Sema::IER_Dependent:
7434 Dependent = true;
7435 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007436
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007437 case Sema::IER_Error:
7438 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007440
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007441 // We need to continue with the instantiation, so do so now.
7442 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7443 if (SubStmt.isInvalid())
7444 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007445
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007446 // If we have resolved the name, just transform to the substatement.
7447 if (!Dependent)
7448 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007449
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007450 // The name is still dependent, so build a dependent expression again.
7451 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7452 S->isIfExists(),
7453 QualifierLoc,
7454 NameInfo,
7455 SubStmt.get());
7456}
7457
7458template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007459ExprResult
7460TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7461 NestedNameSpecifierLoc QualifierLoc;
7462 if (E->getQualifierLoc()) {
7463 QualifierLoc
7464 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7465 if (!QualifierLoc)
7466 return ExprError();
7467 }
7468
7469 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7470 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7471 if (!PD)
7472 return ExprError();
7473
7474 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7475 if (Base.isInvalid())
7476 return ExprError();
7477
7478 return new (SemaRef.getASTContext())
7479 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7480 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7481 QualifierLoc, E->getMemberLoc());
7482}
7483
David Majnemerfad8f482013-10-15 09:33:02 +00007484template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007485ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7486 MSPropertySubscriptExpr *E) {
7487 auto BaseRes = getDerived().TransformExpr(E->getBase());
7488 if (BaseRes.isInvalid())
7489 return ExprError();
7490 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7491 if (IdxRes.isInvalid())
7492 return ExprError();
7493
7494 if (!getDerived().AlwaysRebuild() &&
7495 BaseRes.get() == E->getBase() &&
7496 IdxRes.get() == E->getIdx())
7497 return E;
7498
7499 return getDerived().RebuildArraySubscriptExpr(
7500 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7501}
7502
7503template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007504StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007505 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007506 if (TryBlock.isInvalid())
7507 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007508
7509 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007510 if (Handler.isInvalid())
7511 return StmtError();
7512
David Majnemerfad8f482013-10-15 09:33:02 +00007513 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7514 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007515 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007516
Warren Huntf6be4cb2014-07-25 20:52:51 +00007517 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7518 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007519}
7520
David Majnemerfad8f482013-10-15 09:33:02 +00007521template <typename Derived>
7522StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007523 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007524 if (Block.isInvalid())
7525 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007526
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007527 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007528}
7529
David Majnemerfad8f482013-10-15 09:33:02 +00007530template <typename Derived>
7531StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007532 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007533 if (FilterExpr.isInvalid())
7534 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007535
David Majnemer7e755502013-10-15 09:30:14 +00007536 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007537 if (Block.isInvalid())
7538 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007539
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007540 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7541 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007542}
7543
David Majnemerfad8f482013-10-15 09:33:02 +00007544template <typename Derived>
7545StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7546 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007547 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7548 else
7549 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7550}
7551
Nico Weber9b982072014-07-07 00:12:30 +00007552template<typename Derived>
7553StmtResult
7554TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7555 return S;
7556}
7557
Alexander Musman64d33f12014-06-04 07:53:32 +00007558//===----------------------------------------------------------------------===//
7559// OpenMP directive transformation
7560//===----------------------------------------------------------------------===//
7561template <typename Derived>
7562StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7563 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007564
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007565 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007566 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007567 ArrayRef<OMPClause *> Clauses = D->clauses();
7568 TClauses.reserve(Clauses.size());
7569 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7570 I != E; ++I) {
7571 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007572 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007573 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007574 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007575 if (Clause)
7576 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007577 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007578 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007579 }
7580 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007581 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007582 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007583 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7584 /*CurScope=*/nullptr);
7585 StmtResult Body;
7586 {
7587 Sema::CompoundScopeRAII CompoundScope(getSema());
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007588 int ThisCaptureLevel =
7589 Sema::getOpenMPCaptureLevels(D->getDirectiveKind());
7590 Stmt *CS = D->getAssociatedStmt();
7591 while (--ThisCaptureLevel >= 0)
7592 CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7593 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007594 }
7595 AssociatedStmt =
7596 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007597 if (AssociatedStmt.isInvalid()) {
7598 return StmtError();
7599 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007600 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007601 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007602 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007603 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007604
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007605 // Transform directive name for 'omp critical' directive.
7606 DeclarationNameInfo DirName;
7607 if (D->getDirectiveKind() == OMPD_critical) {
7608 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7609 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7610 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007611 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7612 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7613 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007614 } else if (D->getDirectiveKind() == OMPD_cancel) {
7615 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007616 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007617
Alexander Musman64d33f12014-06-04 07:53:32 +00007618 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007619 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7620 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007621}
7622
Alexander Musman64d33f12014-06-04 07:53:32 +00007623template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007624StmtResult
7625TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7626 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007627 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7628 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007629 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7630 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7631 return Res;
7632}
7633
Alexander Musman64d33f12014-06-04 07:53:32 +00007634template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007635StmtResult
7636TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7637 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007638 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7639 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007640 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7641 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007642 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007643}
7644
Alexey Bataevf29276e2014-06-18 04:14:57 +00007645template <typename Derived>
7646StmtResult
7647TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7648 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007649 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7650 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007651 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7652 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7653 return Res;
7654}
7655
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007656template <typename Derived>
7657StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007658TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7659 DeclarationNameInfo DirName;
7660 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7661 D->getLocStart());
7662 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7663 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7664 return Res;
7665}
7666
7667template <typename Derived>
7668StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007669TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7670 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007671 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7672 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007673 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7674 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7675 return Res;
7676}
7677
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007678template <typename Derived>
7679StmtResult
7680TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7681 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007682 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7683 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007684 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7685 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7686 return Res;
7687}
7688
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007689template <typename Derived>
7690StmtResult
7691TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7692 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007693 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7694 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007695 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7696 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7697 return Res;
7698}
7699
Alexey Bataev4acb8592014-07-07 13:01:15 +00007700template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007701StmtResult
7702TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7703 DeclarationNameInfo DirName;
7704 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7705 D->getLocStart());
7706 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7707 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7708 return Res;
7709}
7710
7711template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007712StmtResult
7713TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7714 getDerived().getSema().StartOpenMPDSABlock(
7715 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7716 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7717 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7718 return Res;
7719}
7720
7721template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007722StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7723 OMPParallelForDirective *D) {
7724 DeclarationNameInfo DirName;
7725 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7726 nullptr, D->getLocStart());
7727 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7728 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7729 return Res;
7730}
7731
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007732template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007733StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7734 OMPParallelForSimdDirective *D) {
7735 DeclarationNameInfo DirName;
7736 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7737 nullptr, D->getLocStart());
7738 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7739 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7740 return Res;
7741}
7742
7743template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007744StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7745 OMPParallelSectionsDirective *D) {
7746 DeclarationNameInfo DirName;
7747 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7748 nullptr, D->getLocStart());
7749 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7750 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7751 return Res;
7752}
7753
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007754template <typename Derived>
7755StmtResult
7756TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7757 DeclarationNameInfo DirName;
7758 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7759 D->getLocStart());
7760 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7761 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7762 return Res;
7763}
7764
Alexey Bataev68446b72014-07-18 07:47:19 +00007765template <typename Derived>
7766StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7767 OMPTaskyieldDirective *D) {
7768 DeclarationNameInfo DirName;
7769 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7770 D->getLocStart());
7771 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7772 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7773 return Res;
7774}
7775
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007776template <typename Derived>
7777StmtResult
7778TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7779 DeclarationNameInfo DirName;
7780 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7781 D->getLocStart());
7782 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7783 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7784 return Res;
7785}
7786
Alexey Bataev2df347a2014-07-18 10:17:07 +00007787template <typename Derived>
7788StmtResult
7789TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7790 DeclarationNameInfo DirName;
7791 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7792 D->getLocStart());
7793 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7794 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7795 return Res;
7796}
7797
Alexey Bataev6125da92014-07-21 11:26:11 +00007798template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007799StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7800 OMPTaskgroupDirective *D) {
7801 DeclarationNameInfo DirName;
7802 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7803 D->getLocStart());
7804 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7805 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7806 return Res;
7807}
7808
7809template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007810StmtResult
7811TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7812 DeclarationNameInfo DirName;
7813 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7814 D->getLocStart());
7815 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7816 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7817 return Res;
7818}
7819
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007820template <typename Derived>
7821StmtResult
7822TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7823 DeclarationNameInfo DirName;
7824 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7825 D->getLocStart());
7826 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7827 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7828 return Res;
7829}
7830
Alexey Bataev0162e452014-07-22 10:10:35 +00007831template <typename Derived>
7832StmtResult
7833TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7834 DeclarationNameInfo DirName;
7835 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7836 D->getLocStart());
7837 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7838 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7839 return Res;
7840}
7841
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007842template <typename Derived>
7843StmtResult
7844TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7845 DeclarationNameInfo DirName;
7846 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7847 D->getLocStart());
7848 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7849 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7850 return Res;
7851}
7852
Alexey Bataev13314bf2014-10-09 04:18:56 +00007853template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007854StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7855 OMPTargetDataDirective *D) {
7856 DeclarationNameInfo DirName;
7857 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7858 D->getLocStart());
7859 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7860 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7861 return Res;
7862}
7863
7864template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007865StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7866 OMPTargetEnterDataDirective *D) {
7867 DeclarationNameInfo DirName;
7868 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7869 nullptr, D->getLocStart());
7870 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7871 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7872 return Res;
7873}
7874
7875template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007876StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7877 OMPTargetExitDataDirective *D) {
7878 DeclarationNameInfo DirName;
7879 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7880 nullptr, D->getLocStart());
7881 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7882 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7883 return Res;
7884}
7885
7886template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007887StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7888 OMPTargetParallelDirective *D) {
7889 DeclarationNameInfo DirName;
7890 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7891 nullptr, D->getLocStart());
7892 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7893 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7894 return Res;
7895}
7896
7897template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007898StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7899 OMPTargetParallelForDirective *D) {
7900 DeclarationNameInfo DirName;
7901 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7902 nullptr, D->getLocStart());
7903 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7904 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7905 return Res;
7906}
7907
7908template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007909StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7910 OMPTargetUpdateDirective *D) {
7911 DeclarationNameInfo DirName;
7912 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7913 nullptr, D->getLocStart());
7914 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7915 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7916 return Res;
7917}
7918
7919template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007920StmtResult
7921TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7922 DeclarationNameInfo DirName;
7923 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7924 D->getLocStart());
7925 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7926 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7927 return Res;
7928}
7929
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007930template <typename Derived>
7931StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7932 OMPCancellationPointDirective *D) {
7933 DeclarationNameInfo DirName;
7934 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7935 nullptr, D->getLocStart());
7936 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7937 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7938 return Res;
7939}
7940
Alexey Bataev80909872015-07-02 11:25:17 +00007941template <typename Derived>
7942StmtResult
7943TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7944 DeclarationNameInfo DirName;
7945 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7946 D->getLocStart());
7947 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7948 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7949 return Res;
7950}
7951
Alexey Bataev49f6e782015-12-01 04:18:41 +00007952template <typename Derived>
7953StmtResult
7954TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7955 DeclarationNameInfo DirName;
7956 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7957 D->getLocStart());
7958 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7959 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7960 return Res;
7961}
7962
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007963template <typename Derived>
7964StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7965 OMPTaskLoopSimdDirective *D) {
7966 DeclarationNameInfo DirName;
7967 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7968 nullptr, D->getLocStart());
7969 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7970 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7971 return Res;
7972}
7973
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007974template <typename Derived>
7975StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7976 OMPDistributeDirective *D) {
7977 DeclarationNameInfo DirName;
7978 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7979 D->getLocStart());
7980 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7981 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7982 return Res;
7983}
7984
Carlo Bertolli9925f152016-06-27 14:55:37 +00007985template <typename Derived>
7986StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7987 OMPDistributeParallelForDirective *D) {
7988 DeclarationNameInfo DirName;
7989 getDerived().getSema().StartOpenMPDSABlock(
7990 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7991 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7992 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7993 return Res;
7994}
7995
Kelvin Li4a39add2016-07-05 05:00:15 +00007996template <typename Derived>
7997StmtResult
7998TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7999 OMPDistributeParallelForSimdDirective *D) {
8000 DeclarationNameInfo DirName;
8001 getDerived().getSema().StartOpenMPDSABlock(
8002 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8003 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8004 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8005 return Res;
8006}
8007
Kelvin Li787f3fc2016-07-06 04:45:38 +00008008template <typename Derived>
8009StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8010 OMPDistributeSimdDirective *D) {
8011 DeclarationNameInfo DirName;
8012 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
8013 nullptr, D->getLocStart());
8014 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8015 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8016 return Res;
8017}
8018
Kelvin Lia579b912016-07-14 02:54:56 +00008019template <typename Derived>
8020StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8021 OMPTargetParallelForSimdDirective *D) {
8022 DeclarationNameInfo DirName;
8023 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8024 DirName, nullptr,
8025 D->getLocStart());
8026 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8027 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8028 return Res;
8029}
8030
Kelvin Li986330c2016-07-20 22:57:10 +00008031template <typename Derived>
8032StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8033 OMPTargetSimdDirective *D) {
8034 DeclarationNameInfo DirName;
8035 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8036 D->getLocStart());
8037 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8038 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8039 return Res;
8040}
8041
Kelvin Li02532872016-08-05 14:37:37 +00008042template <typename Derived>
8043StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8044 OMPTeamsDistributeDirective *D) {
8045 DeclarationNameInfo DirName;
8046 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8047 nullptr, D->getLocStart());
8048 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8049 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8050 return Res;
8051}
8052
Kelvin Li4e325f72016-10-25 12:50:55 +00008053template <typename Derived>
8054StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8055 OMPTeamsDistributeSimdDirective *D) {
8056 DeclarationNameInfo DirName;
8057 getDerived().getSema().StartOpenMPDSABlock(
8058 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8059 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8060 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8061 return Res;
8062}
8063
Kelvin Li579e41c2016-11-30 23:51:03 +00008064template <typename Derived>
8065StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8066 OMPTeamsDistributeParallelForSimdDirective *D) {
8067 DeclarationNameInfo DirName;
8068 getDerived().getSema().StartOpenMPDSABlock(
8069 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8070 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8071 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8072 return Res;
8073}
8074
Kelvin Li7ade93f2016-12-09 03:24:30 +00008075template <typename Derived>
8076StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8077 OMPTeamsDistributeParallelForDirective *D) {
8078 DeclarationNameInfo DirName;
8079 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8080 DirName, nullptr, D->getLocStart());
8081 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8082 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8083 return Res;
8084}
8085
Kelvin Libf594a52016-12-17 05:48:59 +00008086template <typename Derived>
8087StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8088 OMPTargetTeamsDirective *D) {
8089 DeclarationNameInfo DirName;
8090 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8091 nullptr, D->getLocStart());
8092 auto Res = getDerived().TransformOMPExecutableDirective(D);
8093 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8094 return Res;
8095}
Kelvin Li579e41c2016-11-30 23:51:03 +00008096
Kelvin Li83c451e2016-12-25 04:52:54 +00008097template <typename Derived>
8098StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8099 OMPTargetTeamsDistributeDirective *D) {
8100 DeclarationNameInfo DirName;
8101 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8102 DirName, nullptr, D->getLocStart());
8103 auto Res = getDerived().TransformOMPExecutableDirective(D);
8104 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8105 return Res;
8106}
8107
Kelvin Li80e8f562016-12-29 22:16:30 +00008108template <typename Derived>
8109StmtResult
8110TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8111 OMPTargetTeamsDistributeParallelForDirective *D) {
8112 DeclarationNameInfo DirName;
8113 getDerived().getSema().StartOpenMPDSABlock(
8114 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8115 D->getLocStart());
8116 auto Res = getDerived().TransformOMPExecutableDirective(D);
8117 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8118 return Res;
8119}
8120
Kelvin Li1851df52017-01-03 05:23:48 +00008121template <typename Derived>
8122StmtResult TreeTransform<Derived>::
8123 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8124 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8125 DeclarationNameInfo DirName;
8126 getDerived().getSema().StartOpenMPDSABlock(
8127 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8128 D->getLocStart());
8129 auto Res = getDerived().TransformOMPExecutableDirective(D);
8130 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8131 return Res;
8132}
8133
Kelvin Lida681182017-01-10 18:08:18 +00008134template <typename Derived>
8135StmtResult
8136TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8137 OMPTargetTeamsDistributeSimdDirective *D) {
8138 DeclarationNameInfo DirName;
8139 getDerived().getSema().StartOpenMPDSABlock(
8140 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8141 auto Res = getDerived().TransformOMPExecutableDirective(D);
8142 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8143 return Res;
8144}
8145
Kelvin Li1851df52017-01-03 05:23:48 +00008146
Alexander Musman64d33f12014-06-04 07:53:32 +00008147//===----------------------------------------------------------------------===//
8148// OpenMP clause transformation
8149//===----------------------------------------------------------------------===//
8150template <typename Derived>
8151OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008152 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8153 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008154 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008155 return getDerived().RebuildOMPIfClause(
8156 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8157 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008158}
8159
Alexander Musman64d33f12014-06-04 07:53:32 +00008160template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008161OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8162 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8163 if (Cond.isInvalid())
8164 return nullptr;
8165 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8166 C->getLParenLoc(), C->getLocEnd());
8167}
8168
8169template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008170OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008171TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8172 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8173 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008174 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008175 return getDerived().RebuildOMPNumThreadsClause(
8176 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00008177}
8178
Alexey Bataev62c87d22014-03-21 04:51:18 +00008179template <typename Derived>
8180OMPClause *
8181TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8182 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8183 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008184 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008185 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008186 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008187}
8188
Alexander Musman8bd31e62014-05-27 15:12:19 +00008189template <typename Derived>
8190OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008191TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8192 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8193 if (E.isInvalid())
8194 return nullptr;
8195 return getDerived().RebuildOMPSimdlenClause(
8196 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8197}
8198
8199template <typename Derived>
8200OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008201TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8202 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8203 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008204 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008205 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008206 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008207}
8208
Alexander Musman64d33f12014-06-04 07:53:32 +00008209template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008210OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008211TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008212 return getDerived().RebuildOMPDefaultClause(
8213 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8214 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008215}
8216
Alexander Musman64d33f12014-06-04 07:53:32 +00008217template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008218OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008219TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008220 return getDerived().RebuildOMPProcBindClause(
8221 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8222 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008223}
8224
Alexander Musman64d33f12014-06-04 07:53:32 +00008225template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008226OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008227TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8228 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8229 if (E.isInvalid())
8230 return nullptr;
8231 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008232 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008233 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008234 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008235 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8236}
8237
8238template <typename Derived>
8239OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008240TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008241 ExprResult E;
8242 if (auto *Num = C->getNumForLoops()) {
8243 E = getDerived().TransformExpr(Num);
8244 if (E.isInvalid())
8245 return nullptr;
8246 }
8247 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8248 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008249}
8250
8251template <typename Derived>
8252OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008253TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8254 // No need to rebuild this clause, no template-dependent parameters.
8255 return C;
8256}
8257
8258template <typename Derived>
8259OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008260TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8261 // No need to rebuild this clause, no template-dependent parameters.
8262 return C;
8263}
8264
8265template <typename Derived>
8266OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008267TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8268 // No need to rebuild this clause, no template-dependent parameters.
8269 return C;
8270}
8271
8272template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008273OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8274 // No need to rebuild this clause, no template-dependent parameters.
8275 return C;
8276}
8277
8278template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008279OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8280 // No need to rebuild this clause, no template-dependent parameters.
8281 return C;
8282}
8283
8284template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008285OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008286TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8287 // No need to rebuild this clause, no template-dependent parameters.
8288 return C;
8289}
8290
8291template <typename Derived>
8292OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008293TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8294 // No need to rebuild this clause, no template-dependent parameters.
8295 return C;
8296}
8297
8298template <typename Derived>
8299OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008300TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8301 // No need to rebuild this clause, no template-dependent parameters.
8302 return C;
8303}
8304
8305template <typename Derived>
8306OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008307TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8308 // No need to rebuild this clause, no template-dependent parameters.
8309 return C;
8310}
8311
8312template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008313OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8314 // No need to rebuild this clause, no template-dependent parameters.
8315 return C;
8316}
8317
8318template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008319OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008320TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8321 // No need to rebuild this clause, no template-dependent parameters.
8322 return C;
8323}
8324
8325template <typename Derived>
8326OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008327TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008328 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008329 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008330 for (auto *VE : C->varlists()) {
8331 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008332 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008333 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008334 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008335 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008336 return getDerived().RebuildOMPPrivateClause(
8337 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008338}
8339
Alexander Musman64d33f12014-06-04 07:53:32 +00008340template <typename Derived>
8341OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8342 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008343 llvm::SmallVector<Expr *, 16> Vars;
8344 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008345 for (auto *VE : C->varlists()) {
8346 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008347 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008348 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008349 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008350 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008351 return getDerived().RebuildOMPFirstprivateClause(
8352 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008353}
8354
Alexander Musman64d33f12014-06-04 07:53:32 +00008355template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008356OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008357TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8358 llvm::SmallVector<Expr *, 16> Vars;
8359 Vars.reserve(C->varlist_size());
8360 for (auto *VE : C->varlists()) {
8361 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8362 if (EVar.isInvalid())
8363 return nullptr;
8364 Vars.push_back(EVar.get());
8365 }
8366 return getDerived().RebuildOMPLastprivateClause(
8367 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8368}
8369
8370template <typename Derived>
8371OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008372TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8373 llvm::SmallVector<Expr *, 16> Vars;
8374 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008375 for (auto *VE : C->varlists()) {
8376 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008377 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008378 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008379 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008380 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008381 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8382 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008383}
8384
Alexander Musman64d33f12014-06-04 07:53:32 +00008385template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008386OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008387TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8388 llvm::SmallVector<Expr *, 16> Vars;
8389 Vars.reserve(C->varlist_size());
8390 for (auto *VE : C->varlists()) {
8391 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8392 if (EVar.isInvalid())
8393 return nullptr;
8394 Vars.push_back(EVar.get());
8395 }
8396 CXXScopeSpec ReductionIdScopeSpec;
8397 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8398
8399 DeclarationNameInfo NameInfo = C->getNameInfo();
8400 if (NameInfo.getName()) {
8401 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8402 if (!NameInfo.getName())
8403 return nullptr;
8404 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008405 // Build a list of all UDR decls with the same names ranged by the Scopes.
8406 // The Scope boundary is a duplication of the previous decl.
8407 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8408 for (auto *E : C->reduction_ops()) {
8409 // Transform all the decls.
8410 if (E) {
8411 auto *ULE = cast<UnresolvedLookupExpr>(E);
8412 UnresolvedSet<8> Decls;
8413 for (auto *D : ULE->decls()) {
8414 NamedDecl *InstD =
8415 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8416 Decls.addDecl(InstD, InstD->getAccess());
8417 }
8418 UnresolvedReductions.push_back(
8419 UnresolvedLookupExpr::Create(
8420 SemaRef.Context, /*NamingClass=*/nullptr,
8421 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8422 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8423 Decls.begin(), Decls.end()));
8424 } else
8425 UnresolvedReductions.push_back(nullptr);
8426 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008427 return getDerived().RebuildOMPReductionClause(
8428 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008429 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008430}
8431
8432template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008433OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8434 OMPTaskReductionClause *C) {
8435 llvm::SmallVector<Expr *, 16> Vars;
8436 Vars.reserve(C->varlist_size());
8437 for (auto *VE : C->varlists()) {
8438 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8439 if (EVar.isInvalid())
8440 return nullptr;
8441 Vars.push_back(EVar.get());
8442 }
8443 CXXScopeSpec ReductionIdScopeSpec;
8444 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8445
8446 DeclarationNameInfo NameInfo = C->getNameInfo();
8447 if (NameInfo.getName()) {
8448 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8449 if (!NameInfo.getName())
8450 return nullptr;
8451 }
8452 // Build a list of all UDR decls with the same names ranged by the Scopes.
8453 // The Scope boundary is a duplication of the previous decl.
8454 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8455 for (auto *E : C->reduction_ops()) {
8456 // Transform all the decls.
8457 if (E) {
8458 auto *ULE = cast<UnresolvedLookupExpr>(E);
8459 UnresolvedSet<8> Decls;
8460 for (auto *D : ULE->decls()) {
8461 NamedDecl *InstD =
8462 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8463 Decls.addDecl(InstD, InstD->getAccess());
8464 }
8465 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8466 SemaRef.Context, /*NamingClass=*/nullptr,
8467 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8468 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8469 } else
8470 UnresolvedReductions.push_back(nullptr);
8471 }
8472 return getDerived().RebuildOMPTaskReductionClause(
8473 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8474 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8475}
8476
8477template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008478OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008479TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8480 llvm::SmallVector<Expr *, 16> Vars;
8481 Vars.reserve(C->varlist_size());
8482 for (auto *VE : C->varlists()) {
8483 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8484 if (EVar.isInvalid())
8485 return nullptr;
8486 Vars.push_back(EVar.get());
8487 }
8488 CXXScopeSpec ReductionIdScopeSpec;
8489 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8490
8491 DeclarationNameInfo NameInfo = C->getNameInfo();
8492 if (NameInfo.getName()) {
8493 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8494 if (!NameInfo.getName())
8495 return nullptr;
8496 }
8497 // Build a list of all UDR decls with the same names ranged by the Scopes.
8498 // The Scope boundary is a duplication of the previous decl.
8499 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8500 for (auto *E : C->reduction_ops()) {
8501 // Transform all the decls.
8502 if (E) {
8503 auto *ULE = cast<UnresolvedLookupExpr>(E);
8504 UnresolvedSet<8> Decls;
8505 for (auto *D : ULE->decls()) {
8506 NamedDecl *InstD =
8507 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8508 Decls.addDecl(InstD, InstD->getAccess());
8509 }
8510 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8511 SemaRef.Context, /*NamingClass=*/nullptr,
8512 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8513 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8514 } else
8515 UnresolvedReductions.push_back(nullptr);
8516 }
8517 return getDerived().RebuildOMPInReductionClause(
8518 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8519 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8520}
8521
8522template <typename Derived>
8523OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008524TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8525 llvm::SmallVector<Expr *, 16> Vars;
8526 Vars.reserve(C->varlist_size());
8527 for (auto *VE : C->varlists()) {
8528 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8529 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008530 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008531 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008532 }
8533 ExprResult Step = getDerived().TransformExpr(C->getStep());
8534 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008535 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008536 return getDerived().RebuildOMPLinearClause(
8537 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8538 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008539}
8540
Alexander Musman64d33f12014-06-04 07:53:32 +00008541template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008542OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008543TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8544 llvm::SmallVector<Expr *, 16> Vars;
8545 Vars.reserve(C->varlist_size());
8546 for (auto *VE : C->varlists()) {
8547 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8548 if (EVar.isInvalid())
8549 return nullptr;
8550 Vars.push_back(EVar.get());
8551 }
8552 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8553 if (Alignment.isInvalid())
8554 return nullptr;
8555 return getDerived().RebuildOMPAlignedClause(
8556 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8557 C->getColonLoc(), C->getLocEnd());
8558}
8559
Alexander Musman64d33f12014-06-04 07:53:32 +00008560template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008561OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008562TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8563 llvm::SmallVector<Expr *, 16> Vars;
8564 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008565 for (auto *VE : C->varlists()) {
8566 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008567 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008568 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008569 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008570 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008571 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8572 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008573}
8574
Alexey Bataevbae9a792014-06-27 10:37:06 +00008575template <typename Derived>
8576OMPClause *
8577TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8578 llvm::SmallVector<Expr *, 16> Vars;
8579 Vars.reserve(C->varlist_size());
8580 for (auto *VE : C->varlists()) {
8581 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8582 if (EVar.isInvalid())
8583 return nullptr;
8584 Vars.push_back(EVar.get());
8585 }
8586 return getDerived().RebuildOMPCopyprivateClause(
8587 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8588}
8589
Alexey Bataev6125da92014-07-21 11:26:11 +00008590template <typename Derived>
8591OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8592 llvm::SmallVector<Expr *, 16> Vars;
8593 Vars.reserve(C->varlist_size());
8594 for (auto *VE : C->varlists()) {
8595 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8596 if (EVar.isInvalid())
8597 return nullptr;
8598 Vars.push_back(EVar.get());
8599 }
8600 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8601 C->getLParenLoc(), C->getLocEnd());
8602}
8603
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008604template <typename Derived>
8605OMPClause *
8606TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8607 llvm::SmallVector<Expr *, 16> Vars;
8608 Vars.reserve(C->varlist_size());
8609 for (auto *VE : C->varlists()) {
8610 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8611 if (EVar.isInvalid())
8612 return nullptr;
8613 Vars.push_back(EVar.get());
8614 }
8615 return getDerived().RebuildOMPDependClause(
8616 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8617 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8618}
8619
Michael Wonge710d542015-08-07 16:16:36 +00008620template <typename Derived>
8621OMPClause *
8622TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8623 ExprResult E = getDerived().TransformExpr(C->getDevice());
8624 if (E.isInvalid())
8625 return nullptr;
8626 return getDerived().RebuildOMPDeviceClause(
8627 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8628}
8629
Kelvin Li0bff7af2015-11-23 05:32:03 +00008630template <typename Derived>
8631OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8632 llvm::SmallVector<Expr *, 16> Vars;
8633 Vars.reserve(C->varlist_size());
8634 for (auto *VE : C->varlists()) {
8635 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8636 if (EVar.isInvalid())
8637 return nullptr;
8638 Vars.push_back(EVar.get());
8639 }
8640 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008641 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8642 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8643 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008644}
8645
Kelvin Li099bb8c2015-11-24 20:50:12 +00008646template <typename Derived>
8647OMPClause *
8648TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8649 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8650 if (E.isInvalid())
8651 return nullptr;
8652 return getDerived().RebuildOMPNumTeamsClause(
8653 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8654}
8655
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008656template <typename Derived>
8657OMPClause *
8658TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8659 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8660 if (E.isInvalid())
8661 return nullptr;
8662 return getDerived().RebuildOMPThreadLimitClause(
8663 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8664}
8665
Alexey Bataeva0569352015-12-01 10:17:31 +00008666template <typename Derived>
8667OMPClause *
8668TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8669 ExprResult E = getDerived().TransformExpr(C->getPriority());
8670 if (E.isInvalid())
8671 return nullptr;
8672 return getDerived().RebuildOMPPriorityClause(
8673 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8674}
8675
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008676template <typename Derived>
8677OMPClause *
8678TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8679 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8680 if (E.isInvalid())
8681 return nullptr;
8682 return getDerived().RebuildOMPGrainsizeClause(
8683 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8684}
8685
Alexey Bataev382967a2015-12-08 12:06:20 +00008686template <typename Derived>
8687OMPClause *
8688TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8689 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8690 if (E.isInvalid())
8691 return nullptr;
8692 return getDerived().RebuildOMPNumTasksClause(
8693 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8694}
8695
Alexey Bataev28c75412015-12-15 08:19:24 +00008696template <typename Derived>
8697OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8698 ExprResult E = getDerived().TransformExpr(C->getHint());
8699 if (E.isInvalid())
8700 return nullptr;
8701 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8702 C->getLParenLoc(), C->getLocEnd());
8703}
8704
Carlo Bertollib4adf552016-01-15 18:50:31 +00008705template <typename Derived>
8706OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8707 OMPDistScheduleClause *C) {
8708 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8709 if (E.isInvalid())
8710 return nullptr;
8711 return getDerived().RebuildOMPDistScheduleClause(
8712 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8713 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8714}
8715
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008716template <typename Derived>
8717OMPClause *
8718TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8719 return C;
8720}
8721
Samuel Antao661c0902016-05-26 17:39:58 +00008722template <typename Derived>
8723OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8724 llvm::SmallVector<Expr *, 16> Vars;
8725 Vars.reserve(C->varlist_size());
8726 for (auto *VE : C->varlists()) {
8727 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8728 if (EVar.isInvalid())
8729 return 0;
8730 Vars.push_back(EVar.get());
8731 }
8732 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8733 C->getLParenLoc(), C->getLocEnd());
8734}
8735
Samuel Antaoec172c62016-05-26 17:49:04 +00008736template <typename Derived>
8737OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8738 llvm::SmallVector<Expr *, 16> Vars;
8739 Vars.reserve(C->varlist_size());
8740 for (auto *VE : C->varlists()) {
8741 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8742 if (EVar.isInvalid())
8743 return 0;
8744 Vars.push_back(EVar.get());
8745 }
8746 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8747 C->getLParenLoc(), C->getLocEnd());
8748}
8749
Carlo Bertolli2404b172016-07-13 15:37:16 +00008750template <typename Derived>
8751OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8752 OMPUseDevicePtrClause *C) {
8753 llvm::SmallVector<Expr *, 16> Vars;
8754 Vars.reserve(C->varlist_size());
8755 for (auto *VE : C->varlists()) {
8756 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8757 if (EVar.isInvalid())
8758 return nullptr;
8759 Vars.push_back(EVar.get());
8760 }
8761 return getDerived().RebuildOMPUseDevicePtrClause(
8762 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8763}
8764
Carlo Bertolli70594e92016-07-13 17:16:49 +00008765template <typename Derived>
8766OMPClause *
8767TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8768 llvm::SmallVector<Expr *, 16> Vars;
8769 Vars.reserve(C->varlist_size());
8770 for (auto *VE : C->varlists()) {
8771 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8772 if (EVar.isInvalid())
8773 return nullptr;
8774 Vars.push_back(EVar.get());
8775 }
8776 return getDerived().RebuildOMPIsDevicePtrClause(
8777 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8778}
8779
Douglas Gregorebe10102009-08-20 07:17:43 +00008780//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008781// Expression transformation
8782//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008785TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008786 if (!E->isTypeDependent())
8787 return E;
8788
8789 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8790 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008791}
Mike Stump11289f42009-09-09 15:08:12 +00008792
8793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008795TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008796 NestedNameSpecifierLoc QualifierLoc;
8797 if (E->getQualifierLoc()) {
8798 QualifierLoc
8799 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8800 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008801 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008802 }
John McCallce546572009-12-08 09:08:17 +00008803
8804 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008805 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8806 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008807 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008809
John McCall815039a2010-08-17 21:27:17 +00008810 DeclarationNameInfo NameInfo = E->getNameInfo();
8811 if (NameInfo.getName()) {
8812 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8813 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008814 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008815 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008816
8817 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008818 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008819 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008820 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008821 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008822
8823 // Mark it referenced in the new context regardless.
8824 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008825 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008826
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008827 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008828 }
John McCallce546572009-12-08 09:08:17 +00008829
Craig Topperc3ec1492014-05-26 06:22:03 +00008830 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008831 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008832 TemplateArgs = &TransArgs;
8833 TransArgs.setLAngleLoc(E->getLAngleLoc());
8834 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008835 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8836 E->getNumTemplateArgs(),
8837 TransArgs))
8838 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008839 }
8840
Chad Rosier1dcde962012-08-08 18:46:20 +00008841 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008842 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008843}
Mike Stump11289f42009-09-09 15:08:12 +00008844
Douglas Gregora16548e2009-08-11 05:31:07 +00008845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008847TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008848 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008849}
Mike Stump11289f42009-09-09 15:08:12 +00008850
Douglas Gregora16548e2009-08-11 05:31:07 +00008851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008853TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008854 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008855}
Mike Stump11289f42009-09-09 15:08:12 +00008856
Douglas Gregora16548e2009-08-11 05:31:07 +00008857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008859TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008860 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008861}
Mike Stump11289f42009-09-09 15:08:12 +00008862
Douglas Gregora16548e2009-08-11 05:31:07 +00008863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008865TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008866 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008867}
Mike Stump11289f42009-09-09 15:08:12 +00008868
Douglas Gregora16548e2009-08-11 05:31:07 +00008869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008871TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008872 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008873}
8874
8875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008876ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008877TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008878 if (FunctionDecl *FD = E->getDirectCallee())
8879 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008880 return SemaRef.MaybeBindToTemporary(E);
8881}
8882
8883template<typename Derived>
8884ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008885TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8886 ExprResult ControllingExpr =
8887 getDerived().TransformExpr(E->getControllingExpr());
8888 if (ControllingExpr.isInvalid())
8889 return ExprError();
8890
Chris Lattner01cf8db2011-07-20 06:58:45 +00008891 SmallVector<Expr *, 4> AssocExprs;
8892 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008893 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8894 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8895 if (TS) {
8896 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8897 if (!AssocType)
8898 return ExprError();
8899 AssocTypes.push_back(AssocType);
8900 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008901 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008902 }
8903
8904 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8905 if (AssocExpr.isInvalid())
8906 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008907 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008908 }
8909
8910 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8911 E->getDefaultLoc(),
8912 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008913 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008914 AssocTypes,
8915 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008916}
8917
8918template<typename Derived>
8919ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008920TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008921 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008922 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008924
Douglas Gregora16548e2009-08-11 05:31:07 +00008925 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008926 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008927
John McCallb268a282010-08-23 23:25:46 +00008928 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008929 E->getRParen());
8930}
8931
Richard Smithdb2630f2012-10-21 03:28:35 +00008932/// \brief The operand of a unary address-of operator has special rules: it's
8933/// allowed to refer to a non-static member of a class even if there's no 'this'
8934/// object available.
8935template<typename Derived>
8936ExprResult
8937TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8938 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008939 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008940 else
8941 return getDerived().TransformExpr(E);
8942}
8943
Mike Stump11289f42009-09-09 15:08:12 +00008944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008946TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008947 ExprResult SubExpr;
8948 if (E->getOpcode() == UO_AddrOf)
8949 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8950 else
8951 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008952 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008953 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008954
Douglas Gregora16548e2009-08-11 05:31:07 +00008955 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008956 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008957
Douglas Gregora16548e2009-08-11 05:31:07 +00008958 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8959 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008960 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008961}
Mike Stump11289f42009-09-09 15:08:12 +00008962
Douglas Gregora16548e2009-08-11 05:31:07 +00008963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008964ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008965TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8966 // Transform the type.
8967 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8968 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008969 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008970
Douglas Gregor882211c2010-04-28 22:16:22 +00008971 // Transform all of the components into components similar to what the
8972 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008973 // FIXME: It would be slightly more efficient in the non-dependent case to
8974 // just map FieldDecls, rather than requiring the rebuilder to look for
8975 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008976 // template code that we don't care.
8977 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008978 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008979 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008980 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008981 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008982 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008983 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008984 Comp.LocStart = ON.getSourceRange().getBegin();
8985 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008986 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008987 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008988 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008989 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008990 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008991 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008992
Douglas Gregor882211c2010-04-28 22:16:22 +00008993 ExprChanged = ExprChanged || Index.get() != FromIndex;
8994 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008995 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008996 break;
8997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008998
James Y Knight7281c352015-12-29 22:31:18 +00008999 case OffsetOfNode::Field:
9000 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009001 Comp.isBrackets = false;
9002 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009003 if (!Comp.U.IdentInfo)
9004 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009005
Douglas Gregor882211c2010-04-28 22:16:22 +00009006 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009007
James Y Knight7281c352015-12-29 22:31:18 +00009008 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009009 // Will be recomputed during the rebuild.
9010 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009011 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009012
Douglas Gregor882211c2010-04-28 22:16:22 +00009013 Components.push_back(Comp);
9014 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009015
Douglas Gregor882211c2010-04-28 22:16:22 +00009016 // If nothing changed, retain the existing expression.
9017 if (!getDerived().AlwaysRebuild() &&
9018 Type == E->getTypeSourceInfo() &&
9019 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009020 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009021
Douglas Gregor882211c2010-04-28 22:16:22 +00009022 // Build a new offsetof expression.
9023 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009024 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009025}
9026
9027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009028ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009029TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009030 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009031 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009032 return E;
John McCall8d69a212010-11-15 23:31:06 +00009033}
9034
9035template<typename Derived>
9036ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009037TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9038 return E;
9039}
9040
9041template<typename Derived>
9042ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009043TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009044 // Rebuild the syntactic form. The original syntactic form has
9045 // opaque-value expressions in it, so strip those away and rebuild
9046 // the result. This is a really awful way of doing this, but the
9047 // better solution (rebuilding the semantic expressions and
9048 // rebinding OVEs as necessary) doesn't work; we'd need
9049 // TreeTransform to not strip away implicit conversions.
9050 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9051 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009052 if (result.isInvalid()) return ExprError();
9053
9054 // If that gives us a pseudo-object result back, the pseudo-object
9055 // expression must have been an lvalue-to-rvalue conversion which we
9056 // should reapply.
9057 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009058 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009059
9060 return result;
9061}
9062
9063template<typename Derived>
9064ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009065TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9066 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009067 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009068 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009069
John McCallbcd03502009-12-07 02:54:59 +00009070 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009071 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009073
John McCall4c98fd82009-11-04 07:28:41 +00009074 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009075 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009076
Peter Collingbournee190dee2011-03-11 19:24:49 +00009077 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9078 E->getKind(),
9079 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009080 }
Mike Stump11289f42009-09-09 15:08:12 +00009081
Eli Friedmane4f22df2012-02-29 04:03:55 +00009082 // C++0x [expr.sizeof]p1:
9083 // The operand is either an expression, which is an unevaluated operand
9084 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009085 EnterExpressionEvaluationContext Unevaluated(
9086 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9087 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009088
Reid Kleckner32506ed2014-06-12 23:03:48 +00009089 // Try to recover if we have something like sizeof(T::X) where X is a type.
9090 // Notably, there must be *exactly* one set of parens if X is a type.
9091 TypeSourceInfo *RecoveryTSI = nullptr;
9092 ExprResult SubExpr;
9093 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9094 if (auto *DRE =
9095 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9096 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9097 PE, DRE, false, &RecoveryTSI);
9098 else
9099 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9100
9101 if (RecoveryTSI) {
9102 return getDerived().RebuildUnaryExprOrTypeTrait(
9103 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9104 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009106
Eli Friedmane4f22df2012-02-29 04:03:55 +00009107 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009108 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009109
Peter Collingbournee190dee2011-03-11 19:24:49 +00009110 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9111 E->getOperatorLoc(),
9112 E->getKind(),
9113 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009114}
Mike Stump11289f42009-09-09 15:08:12 +00009115
Douglas Gregora16548e2009-08-11 05:31:07 +00009116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009118TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009119 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009120 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009122
John McCalldadc5752010-08-24 06:29:42 +00009123 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009126
9127
Douglas Gregora16548e2009-08-11 05:31:07 +00009128 if (!getDerived().AlwaysRebuild() &&
9129 LHS.get() == E->getLHS() &&
9130 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009131 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009132
John McCallb268a282010-08-23 23:25:46 +00009133 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009134 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009135 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009136 E->getRBracketLoc());
9137}
Mike Stump11289f42009-09-09 15:08:12 +00009138
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009139template <typename Derived>
9140ExprResult
9141TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9142 ExprResult Base = getDerived().TransformExpr(E->getBase());
9143 if (Base.isInvalid())
9144 return ExprError();
9145
9146 ExprResult LowerBound;
9147 if (E->getLowerBound()) {
9148 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9149 if (LowerBound.isInvalid())
9150 return ExprError();
9151 }
9152
9153 ExprResult Length;
9154 if (E->getLength()) {
9155 Length = getDerived().TransformExpr(E->getLength());
9156 if (Length.isInvalid())
9157 return ExprError();
9158 }
9159
9160 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9161 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9162 return E;
9163
9164 return getDerived().RebuildOMPArraySectionExpr(
9165 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9166 Length.get(), E->getRBracketLoc());
9167}
9168
Mike Stump11289f42009-09-09 15:08:12 +00009169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009171TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009172 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009173 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009174 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009175 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009176
9177 // Transform arguments.
9178 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009179 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009180 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009181 &ArgChanged))
9182 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009183
Douglas Gregora16548e2009-08-11 05:31:07 +00009184 if (!getDerived().AlwaysRebuild() &&
9185 Callee.get() == E->getCallee() &&
9186 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009187 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009188
Douglas Gregora16548e2009-08-11 05:31:07 +00009189 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009190 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009191 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009192 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009193 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009194 E->getRParenLoc());
9195}
Mike Stump11289f42009-09-09 15:08:12 +00009196
9197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009199TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009200 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009201 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009203
Douglas Gregorea972d32011-02-28 21:54:11 +00009204 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009205 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009206 QualifierLoc
9207 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009208
Douglas Gregorea972d32011-02-28 21:54:11 +00009209 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009210 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009211 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009212 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009213
Eli Friedman2cfcef62009-12-04 06:40:45 +00009214 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009215 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9216 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009217 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009218 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009219
John McCall16df1e52010-03-30 21:47:33 +00009220 NamedDecl *FoundDecl = E->getFoundDecl();
9221 if (FoundDecl == E->getMemberDecl()) {
9222 FoundDecl = Member;
9223 } else {
9224 FoundDecl = cast_or_null<NamedDecl>(
9225 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9226 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009227 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009228 }
9229
Douglas Gregora16548e2009-08-11 05:31:07 +00009230 if (!getDerived().AlwaysRebuild() &&
9231 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009232 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009233 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009234 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009235 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009236
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009237 // Mark it referenced in the new context regardless.
9238 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009239 SemaRef.MarkMemberReferenced(E);
9240
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009241 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009242 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009243
John McCall6b51f282009-11-23 01:53:49 +00009244 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009245 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009246 TransArgs.setLAngleLoc(E->getLAngleLoc());
9247 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009248 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9249 E->getNumTemplateArgs(),
9250 TransArgs))
9251 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009252 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009253
Douglas Gregora16548e2009-08-11 05:31:07 +00009254 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009255 SourceLocation FakeOperatorLoc =
9256 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009257
John McCall38836f02010-01-15 08:34:02 +00009258 // FIXME: to do this check properly, we will need to preserve the
9259 // first-qualifier-in-scope here, just in case we had a dependent
9260 // base (and therefore couldn't do the check) and a
9261 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009262 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009263 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9264 if (MemberNameInfo.getName()) {
9265 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9266 if (!MemberNameInfo.getName())
9267 return ExprError();
9268 }
John McCall38836f02010-01-15 08:34:02 +00009269
John McCallb268a282010-08-23 23:25:46 +00009270 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009272 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009273 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009274 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009275 Member,
John McCall16df1e52010-03-30 21:47:33 +00009276 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009277 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009278 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009279 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009280}
Mike Stump11289f42009-09-09 15:08:12 +00009281
Douglas Gregora16548e2009-08-11 05:31:07 +00009282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009284TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009285 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009286 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009288
John McCalldadc5752010-08-24 06:29:42 +00009289 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009290 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009292
Douglas Gregora16548e2009-08-11 05:31:07 +00009293 if (!getDerived().AlwaysRebuild() &&
9294 LHS.get() == E->getLHS() &&
9295 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009296 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009297
Lang Hames5de91cc2012-10-02 04:45:10 +00009298 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009299 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009300
Douglas Gregora16548e2009-08-11 05:31:07 +00009301 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009302 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009303}
9304
Mike Stump11289f42009-09-09 15:08:12 +00009305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009306ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009307TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009308 CompoundAssignOperator *E) {
9309 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009310}
Mike Stump11289f42009-09-09 15:08:12 +00009311
Douglas Gregora16548e2009-08-11 05:31:07 +00009312template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009313ExprResult TreeTransform<Derived>::
9314TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9315 // Just rebuild the common and RHS expressions and see whether we
9316 // get any changes.
9317
9318 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9319 if (commonExpr.isInvalid())
9320 return ExprError();
9321
9322 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9323 if (rhs.isInvalid())
9324 return ExprError();
9325
9326 if (!getDerived().AlwaysRebuild() &&
9327 commonExpr.get() == e->getCommon() &&
9328 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009329 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009330
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009331 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009332 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009333 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009334 e->getColonLoc(),
9335 rhs.get());
9336}
9337
9338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009340TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009341 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009342 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009343 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009344
John McCalldadc5752010-08-24 06:29:42 +00009345 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009346 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009348
John McCalldadc5752010-08-24 06:29:42 +00009349 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009350 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009352
Douglas Gregora16548e2009-08-11 05:31:07 +00009353 if (!getDerived().AlwaysRebuild() &&
9354 Cond.get() == E->getCond() &&
9355 LHS.get() == E->getLHS() &&
9356 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009357 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009358
John McCallb268a282010-08-23 23:25:46 +00009359 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009360 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009361 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009362 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009363 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009364}
Mike Stump11289f42009-09-09 15:08:12 +00009365
9366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009367ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009368TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009369 // Implicit casts are eliminated during transformation, since they
9370 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009371 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009372}
Mike Stump11289f42009-09-09 15:08:12 +00009373
Douglas Gregora16548e2009-08-11 05:31:07 +00009374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009376TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009377 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9378 if (!Type)
9379 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009380
John McCalldadc5752010-08-24 06:29:42 +00009381 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009382 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009383 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009384 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009385
Douglas Gregora16548e2009-08-11 05:31:07 +00009386 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009387 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009388 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009389 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009390
John McCall97513962010-01-15 18:39:57 +00009391 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009392 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009393 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009394 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009395}
Mike Stump11289f42009-09-09 15:08:12 +00009396
Douglas Gregora16548e2009-08-11 05:31:07 +00009397template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009398ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009399TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009400 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9401 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9402 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009404
John McCalldadc5752010-08-24 06:29:42 +00009405 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009406 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009408
Douglas Gregora16548e2009-08-11 05:31:07 +00009409 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009410 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009411 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009412 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009413
John McCall5d7aa7f2010-01-19 22:33:45 +00009414 // Note: the expression type doesn't necessarily match the
9415 // type-as-written, but that's okay, because it should always be
9416 // derivable from the initializer.
9417
John McCalle15bbff2010-01-18 19:35:47 +00009418 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00009419 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00009420 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009421}
Mike Stump11289f42009-09-09 15:08:12 +00009422
Douglas Gregora16548e2009-08-11 05:31:07 +00009423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009425TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009426 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009427 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009428 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009429
Douglas Gregora16548e2009-08-11 05:31:07 +00009430 if (!getDerived().AlwaysRebuild() &&
9431 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009432 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009433
Douglas Gregora16548e2009-08-11 05:31:07 +00009434 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009435 SourceLocation FakeOperatorLoc =
9436 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00009437 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009438 E->getAccessorLoc(),
9439 E->getAccessor());
9440}
Mike Stump11289f42009-09-09 15:08:12 +00009441
Douglas Gregora16548e2009-08-11 05:31:07 +00009442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009443ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009444TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009445 if (InitListExpr *Syntactic = E->getSyntacticForm())
9446 E = Syntactic;
9447
Douglas Gregora16548e2009-08-11 05:31:07 +00009448 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009449
Benjamin Kramerf0623432012-08-23 22:51:59 +00009450 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009451 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009452 Inits, &InitChanged))
9453 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009454
Richard Smith520449d2015-02-05 06:15:50 +00009455 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9456 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9457 // in some cases. We can't reuse it in general, because the syntactic and
9458 // semantic forms are linked, and we can't know that semantic form will
9459 // match even if the syntactic form does.
9460 }
Mike Stump11289f42009-09-09 15:08:12 +00009461
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009462 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00009463 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00009464}
Mike Stump11289f42009-09-09 15:08:12 +00009465
Douglas Gregora16548e2009-08-11 05:31:07 +00009466template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009467ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009468TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009469 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009470
Douglas Gregorebe10102009-08-20 07:17:43 +00009471 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009472 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009473 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009474 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009475
Douglas Gregorebe10102009-08-20 07:17:43 +00009476 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009477 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009478 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009479 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9480 if (D.isFieldDesignator()) {
9481 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9482 D.getDotLoc(),
9483 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009484 if (D.getField()) {
9485 FieldDecl *Field = cast_or_null<FieldDecl>(
9486 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9487 if (Field != D.getField())
9488 // Rebuild the expression when the transformed FieldDecl is
9489 // different to the already assigned FieldDecl.
9490 ExprChanged = true;
9491 } else {
9492 // Ensure that the designator expression is rebuilt when there isn't
9493 // a resolved FieldDecl in the designator as we don't want to assign
9494 // a FieldDecl to a pattern designator that will be instantiated again.
9495 ExprChanged = true;
9496 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009497 continue;
9498 }
Mike Stump11289f42009-09-09 15:08:12 +00009499
David Majnemerf7e36092016-06-23 00:15:04 +00009500 if (D.isArrayDesignator()) {
9501 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009502 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009504
David Majnemerf7e36092016-06-23 00:15:04 +00009505 Desig.AddDesignator(
9506 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009507
David Majnemerf7e36092016-06-23 00:15:04 +00009508 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009509 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009510 continue;
9511 }
Mike Stump11289f42009-09-09 15:08:12 +00009512
David Majnemerf7e36092016-06-23 00:15:04 +00009513 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009514 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009515 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009516 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009518
David Majnemerf7e36092016-06-23 00:15:04 +00009519 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009520 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009521 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009522
9523 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009524 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009525 D.getLBracketLoc(),
9526 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009527
David Majnemerf7e36092016-06-23 00:15:04 +00009528 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9529 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009530
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009531 ArrayExprs.push_back(Start.get());
9532 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009533 }
Mike Stump11289f42009-09-09 15:08:12 +00009534
Douglas Gregora16548e2009-08-11 05:31:07 +00009535 if (!getDerived().AlwaysRebuild() &&
9536 Init.get() == E->getInit() &&
9537 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009538 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009539
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009540 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009541 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009542 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009543}
Mike Stump11289f42009-09-09 15:08:12 +00009544
Yunzhong Gaocb779302015-06-10 00:27:52 +00009545// Seems that if TransformInitListExpr() only works on the syntactic form of an
9546// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9547template<typename Derived>
9548ExprResult
9549TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9550 DesignatedInitUpdateExpr *E) {
9551 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9552 "initializer");
9553 return ExprError();
9554}
9555
9556template<typename Derived>
9557ExprResult
9558TreeTransform<Derived>::TransformNoInitExpr(
9559 NoInitExpr *E) {
9560 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9561 return ExprError();
9562}
9563
Douglas Gregora16548e2009-08-11 05:31:07 +00009564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009565ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009566TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9567 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9568 return ExprError();
9569}
9570
9571template<typename Derived>
9572ExprResult
9573TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9574 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9575 return ExprError();
9576}
9577
9578template<typename Derived>
9579ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009580TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009581 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009582 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009583
Douglas Gregor3da3c062009-10-28 00:29:27 +00009584 // FIXME: Will we ever have proper type location here? Will we actually
9585 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009586 QualType T = getDerived().TransformType(E->getType());
9587 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009589
Douglas Gregora16548e2009-08-11 05:31:07 +00009590 if (!getDerived().AlwaysRebuild() &&
9591 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009592 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009593
Douglas Gregora16548e2009-08-11 05:31:07 +00009594 return getDerived().RebuildImplicitValueInitExpr(T);
9595}
Mike Stump11289f42009-09-09 15:08:12 +00009596
Douglas Gregora16548e2009-08-11 05:31:07 +00009597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009598ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009599TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009600 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9601 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009603
John McCalldadc5752010-08-24 06:29:42 +00009604 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009605 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009607
Douglas Gregora16548e2009-08-11 05:31:07 +00009608 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009609 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009610 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009611 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009612
John McCallb268a282010-08-23 23:25:46 +00009613 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009614 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009615}
9616
9617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009619TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009620 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009621 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009622 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9623 &ArgumentChanged))
9624 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009625
Douglas Gregora16548e2009-08-11 05:31:07 +00009626 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009627 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009628 E->getRParenLoc());
9629}
Mike Stump11289f42009-09-09 15:08:12 +00009630
Douglas Gregora16548e2009-08-11 05:31:07 +00009631/// \brief Transform an address-of-label expression.
9632///
9633/// By default, the transformation of an address-of-label expression always
9634/// rebuilds the expression, so that the label identifier can be resolved to
9635/// the corresponding label statement by semantic analysis.
9636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009638TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009639 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9640 E->getLabel());
9641 if (!LD)
9642 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009643
Douglas Gregora16548e2009-08-11 05:31:07 +00009644 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009645 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009646}
Mike Stump11289f42009-09-09 15:08:12 +00009647
9648template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009650TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009651 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009652 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009653 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009654 if (SubStmt.isInvalid()) {
9655 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009656 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009657 }
Mike Stump11289f42009-09-09 15:08:12 +00009658
Douglas Gregora16548e2009-08-11 05:31:07 +00009659 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009660 SubStmt.get() == E->getSubStmt()) {
9661 // Calling this an 'error' is unintuitive, but it does the right thing.
9662 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009663 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009664 }
Mike Stump11289f42009-09-09 15:08:12 +00009665
9666 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009667 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009668 E->getRParenLoc());
9669}
Mike Stump11289f42009-09-09 15:08:12 +00009670
Douglas Gregora16548e2009-08-11 05:31:07 +00009671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009673TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009674 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009675 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009677
John McCalldadc5752010-08-24 06:29:42 +00009678 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009679 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009681
John McCalldadc5752010-08-24 06:29:42 +00009682 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009684 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009685
Douglas Gregora16548e2009-08-11 05:31:07 +00009686 if (!getDerived().AlwaysRebuild() &&
9687 Cond.get() == E->getCond() &&
9688 LHS.get() == E->getLHS() &&
9689 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009690 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009691
Douglas Gregora16548e2009-08-11 05:31:07 +00009692 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009693 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009694 E->getRParenLoc());
9695}
Mike Stump11289f42009-09-09 15:08:12 +00009696
Douglas Gregora16548e2009-08-11 05:31:07 +00009697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009699TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009700 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009701}
9702
9703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009704ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009705TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009706 switch (E->getOperator()) {
9707 case OO_New:
9708 case OO_Delete:
9709 case OO_Array_New:
9710 case OO_Array_Delete:
9711 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009712
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009713 case OO_Call: {
9714 // This is a call to an object's operator().
9715 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9716
9717 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009718 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009719 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009720 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009721
9722 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009723 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9724 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009725
9726 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009727 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009728 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009729 Args))
9730 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009731
John McCallb268a282010-08-23 23:25:46 +00009732 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009733 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009734 E->getLocEnd());
9735 }
9736
9737#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9738 case OO_##Name:
9739#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9740#include "clang/Basic/OperatorKinds.def"
9741 case OO_Subscript:
9742 // Handled below.
9743 break;
9744
9745 case OO_Conditional:
9746 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009747
9748 case OO_None:
9749 case NUM_OVERLOADED_OPERATORS:
9750 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009751 }
9752
John McCalldadc5752010-08-24 06:29:42 +00009753 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009754 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009755 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009756
Richard Smithdb2630f2012-10-21 03:28:35 +00009757 ExprResult First;
9758 if (E->getOperator() == OO_Amp)
9759 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9760 else
9761 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009762 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009763 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009764
John McCalldadc5752010-08-24 06:29:42 +00009765 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009766 if (E->getNumArgs() == 2) {
9767 Second = getDerived().TransformExpr(E->getArg(1));
9768 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009769 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009770 }
Mike Stump11289f42009-09-09 15:08:12 +00009771
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 if (!getDerived().AlwaysRebuild() &&
9773 Callee.get() == E->getCallee() &&
9774 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009775 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009776 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009777
Lang Hames5de91cc2012-10-02 04:45:10 +00009778 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009779 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009780
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9782 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009783 Callee.get(),
9784 First.get(),
9785 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009786}
Mike Stump11289f42009-09-09 15:08:12 +00009787
Douglas Gregora16548e2009-08-11 05:31:07 +00009788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009789ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009790TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9791 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009792}
Mike Stump11289f42009-09-09 15:08:12 +00009793
Douglas Gregora16548e2009-08-11 05:31:07 +00009794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009795ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009796TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9797 // Transform the callee.
9798 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9799 if (Callee.isInvalid())
9800 return ExprError();
9801
9802 // Transform exec config.
9803 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9804 if (EC.isInvalid())
9805 return ExprError();
9806
9807 // Transform arguments.
9808 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009809 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009810 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009811 &ArgChanged))
9812 return ExprError();
9813
9814 if (!getDerived().AlwaysRebuild() &&
9815 Callee.get() == E->getCallee() &&
9816 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009817 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009818
9819 // FIXME: Wrong source location information for the '('.
9820 SourceLocation FakeLParenLoc
9821 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9822 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009823 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009824 E->getRParenLoc(), EC.get());
9825}
9826
9827template<typename Derived>
9828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009829TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009830 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9831 if (!Type)
9832 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009833
John McCalldadc5752010-08-24 06:29:42 +00009834 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009835 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009836 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009838
Douglas Gregora16548e2009-08-11 05:31:07 +00009839 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009840 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009841 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009842 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009843 return getDerived().RebuildCXXNamedCastExpr(
9844 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9845 Type, E->getAngleBrackets().getEnd(),
9846 // FIXME. this should be '(' location
9847 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009848}
Mike Stump11289f42009-09-09 15:08:12 +00009849
Douglas Gregora16548e2009-08-11 05:31:07 +00009850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009852TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9853 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009854}
Mike Stump11289f42009-09-09 15:08:12 +00009855
9856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009858TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9859 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009860}
9861
Douglas Gregora16548e2009-08-11 05:31:07 +00009862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009863ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009864TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009865 CXXReinterpretCastExpr *E) {
9866 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009867}
Mike Stump11289f42009-09-09 15:08:12 +00009868
Douglas Gregora16548e2009-08-11 05:31:07 +00009869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009871TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9872 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009873}
Mike Stump11289f42009-09-09 15:08:12 +00009874
Douglas Gregora16548e2009-08-11 05:31:07 +00009875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009876ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009877TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009878 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009879 TypeSourceInfo *Type =
9880 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009881 if (!Type)
9882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009883
John McCalldadc5752010-08-24 06:29:42 +00009884 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009885 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009886 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009887 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009888
Douglas Gregora16548e2009-08-11 05:31:07 +00009889 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009890 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009891 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009892 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009893
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009894 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009895 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009896 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009897 E->getRParenLoc());
9898}
Mike Stump11289f42009-09-09 15:08:12 +00009899
Douglas Gregora16548e2009-08-11 05:31:07 +00009900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009901ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009902TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009903 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009904 TypeSourceInfo *TInfo
9905 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9906 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009908
Douglas Gregora16548e2009-08-11 05:31:07 +00009909 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009910 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009911 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009912
Douglas Gregor9da64192010-04-26 22:37:10 +00009913 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9914 E->getLocStart(),
9915 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009916 E->getLocEnd());
9917 }
Mike Stump11289f42009-09-09 15:08:12 +00009918
Eli Friedman456f0182012-01-20 01:26:23 +00009919 // We don't know whether the subexpression is potentially evaluated until
9920 // after we perform semantic analysis. We speculatively assume it is
9921 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009922 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +00009923 EnterExpressionEvaluationContext Unevaluated(
9924 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9925 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009926
John McCalldadc5752010-08-24 06:29:42 +00009927 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009928 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009930
Douglas Gregora16548e2009-08-11 05:31:07 +00009931 if (!getDerived().AlwaysRebuild() &&
9932 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009933 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009934
Douglas Gregor9da64192010-04-26 22:37:10 +00009935 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9936 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009937 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009938 E->getLocEnd());
9939}
9940
9941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009942ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009943TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9944 if (E->isTypeOperand()) {
9945 TypeSourceInfo *TInfo
9946 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9947 if (!TInfo)
9948 return ExprError();
9949
9950 if (!getDerived().AlwaysRebuild() &&
9951 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009952 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009953
Douglas Gregor69735112011-03-06 17:40:41 +00009954 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009955 E->getLocStart(),
9956 TInfo,
9957 E->getLocEnd());
9958 }
9959
Faisal Valid143a0c2017-04-01 21:30:49 +00009960 EnterExpressionEvaluationContext Unevaluated(
9961 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +00009962
9963 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9964 if (SubExpr.isInvalid())
9965 return ExprError();
9966
9967 if (!getDerived().AlwaysRebuild() &&
9968 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009969 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009970
9971 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9972 E->getLocStart(),
9973 SubExpr.get(),
9974 E->getLocEnd());
9975}
9976
9977template<typename Derived>
9978ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009979TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009980 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009981}
Mike Stump11289f42009-09-09 15:08:12 +00009982
Douglas Gregora16548e2009-08-11 05:31:07 +00009983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009984ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009985TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009986 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009987 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009988}
Mike Stump11289f42009-09-09 15:08:12 +00009989
Douglas Gregora16548e2009-08-11 05:31:07 +00009990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009991ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009992TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009993 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009994
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009995 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9996 // Make sure that we capture 'this'.
9997 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009998 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009999 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010000
Douglas Gregorb15af892010-01-07 23:12:05 +000010001 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010002}
Mike Stump11289f42009-09-09 15:08:12 +000010003
Douglas Gregora16548e2009-08-11 05:31:07 +000010004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010006TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010007 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010008 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010010
Douglas Gregora16548e2009-08-11 05:31:07 +000010011 if (!getDerived().AlwaysRebuild() &&
10012 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010013 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010014
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010015 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10016 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010017}
Mike Stump11289f42009-09-09 15:08:12 +000010018
Douglas Gregora16548e2009-08-11 05:31:07 +000010019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010021TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +000010022 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010023 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
10024 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010025 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010027
Chandler Carruth794da4c2010-02-08 06:42:49 +000010028 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010029 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010030 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010031
Douglas Gregor033f6752009-12-23 23:03:06 +000010032 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010033}
Mike Stump11289f42009-09-09 15:08:12 +000010034
Douglas Gregora16548e2009-08-11 05:31:07 +000010035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010036ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010037TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
10038 FieldDecl *Field
10039 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
10040 E->getField()));
10041 if (!Field)
10042 return ExprError();
10043
10044 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010045 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010046
10047 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10048}
10049
10050template<typename Derived>
10051ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010052TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10053 CXXScalarValueInitExpr *E) {
10054 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10055 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010056 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010057
Douglas Gregora16548e2009-08-11 05:31:07 +000010058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010059 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010060 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010061
Chad Rosier1dcde962012-08-08 18:46:20 +000010062 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010063 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010064 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010065}
Mike Stump11289f42009-09-09 15:08:12 +000010066
Douglas Gregora16548e2009-08-11 05:31:07 +000010067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010069TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010070 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010071 TypeSourceInfo *AllocTypeInfo =
10072 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010073 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010075
Douglas Gregora16548e2009-08-11 05:31:07 +000010076 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010077 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010078 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010080
Douglas Gregora16548e2009-08-11 05:31:07 +000010081 // Transform the placement arguments (if any).
10082 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010083 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010084 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010085 E->getNumPlacementArgs(), true,
10086 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010087 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010088
Sebastian Redl6047f072012-02-16 12:22:20 +000010089 // Transform the initializer (if any).
10090 Expr *OldInit = E->getInitializer();
10091 ExprResult NewInit;
10092 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010093 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010094 if (NewInit.isInvalid())
10095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010096
Sebastian Redl6047f072012-02-16 12:22:20 +000010097 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010098 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010099 if (E->getOperatorNew()) {
10100 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010101 getDerived().TransformDecl(E->getLocStart(),
10102 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010103 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010104 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010105 }
10106
Craig Topperc3ec1492014-05-26 06:22:03 +000010107 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010108 if (E->getOperatorDelete()) {
10109 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010110 getDerived().TransformDecl(E->getLocStart(),
10111 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010112 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010113 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010114 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010115
Douglas Gregora16548e2009-08-11 05:31:07 +000010116 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010117 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010118 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010119 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010120 OperatorNew == E->getOperatorNew() &&
10121 OperatorDelete == E->getOperatorDelete() &&
10122 !ArgumentChanged) {
10123 // Mark any declarations we need as referenced.
10124 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010125 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010126 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010127 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010128 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010129
Sebastian Redl6047f072012-02-16 12:22:20 +000010130 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010131 QualType ElementType
10132 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10133 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10134 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10135 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +000010136 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010137 }
10138 }
10139 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010140
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010141 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010142 }
Mike Stump11289f42009-09-09 15:08:12 +000010143
Douglas Gregor0744ef62010-09-07 21:49:58 +000010144 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010145 if (!ArraySize.get()) {
10146 // If no array size was specified, but the new expression was
10147 // instantiated with an array type (e.g., "new T" where T is
10148 // instantiated with "int[4]"), extract the outer bound from the
10149 // array type as our array size. We do this with constant and
10150 // dependently-sized array types.
10151 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10152 if (!ArrayT) {
10153 // Do nothing
10154 } else if (const ConstantArrayType *ConsArrayT
10155 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010156 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10157 SemaRef.Context.getSizeType(),
10158 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010159 AllocType = ConsArrayT->getElementType();
10160 } else if (const DependentSizedArrayType *DepArrayT
10161 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10162 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010163 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010164 AllocType = DepArrayT->getElementType();
10165 }
10166 }
10167 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010168
Douglas Gregora16548e2009-08-11 05:31:07 +000010169 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10170 E->isGlobalNew(),
10171 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010172 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010173 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +000010174 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010175 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +000010176 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +000010177 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +000010178 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010179 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010180}
Mike Stump11289f42009-09-09 15:08:12 +000010181
Douglas Gregora16548e2009-08-11 05:31:07 +000010182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010184TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010185 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010186 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010188
Douglas Gregord2d9da02010-02-26 00:38:10 +000010189 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010190 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010191 if (E->getOperatorDelete()) {
10192 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010193 getDerived().TransformDecl(E->getLocStart(),
10194 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010195 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010196 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010197 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010198
Douglas Gregora16548e2009-08-11 05:31:07 +000010199 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010200 Operand.get() == E->getArgument() &&
10201 OperatorDelete == E->getOperatorDelete()) {
10202 // Mark any declarations we need as referenced.
10203 // FIXME: instantiation-specific.
10204 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010205 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010206
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010207 if (!E->getArgument()->isTypeDependent()) {
10208 QualType Destroyed = SemaRef.Context.getBaseElementType(
10209 E->getDestroyedType());
10210 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10211 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010212 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010213 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010214 }
10215 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010216
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010217 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010218 }
Mike Stump11289f42009-09-09 15:08:12 +000010219
Douglas Gregora16548e2009-08-11 05:31:07 +000010220 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10221 E->isGlobalDelete(),
10222 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +000010223 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010224}
Mike Stump11289f42009-09-09 15:08:12 +000010225
Douglas Gregora16548e2009-08-11 05:31:07 +000010226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010227ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010228TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010229 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010230 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010231 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010232 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010233
John McCallba7bf592010-08-24 05:47:05 +000010234 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010235 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010236 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010237 E->getOperatorLoc(),
10238 E->isArrow()? tok::arrow : tok::period,
10239 ObjectTypePtr,
10240 MayBePseudoDestructor);
10241 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010242 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010243
John McCallba7bf592010-08-24 05:47:05 +000010244 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010245 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10246 if (QualifierLoc) {
10247 QualifierLoc
10248 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10249 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010250 return ExprError();
10251 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010252 CXXScopeSpec SS;
10253 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010254
Douglas Gregor678f90d2010-02-25 01:56:36 +000010255 PseudoDestructorTypeStorage Destroyed;
10256 if (E->getDestroyedTypeInfo()) {
10257 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010258 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010259 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010260 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010261 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010262 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010263 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010264 // We aren't likely to be able to resolve the identifier down to a type
10265 // now anyway, so just retain the identifier.
10266 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10267 E->getDestroyedTypeLoc());
10268 } else {
10269 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010270 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010271 *E->getDestroyedTypeIdentifier(),
10272 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010273 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010274 SS, ObjectTypePtr,
10275 false);
10276 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010277 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010278
Douglas Gregor678f90d2010-02-25 01:56:36 +000010279 Destroyed
10280 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10281 E->getDestroyedTypeLoc());
10282 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010283
Craig Topperc3ec1492014-05-26 06:22:03 +000010284 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010285 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010286 CXXScopeSpec EmptySS;
10287 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010288 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010289 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010290 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010291 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010292
John McCallb268a282010-08-23 23:25:46 +000010293 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010294 E->getOperatorLoc(),
10295 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010296 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010297 ScopeTypeInfo,
10298 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010299 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010300 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010301}
Mike Stump11289f42009-09-09 15:08:12 +000010302
Richard Smith151c4562016-12-20 21:35:28 +000010303template <typename Derived>
10304bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10305 bool RequiresADL,
10306 LookupResult &R) {
10307 // Transform all the decls.
10308 bool AllEmptyPacks = true;
10309 for (auto *OldD : Old->decls()) {
10310 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10311 if (!InstD) {
10312 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10313 // This can happen because of dependent hiding.
10314 if (isa<UsingShadowDecl>(OldD))
10315 continue;
10316 else {
10317 R.clear();
10318 return true;
10319 }
10320 }
10321
10322 // Expand using pack declarations.
10323 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10324 ArrayRef<NamedDecl*> Decls = SingleDecl;
10325 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10326 Decls = UPD->expansions();
10327
10328 // Expand using declarations.
10329 for (auto *D : Decls) {
10330 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10331 for (auto *SD : UD->shadows())
10332 R.addDecl(SD);
10333 } else {
10334 R.addDecl(D);
10335 }
10336 }
10337
10338 AllEmptyPacks &= Decls.empty();
10339 };
10340
10341 // C++ [temp.res]/8.4.2:
10342 // The program is ill-formed, no diagnostic required, if [...] lookup for
10343 // a name in the template definition found a using-declaration, but the
10344 // lookup in the corresponding scope in the instantiation odoes not find
10345 // any declarations because the using-declaration was a pack expansion and
10346 // the corresponding pack is empty
10347 if (AllEmptyPacks && !RequiresADL) {
10348 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10349 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10350 return true;
10351 }
10352
10353 // Resolve a kind, but don't do any further analysis. If it's
10354 // ambiguous, the callee needs to deal with it.
10355 R.resolveKind();
10356 return false;
10357}
10358
Douglas Gregorad8a3362009-09-04 17:36:40 +000010359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010360ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010361TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010362 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010363 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10364 Sema::LookupOrdinaryName);
10365
Richard Smith151c4562016-12-20 21:35:28 +000010366 // Transform the declaration set.
10367 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10368 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010369
10370 // Rebuild the nested-name qualifier, if present.
10371 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010372 if (Old->getQualifierLoc()) {
10373 NestedNameSpecifierLoc QualifierLoc
10374 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10375 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010376 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010377
Douglas Gregor0da1d432011-02-28 20:01:57 +000010378 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010379 }
10380
Douglas Gregor9262f472010-04-27 18:19:34 +000010381 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010382 CXXRecordDecl *NamingClass
10383 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10384 Old->getNameLoc(),
10385 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010386 if (!NamingClass) {
10387 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010388 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010389 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010390
Douglas Gregorda7be082010-04-27 16:10:10 +000010391 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010392 }
10393
Abramo Bagnara7945c982012-01-27 09:46:47 +000010394 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10395
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010396 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010397 // it's a normal declaration name or member reference.
10398 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10399 NamedDecl *D = R.getAsSingle<NamedDecl>();
10400 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10401 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10402 // give a good diagnostic.
10403 if (D && D->isCXXInstanceMember()) {
10404 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10405 /*TemplateArgs=*/nullptr,
10406 /*Scope=*/nullptr);
10407 }
10408
John McCalle66edc12009-11-24 19:00:30 +000010409 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010410 }
John McCalle66edc12009-11-24 19:00:30 +000010411
10412 // If we have template arguments, rebuild them, then rebuild the
10413 // templateid expression.
10414 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010415 if (Old->hasExplicitTemplateArgs() &&
10416 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010417 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010418 TransArgs)) {
10419 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010420 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010421 }
John McCalle66edc12009-11-24 19:00:30 +000010422
Abramo Bagnara7945c982012-01-27 09:46:47 +000010423 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010424 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010425}
Mike Stump11289f42009-09-09 15:08:12 +000010426
Douglas Gregora16548e2009-08-11 05:31:07 +000010427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010428ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010429TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10430 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010431 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010432 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10433 TypeSourceInfo *From = E->getArg(I);
10434 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010435 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010436 TypeLocBuilder TLB;
10437 TLB.reserve(FromTL.getFullDataSize());
10438 QualType To = getDerived().TransformType(TLB, FromTL);
10439 if (To.isNull())
10440 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010441
Douglas Gregor29c42f22012-02-24 07:38:34 +000010442 if (To == From->getType())
10443 Args.push_back(From);
10444 else {
10445 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10446 ArgChanged = true;
10447 }
10448 continue;
10449 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010450
Douglas Gregor29c42f22012-02-24 07:38:34 +000010451 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010452
Douglas Gregor29c42f22012-02-24 07:38:34 +000010453 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010454 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010455 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10456 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10457 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010458
Douglas Gregor29c42f22012-02-24 07:38:34 +000010459 // Determine whether the set of unexpanded parameter packs can and should
10460 // be expanded.
10461 bool Expand = true;
10462 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010463 Optional<unsigned> OrigNumExpansions =
10464 ExpansionTL.getTypePtr()->getNumExpansions();
10465 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010466 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10467 PatternTL.getSourceRange(),
10468 Unexpanded,
10469 Expand, RetainExpansion,
10470 NumExpansions))
10471 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010472
Douglas Gregor29c42f22012-02-24 07:38:34 +000010473 if (!Expand) {
10474 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010475 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010476 // expansion.
10477 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010478
Douglas Gregor29c42f22012-02-24 07:38:34 +000010479 TypeLocBuilder TLB;
10480 TLB.reserve(From->getTypeLoc().getFullDataSize());
10481
10482 QualType To = getDerived().TransformType(TLB, PatternTL);
10483 if (To.isNull())
10484 return ExprError();
10485
Chad Rosier1dcde962012-08-08 18:46:20 +000010486 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010487 PatternTL.getSourceRange(),
10488 ExpansionTL.getEllipsisLoc(),
10489 NumExpansions);
10490 if (To.isNull())
10491 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010492
Douglas Gregor29c42f22012-02-24 07:38:34 +000010493 PackExpansionTypeLoc ToExpansionTL
10494 = TLB.push<PackExpansionTypeLoc>(To);
10495 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10496 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10497 continue;
10498 }
10499
10500 // Expand the pack expansion by substituting for each argument in the
10501 // pack(s).
10502 for (unsigned I = 0; I != *NumExpansions; ++I) {
10503 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10504 TypeLocBuilder TLB;
10505 TLB.reserve(PatternTL.getFullDataSize());
10506 QualType To = getDerived().TransformType(TLB, PatternTL);
10507 if (To.isNull())
10508 return ExprError();
10509
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010510 if (To->containsUnexpandedParameterPack()) {
10511 To = getDerived().RebuildPackExpansionType(To,
10512 PatternTL.getSourceRange(),
10513 ExpansionTL.getEllipsisLoc(),
10514 NumExpansions);
10515 if (To.isNull())
10516 return ExprError();
10517
10518 PackExpansionTypeLoc ToExpansionTL
10519 = TLB.push<PackExpansionTypeLoc>(To);
10520 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10521 }
10522
Douglas Gregor29c42f22012-02-24 07:38:34 +000010523 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10524 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010525
Douglas Gregor29c42f22012-02-24 07:38:34 +000010526 if (!RetainExpansion)
10527 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010528
Douglas Gregor29c42f22012-02-24 07:38:34 +000010529 // If we're supposed to retain a pack expansion, do so by temporarily
10530 // forgetting the partially-substituted parameter pack.
10531 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10532
10533 TypeLocBuilder TLB;
10534 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010535
Douglas Gregor29c42f22012-02-24 07:38:34 +000010536 QualType To = getDerived().TransformType(TLB, PatternTL);
10537 if (To.isNull())
10538 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010539
10540 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010541 PatternTL.getSourceRange(),
10542 ExpansionTL.getEllipsisLoc(),
10543 NumExpansions);
10544 if (To.isNull())
10545 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010546
Douglas Gregor29c42f22012-02-24 07:38:34 +000010547 PackExpansionTypeLoc ToExpansionTL
10548 = TLB.push<PackExpansionTypeLoc>(To);
10549 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10550 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10551 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010552
Douglas Gregor29c42f22012-02-24 07:38:34 +000010553 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010554 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010555
10556 return getDerived().RebuildTypeTrait(E->getTrait(),
10557 E->getLocStart(),
10558 Args,
10559 E->getLocEnd());
10560}
10561
10562template<typename Derived>
10563ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010564TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10565 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10566 if (!T)
10567 return ExprError();
10568
10569 if (!getDerived().AlwaysRebuild() &&
10570 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010571 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010572
10573 ExprResult SubExpr;
10574 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010575 EnterExpressionEvaluationContext Unevaluated(
10576 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010577 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10578 if (SubExpr.isInvalid())
10579 return ExprError();
10580
10581 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010582 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010583 }
10584
10585 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10586 E->getLocStart(),
10587 T,
10588 SubExpr.get(),
10589 E->getLocEnd());
10590}
10591
10592template<typename Derived>
10593ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010594TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10595 ExprResult SubExpr;
10596 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010597 EnterExpressionEvaluationContext Unevaluated(
10598 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010599 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10600 if (SubExpr.isInvalid())
10601 return ExprError();
10602
10603 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010604 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010605 }
10606
10607 return getDerived().RebuildExpressionTrait(
10608 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10609}
10610
Reid Kleckner32506ed2014-06-12 23:03:48 +000010611template <typename Derived>
10612ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10613 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10614 TypeSourceInfo **RecoveryTSI) {
10615 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10616 DRE, AddrTaken, RecoveryTSI);
10617
10618 // Propagate both errors and recovered types, which return ExprEmpty.
10619 if (!NewDRE.isUsable())
10620 return NewDRE;
10621
10622 // We got an expr, wrap it up in parens.
10623 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10624 return PE;
10625 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10626 PE->getRParen());
10627}
10628
10629template <typename Derived>
10630ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10631 DependentScopeDeclRefExpr *E) {
10632 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10633 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010634}
10635
10636template<typename Derived>
10637ExprResult
10638TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10639 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010640 bool IsAddressOfOperand,
10641 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010642 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010643 NestedNameSpecifierLoc QualifierLoc
10644 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10645 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010646 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010647 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010648
John McCall31f82722010-11-12 08:19:04 +000010649 // TODO: If this is a conversion-function-id, verify that the
10650 // destination type name (if present) resolves the same way after
10651 // instantiation as it did in the local scope.
10652
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010653 DeclarationNameInfo NameInfo
10654 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10655 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010657
John McCalle66edc12009-11-24 19:00:30 +000010658 if (!E->hasExplicitTemplateArgs()) {
10659 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010660 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010661 // Note: it is sufficient to compare the Name component of NameInfo:
10662 // if name has not changed, DNLoc has not changed either.
10663 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010664 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010665
Reid Kleckner32506ed2014-06-12 23:03:48 +000010666 return getDerived().RebuildDependentScopeDeclRefExpr(
10667 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10668 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010669 }
John McCall6b51f282009-11-23 01:53:49 +000010670
10671 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010672 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10673 E->getNumTemplateArgs(),
10674 TransArgs))
10675 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010676
Reid Kleckner32506ed2014-06-12 23:03:48 +000010677 return getDerived().RebuildDependentScopeDeclRefExpr(
10678 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10679 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010680}
10681
10682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010684TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010685 // CXXConstructExprs other than for list-initialization and
10686 // CXXTemporaryObjectExpr are always implicit, so when we have
10687 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010688 if ((E->getNumArgs() == 1 ||
10689 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010690 (!getDerived().DropCallArgument(E->getArg(0))) &&
10691 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010692 return getDerived().TransformExpr(E->getArg(0));
10693
Douglas Gregora16548e2009-08-11 05:31:07 +000010694 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10695
10696 QualType T = getDerived().TransformType(E->getType());
10697 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010698 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010699
10700 CXXConstructorDecl *Constructor
10701 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010702 getDerived().TransformDecl(E->getLocStart(),
10703 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010704 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010706
Douglas Gregora16548e2009-08-11 05:31:07 +000010707 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010708 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010709 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010710 &ArgumentChanged))
10711 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010712
Douglas Gregora16548e2009-08-11 05:31:07 +000010713 if (!getDerived().AlwaysRebuild() &&
10714 T == E->getType() &&
10715 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010716 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010717 // Mark the constructor as referenced.
10718 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010719 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010720 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010721 }
Mike Stump11289f42009-09-09 15:08:12 +000010722
Douglas Gregordb121ba2009-12-14 16:27:04 +000010723 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010724 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010725 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010726 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010727 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010728 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010729 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010730 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010731 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010732}
Mike Stump11289f42009-09-09 15:08:12 +000010733
Richard Smith5179eb72016-06-28 19:03:57 +000010734template<typename Derived>
10735ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10736 CXXInheritedCtorInitExpr *E) {
10737 QualType T = getDerived().TransformType(E->getType());
10738 if (T.isNull())
10739 return ExprError();
10740
10741 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10742 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10743 if (!Constructor)
10744 return ExprError();
10745
10746 if (!getDerived().AlwaysRebuild() &&
10747 T == E->getType() &&
10748 Constructor == E->getConstructor()) {
10749 // Mark the constructor as referenced.
10750 // FIXME: Instantiation-specific
10751 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10752 return E;
10753 }
10754
10755 return getDerived().RebuildCXXInheritedCtorInitExpr(
10756 T, E->getLocation(), Constructor,
10757 E->constructsVBase(), E->inheritedFromVBase());
10758}
10759
Douglas Gregora16548e2009-08-11 05:31:07 +000010760/// \brief Transform a C++ temporary-binding expression.
10761///
Douglas Gregor363b1512009-12-24 18:51:59 +000010762/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10763/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010765ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010766TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010767 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010768}
Mike Stump11289f42009-09-09 15:08:12 +000010769
John McCall5d413782010-12-06 08:20:24 +000010770/// \brief Transform a C++ expression that contains cleanups that should
10771/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010772///
John McCall5d413782010-12-06 08:20:24 +000010773/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010774/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010776ExprResult
John McCall5d413782010-12-06 08:20:24 +000010777TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010778 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010779}
Mike Stump11289f42009-09-09 15:08:12 +000010780
Douglas Gregora16548e2009-08-11 05:31:07 +000010781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010782ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010783TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010784 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010785 TypeSourceInfo *T =
10786 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010787 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010789
Douglas Gregora16548e2009-08-11 05:31:07 +000010790 CXXConstructorDecl *Constructor
10791 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010792 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010793 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010794 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010796
Douglas Gregora16548e2009-08-11 05:31:07 +000010797 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010798 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010799 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010800 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010801 &ArgumentChanged))
10802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010803
Douglas Gregora16548e2009-08-11 05:31:07 +000010804 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010805 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010806 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010807 !ArgumentChanged) {
10808 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010809 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010810 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010811 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010812
Richard Smithd59b8322012-12-19 01:39:02 +000010813 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010814 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10815 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010816 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010817 E->getLocEnd());
10818}
Mike Stump11289f42009-09-09 15:08:12 +000010819
Douglas Gregora16548e2009-08-11 05:31:07 +000010820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010821ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010822TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010823 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010824 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010825 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010826 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10827 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010828 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010829 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010830 CEnd = E->capture_end();
10831 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010832 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010833 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010834 EnterExpressionEvaluationContext EEEC(
10835 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010836 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10837 C->getCapturedVar()->getInit(),
10838 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010839
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010840 if (NewExprInitResult.isInvalid())
10841 return ExprError();
10842 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010843
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010844 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010845 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010846 getSema().buildLambdaInitCaptureInitialization(
10847 C->getLocation(), OldVD->getType()->isReferenceType(),
10848 OldVD->getIdentifier(),
10849 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010850 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010851 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10852 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010853 }
10854
Faisal Vali2cba1332013-10-23 06:44:28 +000010855 // Transform the template parameters, and add them to the current
10856 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010857 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010858 E->getTemplateParameterList());
10859
Richard Smith01014ce2014-11-20 23:53:14 +000010860 // Transform the type of the original lambda's call operator.
10861 // The transformation MUST be done in the CurrentInstantiationScope since
10862 // it introduces a mapping of the original to the newly created
10863 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010864 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010865 {
10866 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10867 FunctionProtoTypeLoc OldCallOpFPTL =
10868 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010869
10870 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010871 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010872 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010873 QualType NewCallOpType = TransformFunctionProtoType(
10874 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010875 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10876 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10877 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010878 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010879 if (NewCallOpType.isNull())
10880 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010881 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10882 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010883 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010884
Richard Smithc38498f2015-04-27 21:27:54 +000010885 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10886 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10887 LSI->GLTemplateParameterList = TPL;
10888
Eli Friedmand564afb2012-09-19 01:18:11 +000010889 // Create the local class that will describe the lambda.
10890 CXXRecordDecl *Class
10891 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010892 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010893 /*KnownDependent=*/false,
10894 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010895 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10896
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010897 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010898 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10899 Class, E->getIntroducerRange(), NewCallOpTSI,
10900 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010901 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10902 E->getCallOperator()->isConstexpr());
10903
Faisal Vali2cba1332013-10-23 06:44:28 +000010904 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010905
Akira Hatanaka402818462016-12-16 21:16:57 +000010906 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10907 I != NumParams; ++I) {
10908 auto *P = NewCallOperator->getParamDecl(I);
10909 if (P->hasUninstantiatedDefaultArg()) {
10910 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000010911 getSema(),
10912 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000010913 ExprResult R = getDerived().TransformExpr(
10914 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10915 P->setDefaultArg(R.get());
10916 }
10917 }
10918
Faisal Vali2cba1332013-10-23 06:44:28 +000010919 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010920 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010921
Douglas Gregorb4328232012-02-14 00:00:48 +000010922 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010923 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010924 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010925
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010926 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010927 getSema().buildLambdaScope(LSI, NewCallOperator,
10928 E->getIntroducerRange(),
10929 E->getCaptureDefault(),
10930 E->getCaptureDefaultLoc(),
10931 E->hasExplicitParameters(),
10932 E->hasExplicitResultType(),
10933 E->isMutable());
10934
10935 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010936
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010937 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010938 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010939 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010940 CEnd = E->capture_end();
10941 C != CEnd; ++C) {
10942 // When we hit the first implicit capture, tell Sema that we've finished
10943 // the list of explicit captures.
10944 if (!FinishedExplicitCaptures && C->isImplicit()) {
10945 getSema().finishLambdaExplicitCaptures(LSI);
10946 FinishedExplicitCaptures = true;
10947 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010948
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010949 // Capturing 'this' is trivial.
10950 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010951 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10952 /*BuildAndDiagnose*/ true, nullptr,
10953 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010954 continue;
10955 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010956 // Captured expression will be recaptured during captured variables
10957 // rebuilding.
10958 if (C->capturesVLAType())
10959 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010960
Richard Smithba71c082013-05-16 06:20:58 +000010961 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010962 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010963 InitCaptureInfoTy InitExprTypePair =
10964 InitCaptureExprsAndTypes[C - E->capture_begin()];
10965 ExprResult Init = InitExprTypePair.first;
10966 QualType InitQualType = InitExprTypePair.second;
10967 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010968 Invalid = true;
10969 continue;
10970 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010971 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010972 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010973 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10974 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010975 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010976 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010977 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010978 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010979 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010980 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010981 continue;
10982 }
10983
10984 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10985
Douglas Gregor3e308b12012-02-14 19:27:52 +000010986 // Determine the capture kind for Sema.
10987 Sema::TryCaptureKind Kind
10988 = C->isImplicit()? Sema::TryCapture_Implicit
10989 : C->getCaptureKind() == LCK_ByCopy
10990 ? Sema::TryCapture_ExplicitByVal
10991 : Sema::TryCapture_ExplicitByRef;
10992 SourceLocation EllipsisLoc;
10993 if (C->isPackExpansion()) {
10994 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10995 bool ShouldExpand = false;
10996 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010997 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010998 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10999 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011000 Unexpanded,
11001 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011002 NumExpansions)) {
11003 Invalid = true;
11004 continue;
11005 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011006
Douglas Gregor3e308b12012-02-14 19:27:52 +000011007 if (ShouldExpand) {
11008 // The transform has determined that we should perform an expansion;
11009 // transform and capture each of the arguments.
11010 // expansion of the pattern. Do so.
11011 VarDecl *Pack = C->getCapturedVar();
11012 for (unsigned I = 0; I != *NumExpansions; ++I) {
11013 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11014 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011015 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011016 Pack));
11017 if (!CapturedVar) {
11018 Invalid = true;
11019 continue;
11020 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011021
Douglas Gregor3e308b12012-02-14 19:27:52 +000011022 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011023 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11024 }
Richard Smith9467be42014-06-06 17:33:35 +000011025
11026 // FIXME: Retain a pack expansion if RetainExpansion is true.
11027
Douglas Gregor3e308b12012-02-14 19:27:52 +000011028 continue;
11029 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011030
Douglas Gregor3e308b12012-02-14 19:27:52 +000011031 EllipsisLoc = C->getEllipsisLoc();
11032 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011033
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011034 // Transform the captured variable.
11035 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011036 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011037 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011038 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011039 Invalid = true;
11040 continue;
11041 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011042
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011043 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011044 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11045 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011046 }
11047 if (!FinishedExplicitCaptures)
11048 getSema().finishLambdaExplicitCaptures(LSI);
11049
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011050 // Enter a new evaluation context to insulate the lambda from any
11051 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011052 getSema().PushExpressionEvaluationContext(
11053 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011054
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011055 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011056 StmtResult Body =
11057 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11058
11059 // ActOnLambda* will pop the function scope for us.
11060 FuncScopeCleanup.disable();
11061
Douglas Gregorb4328232012-02-14 00:00:48 +000011062 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011063 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000011064 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011065 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011066 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011067 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011068
Richard Smithc38498f2015-04-27 21:27:54 +000011069 // Copy the LSI before ActOnFinishFunctionBody removes it.
11070 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11071 // the call operator.
11072 auto LSICopy = *LSI;
11073 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11074 /*IsInstantiation*/ true);
11075 SavedContext.pop();
11076
11077 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11078 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011079}
11080
11081template<typename Derived>
11082ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011083TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011084 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011085 TypeSourceInfo *T =
11086 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011087 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011088 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011089
Douglas Gregora16548e2009-08-11 05:31:07 +000011090 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011091 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011092 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000011093 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011094 &ArgumentChanged))
11095 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011096
Douglas Gregora16548e2009-08-11 05:31:07 +000011097 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011098 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011099 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011100 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011101
Douglas Gregora16548e2009-08-11 05:31:07 +000011102 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000011103 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000011104 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011105 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000011106 E->getRParenLoc());
11107}
Mike Stump11289f42009-09-09 15:08:12 +000011108
Douglas Gregora16548e2009-08-11 05:31:07 +000011109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011110ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011111TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011112 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011113 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011114 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011115 Expr *OldBase;
11116 QualType BaseType;
11117 QualType ObjectType;
11118 if (!E->isImplicitAccess()) {
11119 OldBase = E->getBase();
11120 Base = getDerived().TransformExpr(OldBase);
11121 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011123
John McCall2d74de92009-12-01 22:10:20 +000011124 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011125 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011126 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011127 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011128 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011129 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011130 ObjectTy,
11131 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011132 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011133 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011134
John McCallba7bf592010-08-24 05:47:05 +000011135 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011136 BaseType = ((Expr*) Base.get())->getType();
11137 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011138 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011139 BaseType = getDerived().TransformType(E->getBaseType());
11140 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11141 }
Mike Stump11289f42009-09-09 15:08:12 +000011142
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011143 // Transform the first part of the nested-name-specifier that qualifies
11144 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011145 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011146 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011147 E->getFirstQualifierFoundInScope(),
11148 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011149
Douglas Gregore16af532011-02-28 18:50:33 +000011150 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011151 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011152 QualifierLoc
11153 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11154 ObjectType,
11155 FirstQualifierInScope);
11156 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011157 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011158 }
Mike Stump11289f42009-09-09 15:08:12 +000011159
Abramo Bagnara7945c982012-01-27 09:46:47 +000011160 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11161
John McCall31f82722010-11-12 08:19:04 +000011162 // TODO: If this is a conversion-function-id, verify that the
11163 // destination type name (if present) resolves the same way after
11164 // instantiation as it did in the local scope.
11165
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011166 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011167 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011168 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011170
John McCall2d74de92009-12-01 22:10:20 +000011171 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011172 // This is a reference to a member without an explicitly-specified
11173 // template argument list. Optimize for this common case.
11174 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011175 Base.get() == OldBase &&
11176 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011177 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011178 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011179 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011180 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011181
John McCallb268a282010-08-23 23:25:46 +000011182 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011183 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011184 E->isArrow(),
11185 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011186 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011187 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011188 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011189 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011190 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011191 }
11192
John McCall6b51f282009-11-23 01:53:49 +000011193 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011194 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11195 E->getNumTemplateArgs(),
11196 TransArgs))
11197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011198
John McCallb268a282010-08-23 23:25:46 +000011199 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011200 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011201 E->isArrow(),
11202 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011203 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011204 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011205 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011206 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011207 &TransArgs);
11208}
11209
11210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011212TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011213 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011214 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011215 QualType BaseType;
11216 if (!Old->isImplicitAccess()) {
11217 Base = getDerived().TransformExpr(Old->getBase());
11218 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011219 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011220 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011221 Old->isArrow());
11222 if (Base.isInvalid())
11223 return ExprError();
11224 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011225 } else {
11226 BaseType = getDerived().TransformType(Old->getBaseType());
11227 }
John McCall10eae182009-11-30 22:42:35 +000011228
Douglas Gregor0da1d432011-02-28 20:01:57 +000011229 NestedNameSpecifierLoc QualifierLoc;
11230 if (Old->getQualifierLoc()) {
11231 QualifierLoc
11232 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11233 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011234 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011235 }
11236
Abramo Bagnara7945c982012-01-27 09:46:47 +000011237 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11238
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011239 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011240 Sema::LookupOrdinaryName);
11241
Richard Smith151c4562016-12-20 21:35:28 +000011242 // Transform the declaration set.
11243 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11244 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011245
Douglas Gregor9262f472010-04-27 18:19:34 +000011246 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011247 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011248 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011249 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011250 Old->getMemberLoc(),
11251 Old->getNamingClass()));
11252 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011253 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011254
Douglas Gregorda7be082010-04-27 16:10:10 +000011255 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011256 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011257
John McCall10eae182009-11-30 22:42:35 +000011258 TemplateArgumentListInfo TransArgs;
11259 if (Old->hasExplicitTemplateArgs()) {
11260 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11261 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011262 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11263 Old->getNumTemplateArgs(),
11264 TransArgs))
11265 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011266 }
John McCall38836f02010-01-15 08:34:02 +000011267
11268 // FIXME: to do this check properly, we will need to preserve the
11269 // first-qualifier-in-scope here, just in case we had a dependent
11270 // base (and therefore couldn't do the check) and a
11271 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011272 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011273
John McCallb268a282010-08-23 23:25:46 +000011274 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011275 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011276 Old->getOperatorLoc(),
11277 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011278 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011279 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011280 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011281 R,
11282 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011283 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011284}
11285
11286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011287ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011288TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011289 EnterExpressionEvaluationContext Unevaluated(
11290 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011291 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11292 if (SubExpr.isInvalid())
11293 return ExprError();
11294
11295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011296 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011297
11298 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11299}
11300
11301template<typename Derived>
11302ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011303TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011304 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11305 if (Pattern.isInvalid())
11306 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011307
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011308 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011309 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011310
Douglas Gregorb8840002011-01-14 21:20:45 +000011311 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11312 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011313}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011314
11315template<typename Derived>
11316ExprResult
11317TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11318 // If E is not value-dependent, then nothing will change when we transform it.
11319 // Note: This is an instantiation-centric view.
11320 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011321 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011322
Faisal Valid143a0c2017-04-01 21:30:49 +000011323 EnterExpressionEvaluationContext Unevaluated(
11324 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011325
Richard Smithd784e682015-09-23 21:41:42 +000011326 ArrayRef<TemplateArgument> PackArgs;
11327 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011328
Richard Smithd784e682015-09-23 21:41:42 +000011329 // Find the argument list to transform.
11330 if (E->isPartiallySubstituted()) {
11331 PackArgs = E->getPartialArguments();
11332 } else if (E->isValueDependent()) {
11333 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11334 bool ShouldExpand = false;
11335 bool RetainExpansion = false;
11336 Optional<unsigned> NumExpansions;
11337 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11338 Unexpanded,
11339 ShouldExpand, RetainExpansion,
11340 NumExpansions))
11341 return ExprError();
11342
11343 // If we need to expand the pack, build a template argument from it and
11344 // expand that.
11345 if (ShouldExpand) {
11346 auto *Pack = E->getPack();
11347 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11348 ArgStorage = getSema().Context.getPackExpansionType(
11349 getSema().Context.getTypeDeclType(TTPD), None);
11350 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11351 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11352 } else {
11353 auto *VD = cast<ValueDecl>(Pack);
11354 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11355 VK_RValue, E->getPackLoc());
11356 if (DRE.isInvalid())
11357 return ExprError();
11358 ArgStorage = new (getSema().Context) PackExpansionExpr(
11359 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11360 }
11361 PackArgs = ArgStorage;
11362 }
11363 }
11364
11365 // If we're not expanding the pack, just transform the decl.
11366 if (!PackArgs.size()) {
11367 auto *Pack = cast_or_null<NamedDecl>(
11368 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011369 if (!Pack)
11370 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011371 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11372 E->getPackLoc(),
11373 E->getRParenLoc(), None, None);
11374 }
11375
Richard Smithc5452ed2016-10-19 22:18:42 +000011376 // Try to compute the result without performing a partial substitution.
11377 Optional<unsigned> Result = 0;
11378 for (const TemplateArgument &Arg : PackArgs) {
11379 if (!Arg.isPackExpansion()) {
11380 Result = *Result + 1;
11381 continue;
11382 }
11383
11384 TemplateArgumentLoc ArgLoc;
11385 InventTemplateArgumentLoc(Arg, ArgLoc);
11386
11387 // Find the pattern of the pack expansion.
11388 SourceLocation Ellipsis;
11389 Optional<unsigned> OrigNumExpansions;
11390 TemplateArgumentLoc Pattern =
11391 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11392 OrigNumExpansions);
11393
11394 // Substitute under the pack expansion. Do not expand the pack (yet).
11395 TemplateArgumentLoc OutPattern;
11396 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11397 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11398 /*Uneval*/ true))
11399 return true;
11400
11401 // See if we can determine the number of arguments from the result.
11402 Optional<unsigned> NumExpansions =
11403 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11404 if (!NumExpansions) {
11405 // No: we must be in an alias template expansion, and we're going to need
11406 // to actually expand the packs.
11407 Result = None;
11408 break;
11409 }
11410
11411 Result = *Result + *NumExpansions;
11412 }
11413
11414 // Common case: we could determine the number of expansions without
11415 // substituting.
11416 if (Result)
11417 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11418 E->getPackLoc(),
11419 E->getRParenLoc(), *Result, None);
11420
Richard Smithd784e682015-09-23 21:41:42 +000011421 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11422 E->getPackLoc());
11423 {
11424 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11425 typedef TemplateArgumentLocInventIterator<
11426 Derived, const TemplateArgument*> PackLocIterator;
11427 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11428 PackLocIterator(*this, PackArgs.end()),
11429 TransformedPackArgs, /*Uneval*/true))
11430 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011431 }
11432
Richard Smithc5452ed2016-10-19 22:18:42 +000011433 // Check whether we managed to fully-expand the pack.
11434 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011435 SmallVector<TemplateArgument, 8> Args;
11436 bool PartialSubstitution = false;
11437 for (auto &Loc : TransformedPackArgs.arguments()) {
11438 Args.push_back(Loc.getArgument());
11439 if (Loc.getArgument().isPackExpansion())
11440 PartialSubstitution = true;
11441 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011442
Richard Smithd784e682015-09-23 21:41:42 +000011443 if (PartialSubstitution)
11444 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11445 E->getPackLoc(),
11446 E->getRParenLoc(), None, Args);
11447
11448 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011449 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011450 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011451}
11452
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011453template<typename Derived>
11454ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011455TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11456 SubstNonTypeTemplateParmPackExpr *E) {
11457 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011458 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011459}
11460
11461template<typename Derived>
11462ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011463TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11464 SubstNonTypeTemplateParmExpr *E) {
11465 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011466 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011467}
11468
11469template<typename Derived>
11470ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011471TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11472 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011473 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011474}
11475
11476template<typename Derived>
11477ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011478TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11479 MaterializeTemporaryExpr *E) {
11480 return getDerived().TransformExpr(E->GetTemporaryExpr());
11481}
Chad Rosier1dcde962012-08-08 18:46:20 +000011482
Douglas Gregorfe314812011-06-21 17:03:29 +000011483template<typename Derived>
11484ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011485TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11486 Expr *Pattern = E->getPattern();
11487
11488 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11489 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11490 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11491
11492 // Determine whether the set of unexpanded parameter packs can and should
11493 // be expanded.
11494 bool Expand = true;
11495 bool RetainExpansion = false;
11496 Optional<unsigned> NumExpansions;
11497 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11498 Pattern->getSourceRange(),
11499 Unexpanded,
11500 Expand, RetainExpansion,
11501 NumExpansions))
11502 return true;
11503
11504 if (!Expand) {
11505 // Do not expand any packs here, just transform and rebuild a fold
11506 // expression.
11507 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11508
11509 ExprResult LHS =
11510 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11511 if (LHS.isInvalid())
11512 return true;
11513
11514 ExprResult RHS =
11515 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11516 if (RHS.isInvalid())
11517 return true;
11518
11519 if (!getDerived().AlwaysRebuild() &&
11520 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11521 return E;
11522
11523 return getDerived().RebuildCXXFoldExpr(
11524 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11525 RHS.get(), E->getLocEnd());
11526 }
11527
11528 // The transform has determined that we should perform an elementwise
11529 // expansion of the pattern. Do so.
11530 ExprResult Result = getDerived().TransformExpr(E->getInit());
11531 if (Result.isInvalid())
11532 return true;
11533 bool LeftFold = E->isLeftFold();
11534
11535 // If we're retaining an expansion for a right fold, it is the innermost
11536 // component and takes the init (if any).
11537 if (!LeftFold && RetainExpansion) {
11538 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11539
11540 ExprResult Out = getDerived().TransformExpr(Pattern);
11541 if (Out.isInvalid())
11542 return true;
11543
11544 Result = getDerived().RebuildCXXFoldExpr(
11545 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11546 Result.get(), E->getLocEnd());
11547 if (Result.isInvalid())
11548 return true;
11549 }
11550
11551 for (unsigned I = 0; I != *NumExpansions; ++I) {
11552 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11553 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11554 ExprResult Out = getDerived().TransformExpr(Pattern);
11555 if (Out.isInvalid())
11556 return true;
11557
11558 if (Out.get()->containsUnexpandedParameterPack()) {
11559 // We still have a pack; retain a pack expansion for this slice.
11560 Result = getDerived().RebuildCXXFoldExpr(
11561 E->getLocStart(),
11562 LeftFold ? Result.get() : Out.get(),
11563 E->getOperator(), E->getEllipsisLoc(),
11564 LeftFold ? Out.get() : Result.get(),
11565 E->getLocEnd());
11566 } else if (Result.isUsable()) {
11567 // We've got down to a single element; build a binary operator.
11568 Result = getDerived().RebuildBinaryOperator(
11569 E->getEllipsisLoc(), E->getOperator(),
11570 LeftFold ? Result.get() : Out.get(),
11571 LeftFold ? Out.get() : Result.get());
11572 } else
11573 Result = Out;
11574
11575 if (Result.isInvalid())
11576 return true;
11577 }
11578
11579 // If we're retaining an expansion for a left fold, it is the outermost
11580 // component and takes the complete expansion so far as its init (if any).
11581 if (LeftFold && RetainExpansion) {
11582 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11583
11584 ExprResult Out = getDerived().TransformExpr(Pattern);
11585 if (Out.isInvalid())
11586 return true;
11587
11588 Result = getDerived().RebuildCXXFoldExpr(
11589 E->getLocStart(), Result.get(),
11590 E->getOperator(), E->getEllipsisLoc(),
11591 Out.get(), E->getLocEnd());
11592 if (Result.isInvalid())
11593 return true;
11594 }
11595
11596 // If we had no init and an empty pack, and we're not retaining an expansion,
11597 // then produce a fallback value or error.
11598 if (Result.isUnset())
11599 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11600 E->getOperator());
11601
11602 return Result;
11603}
11604
11605template<typename Derived>
11606ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011607TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11608 CXXStdInitializerListExpr *E) {
11609 return getDerived().TransformExpr(E->getSubExpr());
11610}
11611
11612template<typename Derived>
11613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011614TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011615 return SemaRef.MaybeBindToTemporary(E);
11616}
11617
11618template<typename Derived>
11619ExprResult
11620TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011621 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011622}
11623
11624template<typename Derived>
11625ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011626TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11627 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11628 if (SubExpr.isInvalid())
11629 return ExprError();
11630
11631 if (!getDerived().AlwaysRebuild() &&
11632 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011633 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011634
11635 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011636}
11637
11638template<typename Derived>
11639ExprResult
11640TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11641 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011642 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011643 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011644 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011645 /*IsCall=*/false, Elements, &ArgChanged))
11646 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011647
Ted Kremeneke65b0862012-03-06 20:05:56 +000011648 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11649 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011650
Ted Kremeneke65b0862012-03-06 20:05:56 +000011651 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11652 Elements.data(),
11653 Elements.size());
11654}
11655
11656template<typename Derived>
11657ExprResult
11658TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011659 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011660 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011661 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011662 bool ArgChanged = false;
11663 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11664 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011665
Ted Kremeneke65b0862012-03-06 20:05:56 +000011666 if (OrigElement.isPackExpansion()) {
11667 // This key/value element is a pack expansion.
11668 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11669 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11670 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11671 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11672
11673 // Determine whether the set of unexpanded parameter packs can
11674 // and should be expanded.
11675 bool Expand = true;
11676 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011677 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11678 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011679 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11680 OrigElement.Value->getLocEnd());
11681 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11682 PatternRange,
11683 Unexpanded,
11684 Expand, RetainExpansion,
11685 NumExpansions))
11686 return ExprError();
11687
11688 if (!Expand) {
11689 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011690 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011691 // expansion.
11692 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11693 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11694 if (Key.isInvalid())
11695 return ExprError();
11696
11697 if (Key.get() != OrigElement.Key)
11698 ArgChanged = true;
11699
11700 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11701 if (Value.isInvalid())
11702 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011703
Ted Kremeneke65b0862012-03-06 20:05:56 +000011704 if (Value.get() != OrigElement.Value)
11705 ArgChanged = true;
11706
Chad Rosier1dcde962012-08-08 18:46:20 +000011707 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011708 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11709 };
11710 Elements.push_back(Expansion);
11711 continue;
11712 }
11713
11714 // Record right away that the argument was changed. This needs
11715 // to happen even if the array expands to nothing.
11716 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011717
Ted Kremeneke65b0862012-03-06 20:05:56 +000011718 // The transform has determined that we should perform an elementwise
11719 // expansion of the pattern. Do so.
11720 for (unsigned I = 0; I != *NumExpansions; ++I) {
11721 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11722 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11723 if (Key.isInvalid())
11724 return ExprError();
11725
11726 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11727 if (Value.isInvalid())
11728 return ExprError();
11729
Chad Rosier1dcde962012-08-08 18:46:20 +000011730 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011731 Key.get(), Value.get(), SourceLocation(), NumExpansions
11732 };
11733
11734 // If any unexpanded parameter packs remain, we still have a
11735 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011736 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011737 if (Key.get()->containsUnexpandedParameterPack() ||
11738 Value.get()->containsUnexpandedParameterPack())
11739 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011740
Ted Kremeneke65b0862012-03-06 20:05:56 +000011741 Elements.push_back(Element);
11742 }
11743
Richard Smith9467be42014-06-06 17:33:35 +000011744 // FIXME: Retain a pack expansion if RetainExpansion is true.
11745
Ted Kremeneke65b0862012-03-06 20:05:56 +000011746 // We've finished with this pack expansion.
11747 continue;
11748 }
11749
11750 // Transform and check key.
11751 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11752 if (Key.isInvalid())
11753 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011754
Ted Kremeneke65b0862012-03-06 20:05:56 +000011755 if (Key.get() != OrigElement.Key)
11756 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011757
Ted Kremeneke65b0862012-03-06 20:05:56 +000011758 // Transform and check value.
11759 ExprResult Value
11760 = getDerived().TransformExpr(OrigElement.Value);
11761 if (Value.isInvalid())
11762 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011763
Ted Kremeneke65b0862012-03-06 20:05:56 +000011764 if (Value.get() != OrigElement.Value)
11765 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011766
11767 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011768 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011769 };
11770 Elements.push_back(Element);
11771 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011772
Ted Kremeneke65b0862012-03-06 20:05:56 +000011773 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11774 return SemaRef.MaybeBindToTemporary(E);
11775
11776 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011777 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011778}
11779
Mike Stump11289f42009-09-09 15:08:12 +000011780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011782TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011783 TypeSourceInfo *EncodedTypeInfo
11784 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11785 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011787
Douglas Gregora16548e2009-08-11 05:31:07 +000011788 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011789 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011790 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011791
11792 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011793 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011794 E->getRParenLoc());
11795}
Mike Stump11289f42009-09-09 15:08:12 +000011796
Douglas Gregora16548e2009-08-11 05:31:07 +000011797template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011798ExprResult TreeTransform<Derived>::
11799TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011800 // This is a kind of implicit conversion, and it needs to get dropped
11801 // and recomputed for the same general reasons that ImplicitCastExprs
11802 // do, as well a more specific one: this expression is only valid when
11803 // it appears *immediately* as an argument expression.
11804 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011805}
11806
11807template<typename Derived>
11808ExprResult TreeTransform<Derived>::
11809TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011810 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011811 = getDerived().TransformType(E->getTypeInfoAsWritten());
11812 if (!TSInfo)
11813 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011814
John McCall31168b02011-06-15 23:02:42 +000011815 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011816 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011817 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011818
John McCall31168b02011-06-15 23:02:42 +000011819 if (!getDerived().AlwaysRebuild() &&
11820 TSInfo == E->getTypeInfoAsWritten() &&
11821 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011822 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011823
John McCall31168b02011-06-15 23:02:42 +000011824 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011825 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011826 Result.get());
11827}
11828
Erik Pilkington29099de2016-07-16 00:35:23 +000011829template <typename Derived>
11830ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11831 ObjCAvailabilityCheckExpr *E) {
11832 return E;
11833}
11834
John McCall31168b02011-06-15 23:02:42 +000011835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011837TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011838 // Transform arguments.
11839 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011840 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011841 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011842 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011843 &ArgChanged))
11844 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011845
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011846 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11847 // Class message: transform the receiver type.
11848 TypeSourceInfo *ReceiverTypeInfo
11849 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11850 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011851 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011852
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011853 // If nothing changed, just retain the existing message send.
11854 if (!getDerived().AlwaysRebuild() &&
11855 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011856 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011857
11858 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011859 SmallVector<SourceLocation, 16> SelLocs;
11860 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011861 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11862 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011863 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011864 E->getMethodDecl(),
11865 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011866 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011867 E->getRightLoc());
11868 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011869 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11870 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011871 if (!E->getMethodDecl())
11872 return ExprError();
11873
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011874 // Build a new class message send to 'super'.
11875 SmallVector<SourceLocation, 16> SelLocs;
11876 E->getSelectorLocs(SelLocs);
11877 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11878 E->getSelector(),
11879 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011880 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011881 E->getMethodDecl(),
11882 E->getLeftLoc(),
11883 Args,
11884 E->getRightLoc());
11885 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011886
11887 // Instance message: transform the receiver
11888 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11889 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011890 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011891 = getDerived().TransformExpr(E->getInstanceReceiver());
11892 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011893 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011894
11895 // If nothing changed, just retain the existing message send.
11896 if (!getDerived().AlwaysRebuild() &&
11897 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011898 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011899
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011900 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011901 SmallVector<SourceLocation, 16> SelLocs;
11902 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011903 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011904 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011905 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011906 E->getMethodDecl(),
11907 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011908 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011909 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011910}
11911
Mike Stump11289f42009-09-09 15:08:12 +000011912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011913ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011914TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011915 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011916}
11917
Mike Stump11289f42009-09-09 15:08:12 +000011918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011919ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011920TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011921 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011922}
11923
Mike Stump11289f42009-09-09 15:08:12 +000011924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011926TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011927 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011928 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011929 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011930 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011931
11932 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011933
Douglas Gregord51d90d2010-04-26 20:11:03 +000011934 // If nothing changed, just retain the existing expression.
11935 if (!getDerived().AlwaysRebuild() &&
11936 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011937 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011938
John McCallb268a282010-08-23 23:25:46 +000011939 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011940 E->getLocation(),
11941 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011942}
11943
Mike Stump11289f42009-09-09 15:08:12 +000011944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011946TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011947 // 'super' and types never change. Property never changes. Just
11948 // retain the existing expression.
11949 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011950 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011951
Douglas Gregor9faee212010-04-26 20:47:02 +000011952 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011953 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011954 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011955 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011956
Douglas Gregor9faee212010-04-26 20:47:02 +000011957 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011958
Douglas Gregor9faee212010-04-26 20:47:02 +000011959 // If nothing changed, just retain the existing expression.
11960 if (!getDerived().AlwaysRebuild() &&
11961 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011962 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011963
John McCallb7bd14f2010-12-02 01:19:52 +000011964 if (E->isExplicitProperty())
11965 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11966 E->getExplicitProperty(),
11967 E->getLocation());
11968
11969 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011970 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011971 E->getImplicitPropertyGetter(),
11972 E->getImplicitPropertySetter(),
11973 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011974}
11975
Mike Stump11289f42009-09-09 15:08:12 +000011976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011977ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011978TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11979 // Transform the base expression.
11980 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11981 if (Base.isInvalid())
11982 return ExprError();
11983
11984 // Transform the key expression.
11985 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11986 if (Key.isInvalid())
11987 return ExprError();
11988
11989 // If nothing changed, just retain the existing expression.
11990 if (!getDerived().AlwaysRebuild() &&
11991 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011992 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011993
Chad Rosier1dcde962012-08-08 18:46:20 +000011994 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011995 Base.get(), Key.get(),
11996 E->getAtIndexMethodDecl(),
11997 E->setAtIndexMethodDecl());
11998}
11999
12000template<typename Derived>
12001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012002TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012003 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012004 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012005 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012006 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012007
Douglas Gregord51d90d2010-04-26 20:11:03 +000012008 // If nothing changed, just retain the existing expression.
12009 if (!getDerived().AlwaysRebuild() &&
12010 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012011 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012012
John McCallb268a282010-08-23 23:25:46 +000012013 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012014 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012015 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012016}
12017
Mike Stump11289f42009-09-09 15:08:12 +000012018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012020TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012021 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012022 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012023 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012024 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012025 SubExprs, &ArgumentChanged))
12026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012027
Douglas Gregora16548e2009-08-11 05:31:07 +000012028 if (!getDerived().AlwaysRebuild() &&
12029 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012030 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012031
Douglas Gregora16548e2009-08-11 05:31:07 +000012032 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012033 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012034 E->getRParenLoc());
12035}
12036
Mike Stump11289f42009-09-09 15:08:12 +000012037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012038ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012039TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12040 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12041 if (SrcExpr.isInvalid())
12042 return ExprError();
12043
12044 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12045 if (!Type)
12046 return ExprError();
12047
12048 if (!getDerived().AlwaysRebuild() &&
12049 Type == E->getTypeSourceInfo() &&
12050 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012051 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012052
12053 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12054 SrcExpr.get(), Type,
12055 E->getRParenLoc());
12056}
12057
12058template<typename Derived>
12059ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012060TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012061 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012062
Craig Topperc3ec1492014-05-26 06:22:03 +000012063 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012064 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12065
12066 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012067 blockScope->TheDecl->setBlockMissingReturnType(
12068 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012069
Chris Lattner01cf8db2011-07-20 06:58:45 +000012070 SmallVector<ParmVarDecl*, 4> params;
12071 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012072
John McCallc8e321d2016-03-01 02:09:25 +000012073 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12074
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012075 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012076 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012077 if (getDerived().TransformFunctionTypeParams(
12078 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12079 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12080 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012081 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012082 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012083 }
John McCall490112f2011-02-04 18:33:18 +000012084
Eli Friedman34b49062012-01-26 03:00:14 +000012085 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012086 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012087
John McCallc8e321d2016-03-01 02:09:25 +000012088 auto epi = exprFunctionType->getExtProtoInfo();
12089 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12090
Jordan Rose5c382722013-03-08 21:51:21 +000012091 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012092 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012093 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012094
12095 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012096 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012097 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012098
12099 if (!oldBlock->blockMissingReturnType()) {
12100 blockScope->HasImplicitReturnType = false;
12101 blockScope->ReturnType = exprResultType;
12102 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012103
John McCall3882ace2011-01-05 12:14:39 +000012104 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012105 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012106 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012107 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012108 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012109 }
John McCall3882ace2011-01-05 12:14:39 +000012110
John McCall490112f2011-02-04 18:33:18 +000012111#ifndef NDEBUG
12112 // In builds with assertions, make sure that we captured everything we
12113 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012114 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012115 for (const auto &I : oldBlock->captures()) {
12116 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012117
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012118 // Ignore parameter packs.
12119 if (isa<ParmVarDecl>(oldCapture) &&
12120 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12121 continue;
John McCall490112f2011-02-04 18:33:18 +000012122
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012123 VarDecl *newCapture =
12124 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12125 oldCapture));
12126 assert(blockScope->CaptureMap.count(newCapture));
12127 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012128 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012129 }
12130#endif
12131
12132 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012133 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012134}
12135
Mike Stump11289f42009-09-09 15:08:12 +000012136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012137ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012138TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012139 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012140}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012141
12142template<typename Derived>
12143ExprResult
12144TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012145 QualType RetTy = getDerived().TransformType(E->getType());
12146 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012147 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012148 SubExprs.reserve(E->getNumSubExprs());
12149 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12150 SubExprs, &ArgumentChanged))
12151 return ExprError();
12152
12153 if (!getDerived().AlwaysRebuild() &&
12154 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012155 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012156
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012157 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012158 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012159}
Chad Rosier1dcde962012-08-08 18:46:20 +000012160
Douglas Gregora16548e2009-08-11 05:31:07 +000012161//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012162// Type reconstruction
12163//===----------------------------------------------------------------------===//
12164
Mike Stump11289f42009-09-09 15:08:12 +000012165template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012166QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12167 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012168 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012169 getDerived().getBaseEntity());
12170}
12171
Mike Stump11289f42009-09-09 15:08:12 +000012172template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012173QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12174 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012175 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012176 getDerived().getBaseEntity());
12177}
12178
Mike Stump11289f42009-09-09 15:08:12 +000012179template<typename Derived>
12180QualType
John McCall70dd5f62009-10-30 00:06:24 +000012181TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12182 bool WrittenAsLValue,
12183 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012184 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012185 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012186}
12187
12188template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012189QualType
John McCall70dd5f62009-10-30 00:06:24 +000012190TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12191 QualType ClassType,
12192 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012193 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12194 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012195}
12196
12197template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012198QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12199 const ObjCTypeParamDecl *Decl,
12200 SourceLocation ProtocolLAngleLoc,
12201 ArrayRef<ObjCProtocolDecl *> Protocols,
12202 ArrayRef<SourceLocation> ProtocolLocs,
12203 SourceLocation ProtocolRAngleLoc) {
12204 return SemaRef.BuildObjCTypeParamType(Decl,
12205 ProtocolLAngleLoc, Protocols,
12206 ProtocolLocs, ProtocolRAngleLoc,
12207 /*FailOnError=*/true);
12208}
12209
12210template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012211QualType TreeTransform<Derived>::RebuildObjCObjectType(
12212 QualType BaseType,
12213 SourceLocation Loc,
12214 SourceLocation TypeArgsLAngleLoc,
12215 ArrayRef<TypeSourceInfo *> TypeArgs,
12216 SourceLocation TypeArgsRAngleLoc,
12217 SourceLocation ProtocolLAngleLoc,
12218 ArrayRef<ObjCProtocolDecl *> Protocols,
12219 ArrayRef<SourceLocation> ProtocolLocs,
12220 SourceLocation ProtocolRAngleLoc) {
12221 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12222 TypeArgs, TypeArgsRAngleLoc,
12223 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12224 ProtocolRAngleLoc,
12225 /*FailOnError=*/true);
12226}
12227
12228template<typename Derived>
12229QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12230 QualType PointeeType,
12231 SourceLocation Star) {
12232 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12233}
12234
12235template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012236QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012237TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12238 ArrayType::ArraySizeModifier SizeMod,
12239 const llvm::APInt *Size,
12240 Expr *SizeExpr,
12241 unsigned IndexTypeQuals,
12242 SourceRange BracketsRange) {
12243 if (SizeExpr || !Size)
12244 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12245 IndexTypeQuals, BracketsRange,
12246 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012247
12248 QualType Types[] = {
12249 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12250 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12251 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012252 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012253 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012254 QualType SizeType;
12255 for (unsigned I = 0; I != NumTypes; ++I)
12256 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12257 SizeType = Types[I];
12258 break;
12259 }
Mike Stump11289f42009-09-09 15:08:12 +000012260
Eli Friedman9562f392012-01-25 23:20:27 +000012261 // Note that we can return a VariableArrayType here in the case where
12262 // the element type was a dependent VariableArrayType.
12263 IntegerLiteral *ArraySize
12264 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12265 /*FIXME*/BracketsRange.getBegin());
12266 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012267 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012268 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012269}
Mike Stump11289f42009-09-09 15:08:12 +000012270
Douglas Gregord6ff3322009-08-04 16:50:30 +000012271template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012272QualType
12273TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012274 ArrayType::ArraySizeModifier SizeMod,
12275 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012276 unsigned IndexTypeQuals,
12277 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012278 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012279 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012280}
12281
12282template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012283QualType
Mike Stump11289f42009-09-09 15:08:12 +000012284TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012285 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012286 unsigned IndexTypeQuals,
12287 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012288 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012289 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012290}
Mike Stump11289f42009-09-09 15:08:12 +000012291
Douglas Gregord6ff3322009-08-04 16:50:30 +000012292template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012293QualType
12294TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012295 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012296 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012297 unsigned IndexTypeQuals,
12298 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012299 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012300 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012301 IndexTypeQuals, BracketsRange);
12302}
12303
12304template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012305QualType
12306TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012307 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012308 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012309 unsigned IndexTypeQuals,
12310 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012311 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012312 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012313 IndexTypeQuals, BracketsRange);
12314}
12315
12316template<typename Derived>
12317QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000012318 unsigned NumElements,
12319 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012320 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012321 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012322}
Mike Stump11289f42009-09-09 15:08:12 +000012323
Douglas Gregord6ff3322009-08-04 16:50:30 +000012324template<typename Derived>
12325QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12326 unsigned NumElements,
12327 SourceLocation AttributeLoc) {
12328 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12329 NumElements, true);
12330 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012331 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12332 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012333 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012334}
Mike Stump11289f42009-09-09 15:08:12 +000012335
Douglas Gregord6ff3322009-08-04 16:50:30 +000012336template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012337QualType
12338TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012339 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012340 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012341 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012342}
Mike Stump11289f42009-09-09 15:08:12 +000012343
Douglas Gregord6ff3322009-08-04 16:50:30 +000012344template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012345QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12346 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012347 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012348 const FunctionProtoType::ExtProtoInfo &EPI) {
12349 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012350 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012351 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012352 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012353}
Mike Stump11289f42009-09-09 15:08:12 +000012354
Douglas Gregord6ff3322009-08-04 16:50:30 +000012355template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012356QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12357 return SemaRef.Context.getFunctionNoProtoType(T);
12358}
12359
12360template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012361QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12362 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012363 assert(D && "no decl found");
12364 if (D->isInvalidDecl()) return QualType();
12365
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012366 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012367 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012368 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12369 // A valid resolved using typename pack expansion decl can have multiple
12370 // UsingDecls, but they must each have exactly one type, and it must be
12371 // the same type in every case. But we must have at least one expansion!
12372 if (UPD->expansions().empty()) {
12373 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12374 << UPD->isCXXClassMember() << UPD;
12375 return QualType();
12376 }
12377
12378 // We might still have some unresolved types. Try to pick a resolved type
12379 // if we can. The final instantiation will check that the remaining
12380 // unresolved types instantiate to the type we pick.
12381 QualType FallbackT;
12382 QualType T;
12383 for (auto *E : UPD->expansions()) {
12384 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12385 if (ThisT.isNull())
12386 continue;
12387 else if (ThisT->getAs<UnresolvedUsingType>())
12388 FallbackT = ThisT;
12389 else if (T.isNull())
12390 T = ThisT;
12391 else
12392 assert(getSema().Context.hasSameType(ThisT, T) &&
12393 "mismatched resolved types in using pack expansion");
12394 }
12395 return T.isNull() ? FallbackT : T;
12396 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012397 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012398 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12399
12400 // A valid resolved using typename decl points to exactly one type decl.
12401 assert(++Using->shadow_begin() == Using->shadow_end());
12402 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012403 } else {
12404 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12405 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12406 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12407 }
12408
12409 return SemaRef.Context.getTypeDeclType(Ty);
12410}
12411
12412template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012413QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12414 SourceLocation Loc) {
12415 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012416}
12417
12418template<typename Derived>
12419QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12420 return SemaRef.Context.getTypeOfType(Underlying);
12421}
12422
12423template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012424QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12425 SourceLocation Loc) {
12426 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012427}
12428
12429template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012430QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12431 UnaryTransformType::UTTKind UKind,
12432 SourceLocation Loc) {
12433 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12434}
12435
12436template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012437QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012438 TemplateName Template,
12439 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012440 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012441 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012442}
Mike Stump11289f42009-09-09 15:08:12 +000012443
Douglas Gregor1135c352009-08-06 05:28:30 +000012444template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012445QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12446 SourceLocation KWLoc) {
12447 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12448}
12449
12450template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012451QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012452 SourceLocation KWLoc,
12453 bool isReadPipe) {
12454 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12455 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012456}
12457
12458template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012459TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012460TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012461 bool TemplateKW,
12462 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012463 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012464 Template);
12465}
12466
12467template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012468TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012469TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12470 const IdentifierInfo &Name,
12471 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012472 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012473 NamedDecl *FirstQualifierInScope,
12474 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012475 UnqualifiedId TemplateName;
12476 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012477 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000012478 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000012479 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012480 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012481 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012482 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012483 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012484 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012485}
Mike Stump11289f42009-09-09 15:08:12 +000012486
Douglas Gregora16548e2009-08-11 05:31:07 +000012487template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012488TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012489TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012490 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012491 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012492 QualType ObjectType,
12493 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012494 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012495 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012496 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012497 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000012498 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000012499 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012500 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012501 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012502 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012503 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012504 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012505 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012506}
Chad Rosier1dcde962012-08-08 18:46:20 +000012507
Douglas Gregor71395fa2009-11-04 00:56:37 +000012508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012509ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012510TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12511 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012512 Expr *OrigCallee,
12513 Expr *First,
12514 Expr *Second) {
12515 Expr *Callee = OrigCallee->IgnoreParenCasts();
12516 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012517
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012518 if (First->getObjectKind() == OK_ObjCProperty) {
12519 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12520 if (BinaryOperator::isAssignmentOp(Opc))
12521 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12522 First, Second);
12523 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12524 if (Result.isInvalid())
12525 return ExprError();
12526 First = Result.get();
12527 }
12528
12529 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12530 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12531 if (Result.isInvalid())
12532 return ExprError();
12533 Second = Result.get();
12534 }
12535
Douglas Gregora16548e2009-08-11 05:31:07 +000012536 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012537 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012538 if (!First->getType()->isOverloadableType() &&
12539 !Second->getType()->isOverloadableType())
12540 return getSema().CreateBuiltinArraySubscriptExpr(First,
12541 Callee->getLocStart(),
12542 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012543 } else if (Op == OO_Arrow) {
12544 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012545 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12546 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012547 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012548 // The argument is not of overloadable type, so try to create a
12549 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012550 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012551 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012552
John McCallb268a282010-08-23 23:25:46 +000012553 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012554 }
12555 } else {
John McCallb268a282010-08-23 23:25:46 +000012556 if (!First->getType()->isOverloadableType() &&
12557 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012558 // Neither of the arguments is an overloadable type, so try to
12559 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012560 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012561 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012562 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012563 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012565
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012566 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012567 }
12568 }
Mike Stump11289f42009-09-09 15:08:12 +000012569
12570 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012571 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012572 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000012573
John McCallb268a282010-08-23 23:25:46 +000012574 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000012575 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000012576 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000012577 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012578 // If we've resolved this to a particular non-member function, just call
12579 // that function. If we resolved it to a member function,
12580 // CreateOverloaded* will find that function for us.
12581 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12582 if (!isa<CXXMethodDecl>(ND))
12583 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000012584 }
Mike Stump11289f42009-09-09 15:08:12 +000012585
Douglas Gregora16548e2009-08-11 05:31:07 +000012586 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012587 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012588 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012589
Douglas Gregora16548e2009-08-11 05:31:07 +000012590 // Create the overloaded operator invocation for unary operators.
12591 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012592 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012593 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000012594 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012595 }
Mike Stump11289f42009-09-09 15:08:12 +000012596
Douglas Gregore9d62932011-07-15 16:25:15 +000012597 if (Op == OO_Subscript) {
12598 SourceLocation LBrace;
12599 SourceLocation RBrace;
12600
12601 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012602 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012603 LBrace = SourceLocation::getFromRawEncoding(
12604 NameLoc.CXXOperatorName.BeginOpNameLoc);
12605 RBrace = SourceLocation::getFromRawEncoding(
12606 NameLoc.CXXOperatorName.EndOpNameLoc);
12607 } else {
12608 LBrace = Callee->getLocStart();
12609 RBrace = OpLoc;
12610 }
12611
12612 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12613 First, Second);
12614 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012615
Douglas Gregora16548e2009-08-11 05:31:07 +000012616 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012617 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012618 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012619 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12620 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012622
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012623 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012624}
Mike Stump11289f42009-09-09 15:08:12 +000012625
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012626template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012627ExprResult
John McCallb268a282010-08-23 23:25:46 +000012628TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012629 SourceLocation OperatorLoc,
12630 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012631 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012632 TypeSourceInfo *ScopeType,
12633 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012634 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012635 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012636 QualType BaseType = Base->getType();
12637 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012638 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012639 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012640 !BaseType->getAs<PointerType>()->getPointeeType()
12641 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012642 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012643 return SemaRef.BuildPseudoDestructorExpr(
12644 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12645 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012646 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012647
Douglas Gregor678f90d2010-02-25 01:56:36 +000012648 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012649 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12650 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12651 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12652 NameInfo.setNamedTypeInfo(DestroyedType);
12653
Richard Smith8e4a3862012-05-15 06:15:11 +000012654 // The scope type is now known to be a valid nested name specifier
12655 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012656 if (ScopeType) {
12657 if (!ScopeType->getType()->getAs<TagType>()) {
12658 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12659 diag::err_expected_class_or_namespace)
12660 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12661 return ExprError();
12662 }
12663 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12664 CCLoc);
12665 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012666
Abramo Bagnara7945c982012-01-27 09:46:47 +000012667 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012668 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012669 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012670 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012671 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012672 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012673 /*TemplateArgs*/ nullptr,
12674 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012675}
12676
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012677template<typename Derived>
12678StmtResult
12679TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012680 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012681 CapturedDecl *CD = S->getCapturedDecl();
12682 unsigned NumParams = CD->getNumParams();
12683 unsigned ContextParamPos = CD->getContextParamPosition();
12684 SmallVector<Sema::CapturedParamNameType, 4> Params;
12685 for (unsigned I = 0; I < NumParams; ++I) {
12686 if (I != ContextParamPos) {
12687 Params.push_back(
12688 std::make_pair(
12689 CD->getParam(I)->getName(),
12690 getDerived().TransformType(CD->getParam(I)->getType())));
12691 } else {
12692 Params.push_back(std::make_pair(StringRef(), QualType()));
12693 }
12694 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012695 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012696 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012697 StmtResult Body;
12698 {
12699 Sema::CompoundScopeRAII CompoundScope(getSema());
12700 Body = getDerived().TransformStmt(S->getCapturedStmt());
12701 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012702
12703 if (Body.isInvalid()) {
12704 getSema().ActOnCapturedRegionError();
12705 return StmtError();
12706 }
12707
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012708 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012709}
12710
Douglas Gregord6ff3322009-08-04 16:50:30 +000012711} // end namespace clang
12712
Hans Wennborg59dbe862015-09-29 20:56:43 +000012713#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H