blob: 96969ea87a13528d14a9bcb59244e308ba459608 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Eric Fiselierbee782b2017-04-03 19:21:00 +000017#include "CoroutineStmtBuilder.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000020#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000021#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000025#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000029#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000030#include "clang/Sema/Designator.h"
31#include "clang/Sema/Lookup.h"
32#include "clang/Sema/Ownership.h"
33#include "clang/Sema/ParsedTemplate.h"
34#include "clang/Sema/ScopeInfo.h"
35#include "clang/Sema/SemaDiagnostic.h"
36#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000037#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000038#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000039#include <algorithm>
40
41namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000042using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000043
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// \brief A semantic tree transformation that allows one to transform one
45/// abstract syntax tree into another.
46///
Mike Stump11289f42009-09-09 15:08:12 +000047/// A new tree transformation is defined by creating a new subclass \c X of
48/// \c TreeTransform<X> and then overriding certain operations to provide
49/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000050/// instantiation is implemented as a tree transformation where the
51/// transformation of TemplateTypeParmType nodes involves substituting the
52/// template arguments for their corresponding template parameters; a similar
53/// transformation is performed for non-type template parameters and
54/// template template parameters.
55///
56/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000057/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000058/// override any of the transformation or rebuild operators by providing an
59/// operation with the same signature as the default implementation. The
60/// overridding function should not be virtual.
61///
62/// Semantic tree transformations are split into two stages, either of which
63/// can be replaced by a subclass. The "transform" step transforms an AST node
64/// or the parts of an AST node using the various transformation functions,
65/// then passes the pieces on to the "rebuild" step, which constructs a new AST
66/// node of the appropriate kind from the pieces. The default transformation
67/// routines recursively transform the operands to composite AST nodes (e.g.,
68/// the pointee type of a PointerType node) and, if any of those operand nodes
69/// were changed by the transformation, invokes the rebuild operation to create
70/// a new AST node.
71///
Mike Stump11289f42009-09-09 15:08:12 +000072/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000073/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000074/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// TransformTemplateName(), or TransformTemplateArgument() with entirely
76/// new implementations.
77///
78/// For more fine-grained transformations, subclasses can replace any of the
79/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000080/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000082/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000083/// parameters. Additionally, subclasses can override the \c RebuildXXX
84/// functions to control how AST nodes are rebuilt when their operands change.
85/// By default, \c TreeTransform will invoke semantic analysis to rebuild
86/// AST nodes. However, certain other tree transformations (e.g, cloning) may
87/// be able to use more efficient rebuild steps.
88///
89/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000090/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000091/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
92/// operands have not changed (\c AlwaysRebuild()), and customize the
93/// default locations and entity names used for type-checking
94/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000095template<typename Derived>
96class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000097 /// \brief Private RAII object that helps us forget and then re-remember
98 /// the template argument corresponding to a partially-substituted parameter
99 /// pack.
100 class ForgetPartiallySubstitutedPackRAII {
101 Derived &Self;
102 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000103
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000104 public:
105 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
106 Old = Self.ForgetPartiallySubstitutedPack();
107 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000108
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000109 ~ForgetPartiallySubstitutedPackRAII() {
110 Self.RememberPartiallySubstitutedPack(Old);
111 }
112 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114protected:
115 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000116
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000117 /// \brief The set of local declarations that have been transformed, for
118 /// cases where we are forced to build new declarations within the transformer
119 /// rather than in the subclass (e.g., lambda closure types).
120 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000121
Mike Stump11289f42009-09-09 15:08:12 +0000122public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000124 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000125
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// \brief Retrieves a reference to the derived class.
127 Derived &getDerived() { return static_cast<Derived&>(*this); }
128
129 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000130 const Derived &getDerived() const {
131 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 }
133
John McCalldadc5752010-08-24 06:29:42 +0000134 static inline ExprResult Owned(Expr *E) { return E; }
135 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000136
Douglas Gregord6ff3322009-08-04 16:50:30 +0000137 /// \brief Retrieves a reference to the semantic analysis object used for
138 /// this tree transform.
139 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Whether the transformation should always rebuild AST nodes, even
142 /// if none of the children have changed.
143 ///
144 /// Subclasses may override this function to specify when the transformation
145 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000146 ///
147 /// We must always rebuild all AST nodes when performing variadic template
148 /// pack expansion, in order to avoid violating the AST invariant that each
149 /// statement node appears at most once in its containing declaration.
150 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000151
Douglas Gregord6ff3322009-08-04 16:50:30 +0000152 /// \brief Returns the location of the entity being transformed, if that
153 /// information was not available elsewhere in the AST.
154 ///
Mike Stump11289f42009-09-09 15:08:12 +0000155 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000156 /// provide an alternative implementation that provides better location
157 /// information.
158 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000159
Douglas Gregord6ff3322009-08-04 16:50:30 +0000160 /// \brief Returns the name of the entity being transformed, if that
161 /// information was not available elsewhere in the AST.
162 ///
163 /// By default, returns an empty name. Subclasses can provide an alternative
164 /// implementation with a more precise name.
165 DeclarationName getBaseEntity() { return DeclarationName(); }
166
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 /// \brief Sets the "base" location and entity when that
168 /// information is known based on another transformation.
169 ///
170 /// By default, the source location and entity are ignored. Subclasses can
171 /// override this function to provide a customized implementation.
172 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000173
Douglas Gregora16548e2009-08-11 05:31:07 +0000174 /// \brief RAII object that temporarily sets the base location and entity
175 /// used for reporting diagnostics in types.
176 class TemporaryBase {
177 TreeTransform &Self;
178 SourceLocation OldLocation;
179 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000180
Douglas Gregora16548e2009-08-11 05:31:07 +0000181 public:
182 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000183 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000184 OldLocation = Self.getDerived().getBaseLocation();
185 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000186
Douglas Gregora518d5b2011-01-25 17:51:48 +0000187 if (Location.isValid())
188 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 }
Mike Stump11289f42009-09-09 15:08:12 +0000190
Douglas Gregora16548e2009-08-11 05:31:07 +0000191 ~TemporaryBase() {
192 Self.getDerived().setBase(OldLocation, OldEntity);
193 }
194 };
Mike Stump11289f42009-09-09 15:08:12 +0000195
196 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000197 /// transformed.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000200 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000201 /// not change. For example, template instantiation need not traverse
202 /// non-dependent types.
203 bool AlreadyTransformed(QualType T) {
204 return T.isNull();
205 }
206
Douglas Gregord196a582009-12-14 19:27:10 +0000207 /// \brief Determine whether the given call argument should be dropped, e.g.,
208 /// because it is a default argument.
209 ///
210 /// Subclasses can provide an alternative implementation of this routine to
211 /// determine which kinds of call arguments get dropped. By default,
212 /// CXXDefaultArgument nodes are dropped (prior to transformation).
213 bool DropCallArgument(Expr *E) {
214 return E->isDefaultArgument();
215 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000216
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000217 /// \brief Determine whether we should expand a pack expansion with the
218 /// given set of parameter packs into separate arguments by repeatedly
219 /// transforming the pattern.
220 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000221 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000222 /// Subclasses can override this routine to provide different behavior.
223 ///
224 /// \param EllipsisLoc The location of the ellipsis that identifies the
225 /// pack expansion.
226 ///
227 /// \param PatternRange The source range that covers the entire pattern of
228 /// the pack expansion.
229 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000230 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// pattern.
232 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000233 /// \param ShouldExpand Will be set to \c true if the transformer should
234 /// expand the corresponding pack expansions into separate arguments. When
235 /// set, \c NumExpansions must also be set.
236 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000237 /// \param RetainExpansion Whether the caller should add an unexpanded
238 /// pack expansion after all of the expanded arguments. This is used
239 /// when extending explicitly-specified template argument packs per
240 /// C++0x [temp.arg.explicit]p9.
241 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000242 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000243 /// the expanded form of the corresponding pack expansion. This is both an
244 /// input and an output parameter, which can be set by the caller if the
245 /// number of expansions is known a priori (e.g., due to a prior substitution)
246 /// and will be set by the callee when the number of expansions is known.
247 /// The callee must set this value when \c ShouldExpand is \c true; it may
248 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000250 /// \returns true if an error occurred (e.g., because the parameter packs
251 /// are to be instantiated with arguments of different lengths), false
252 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000253 /// must be set.
254 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
255 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000256 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000257 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000258 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000259 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000260 ShouldExpand = false;
261 return false;
262 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000263
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000264 /// \brief "Forget" about the partially-substituted pack template argument,
265 /// when performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 TemplateArgument ForgetPartiallySubstitutedPack() {
270 return TemplateArgument();
271 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000272
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000273 /// \brief "Remember" the partially-substituted pack template argument
274 /// after performing an instantiation that must preserve the parameter pack
275 /// use.
276 ///
277 /// This routine is meant to be overridden by the template instantiator.
278 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000279
Douglas Gregorf3010112011-01-07 16:43:16 +0000280 /// \brief Note to the derived class when a function parameter pack is
281 /// being expanded.
282 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000283
Douglas Gregord6ff3322009-08-04 16:50:30 +0000284 /// \brief Transforms the given type into another type.
285 ///
John McCall550e0c22009-10-21 00:40:46 +0000286 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000287 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000288 /// function. This is expensive, but we don't mind, because
289 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000290 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 ///
292 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000293 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000294
John McCall550e0c22009-10-21 00:40:46 +0000295 /// \brief Transforms the given type-with-location into a new
296 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000297 ///
John McCall550e0c22009-10-21 00:40:46 +0000298 /// By default, this routine transforms a type by delegating to the
299 /// appropriate TransformXXXType to build a new type. Subclasses
300 /// may override this function (to take over all type
301 /// transformations) or some set of the TransformXXXType functions
302 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000303 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000304
305 /// \brief Transform the given type-with-location into a new
306 /// type, collecting location information in the given builder
307 /// as necessary.
308 ///
John McCall31f82722010-11-12 08:19:04 +0000309 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000310
Richard Smithee579842017-01-30 20:39:26 +0000311 /// \brief Transform a type that is permitted to produce a
312 /// DeducedTemplateSpecializationType.
313 ///
314 /// This is used in the (relatively rare) contexts where it is acceptable
315 /// for transformation to produce a class template type with deduced
316 /// template arguments.
317 /// @{
318 QualType TransformTypeWithDeducedTST(QualType T);
319 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
320 /// @}
321
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000322 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000323 ///
Mike Stump11289f42009-09-09 15:08:12 +0000324 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000325 /// appropriate TransformXXXStmt function to transform a specific kind of
326 /// statement or the TransformExpr() function to transform an expression.
327 /// Subclasses may override this function to transform statements using some
328 /// other mechanism.
329 ///
330 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000331 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000332
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000333 /// \brief Transform the given statement.
334 ///
335 /// By default, this routine transforms a statement by delegating to the
336 /// appropriate TransformOMPXXXClause function to transform a specific kind
337 /// of clause. Subclasses may override this function to transform statements
338 /// using some other mechanism.
339 ///
340 /// \returns the transformed OpenMP clause.
341 OMPClause *TransformOMPClause(OMPClause *S);
342
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000343 /// \brief Transform the given attribute.
344 ///
345 /// By default, this routine transforms a statement by delegating to the
346 /// appropriate TransformXXXAttr function to transform a specific kind
347 /// of attribute. Subclasses may override this function to transform
348 /// attributed statements using some other mechanism.
349 ///
350 /// \returns the transformed attribute
351 const Attr *TransformAttr(const Attr *S);
352
353/// \brief Transform the specified attribute.
354///
355/// Subclasses should override the transformation of attributes with a pragma
356/// spelling to transform expressions stored within the attribute.
357///
358/// \returns the transformed attribute.
359#define ATTR(X)
360#define PRAGMA_SPELLING_ATTR(X) \
361 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
362#include "clang/Basic/AttrList.inc"
363
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000364 /// \brief Transform the given expression.
365 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000366 /// By default, this routine transforms an expression by delegating to the
367 /// appropriate TransformXXXExpr function to build a new expression.
368 /// Subclasses may override this function to transform expressions using some
369 /// other mechanism.
370 ///
371 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000372 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Richard Smithd59b8322012-12-19 01:39:02 +0000374 /// \brief Transform the given initializer.
375 ///
376 /// By default, this routine transforms an initializer by stripping off the
377 /// semantic nodes added by initialization, then passing the result to
378 /// TransformExpr or TransformExprs.
379 ///
380 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000381 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000382
Douglas Gregora3efea12011-01-03 19:04:46 +0000383 /// \brief Transform the given list of expressions.
384 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000385 /// This routine transforms a list of expressions by invoking
386 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000387 /// support for variadic templates by expanding any pack expansions (if the
388 /// derived class permits such expansion) along the way. When pack expansions
389 /// are present, the number of outputs may not equal the number of inputs.
390 ///
391 /// \param Inputs The set of expressions to be transformed.
392 ///
393 /// \param NumInputs The number of expressions in \c Inputs.
394 ///
395 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000396 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000397 /// be.
398 ///
399 /// \param Outputs The transformed input expressions will be added to this
400 /// vector.
401 ///
402 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
403 /// due to transformation.
404 ///
405 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000406 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000407 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000408 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 /// \brief Transform the given declaration, which is referenced from a type
411 /// or expression.
412 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// By default, acts as the identity function on declarations, unless the
414 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000415 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000416 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000417 llvm::DenseMap<Decl *, Decl *>::iterator Known
418 = TransformedLocalDecls.find(D);
419 if (Known != TransformedLocalDecls.end())
420 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000421
422 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000424
Richard Smith03a4aa32016-06-23 19:02:52 +0000425 /// \brief Transform the specified condition.
426 ///
427 /// By default, this transforms the variable and expression and rebuilds
428 /// the condition.
429 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
430 Expr *Expr,
431 Sema::ConditionKind Kind);
432
Chad Rosier1dcde962012-08-08 18:46:20 +0000433 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000434 /// place them on the new declaration.
435 ///
436 /// By default, this operation does nothing. Subclasses may override this
437 /// behavior to transform attributes.
438 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000439
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000440 /// \brief Note that a local declaration has been transformed by this
441 /// transformer.
442 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000444 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
445 /// the transformer itself has to transform the declarations. This routine
446 /// can be overridden by a subclass that keeps track of such mappings.
447 void transformedLocalDecl(Decl *Old, Decl *New) {
448 TransformedLocalDecls[Old] = New;
449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregorebe10102009-08-20 07:17:43 +0000451 /// \brief Transform the definition of the given declaration.
452 ///
Mike Stump11289f42009-09-09 15:08:12 +0000453 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000454 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000455 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
456 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000457 }
Mike Stump11289f42009-09-09 15:08:12 +0000458
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000459 /// \brief Transform the given declaration, which was the first part of a
460 /// nested-name-specifier in a member access expression.
461 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000462 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000463 /// identifier in a nested-name-specifier of a member access expression, e.g.,
464 /// the \c T in \c x->T::member
465 ///
466 /// By default, invokes TransformDecl() to transform the declaration.
467 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000468 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
469 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000470 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000471
Richard Smith151c4562016-12-20 21:35:28 +0000472 /// Transform the set of declarations in an OverloadExpr.
473 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
474 LookupResult &R);
475
Douglas Gregor14454802011-02-25 02:25:35 +0000476 /// \brief Transform the given nested-name-specifier with source-location
477 /// information.
478 ///
479 /// By default, transforms all of the types and declarations within the
480 /// nested-name-specifier. Subclasses may override this function to provide
481 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000482 NestedNameSpecifierLoc
483 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
484 QualType ObjectType = QualType(),
485 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000486
Douglas Gregorf816bd72009-09-03 22:13:48 +0000487 /// \brief Transform the given declaration name.
488 ///
489 /// By default, transforms the types of conversion function, constructor,
490 /// and destructor names and then (if needed) rebuilds the declaration name.
491 /// Identifiers and selectors are returned unmodified. Sublcasses may
492 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000493 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000494 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000495
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000497 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000498 /// \param SS The nested-name-specifier that qualifies the template
499 /// name. This nested-name-specifier must already have been transformed.
500 ///
501 /// \param Name The template name to transform.
502 ///
503 /// \param NameLoc The source location of the template name.
504 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000505 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000506 /// access expression, this is the type of the object whose member template
507 /// is being referenced.
508 ///
509 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
510 /// also refers to a name within the current (lexical) scope, this is the
511 /// declaration it refers to.
512 ///
513 /// By default, transforms the template name by transforming the declarations
514 /// and nested-name-specifiers that occur within the template name.
515 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000516 TemplateName
517 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
518 SourceLocation NameLoc,
519 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000520 NamedDecl *FirstQualifierInScope = nullptr,
521 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000522
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523 /// \brief Transform the given template argument.
524 ///
Mike Stump11289f42009-09-09 15:08:12 +0000525 /// By default, this operation transforms the type, expression, or
526 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000527 /// new template argument from the transformed result. Subclasses may
528 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000529 ///
530 /// Returns true if there was an error.
531 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000532 TemplateArgumentLoc &Output,
533 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000534
Douglas Gregor62e06f22010-12-20 17:31:10 +0000535 /// \brief Transform the given set of template arguments.
536 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000537 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000538 /// in the input set using \c TransformTemplateArgument(), and appends
539 /// the transformed arguments to the output list.
540 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000541 /// Note that this overload of \c TransformTemplateArguments() is merely
542 /// a convenience function. Subclasses that wish to override this behavior
543 /// should override the iterator-based member template version.
544 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000545 /// \param Inputs The set of template arguments to be transformed.
546 ///
547 /// \param NumInputs The number of template arguments in \p Inputs.
548 ///
549 /// \param Outputs The set of transformed template arguments output by this
550 /// routine.
551 ///
552 /// Returns true if an error occurred.
553 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
554 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000555 TemplateArgumentListInfo &Outputs,
556 bool Uneval = false) {
557 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
558 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000559 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000560
561 /// \brief Transform the given set of template arguments.
562 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000564 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000565 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000566 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000567 /// \param First An iterator to the first template argument.
568 ///
569 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000570 ///
571 /// \param Outputs The set of transformed template arguments output by this
572 /// routine.
573 ///
574 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000575 template<typename InputIterator>
576 bool TransformTemplateArguments(InputIterator First,
577 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000578 TemplateArgumentListInfo &Outputs,
579 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000580
John McCall0ad16662009-10-29 08:12:44 +0000581 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
582 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
583 TemplateArgumentLoc &ArgLoc);
584
John McCallbcd03502009-12-07 02:54:59 +0000585 /// \brief Fakes up a TypeSourceInfo for a type.
586 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
587 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000588 getDerived().getBaseLocation());
589 }
Mike Stump11289f42009-09-09 15:08:12 +0000590
John McCall550e0c22009-10-21 00:40:46 +0000591#define ABSTRACT_TYPELOC(CLASS, PARENT)
592#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000593 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000594#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000595
Richard Smith2e321552014-11-12 02:00:47 +0000596 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000597 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
598 FunctionProtoTypeLoc TL,
599 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000600 unsigned ThisTypeQuals,
601 Fn TransformExceptionSpec);
602
603 bool TransformExceptionSpec(SourceLocation Loc,
604 FunctionProtoType::ExceptionSpecInfo &ESI,
605 SmallVectorImpl<QualType> &Exceptions,
606 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000607
David Majnemerfad8f482013-10-15 09:33:02 +0000608 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000609
Chad Rosier1dcde962012-08-08 18:46:20 +0000610 QualType
John McCall31f82722010-11-12 08:19:04 +0000611 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
612 TemplateSpecializationTypeLoc TL,
613 TemplateName Template);
614
Chad Rosier1dcde962012-08-08 18:46:20 +0000615 QualType
John McCall31f82722010-11-12 08:19:04 +0000616 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
617 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000618 TemplateName Template,
619 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000620
Nico Weberc153d242014-07-28 00:02:09 +0000621 QualType TransformDependentTemplateSpecializationType(
622 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
623 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000624
John McCall58f10c32010-03-11 09:03:00 +0000625 /// \brief Transforms the parameters of a function type into the
626 /// given vectors.
627 ///
628 /// The result vectors should be kept in sync; null entries in the
629 /// variables vector are acceptable.
630 ///
631 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000632 bool TransformFunctionTypeParams(
633 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
634 const QualType *ParamTypes,
635 const FunctionProtoType::ExtParameterInfo *ParamInfos,
636 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
637 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000638
639 /// \brief Transforms a single function-type parameter. Return null
640 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000641 ///
642 /// \param indexAdjustment - A number to add to the parameter's
643 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000644 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000645 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000646 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000647 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000648
John McCall31f82722010-11-12 08:19:04 +0000649 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000650
John McCalldadc5752010-08-24 06:29:42 +0000651 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
652 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000653
Faisal Vali2cba1332013-10-23 06:44:28 +0000654 TemplateParameterList *TransformTemplateParameterList(
655 TemplateParameterList *TPL) {
656 return TPL;
657 }
658
Richard Smithdb2630f2012-10-21 03:28:35 +0000659 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000660
Richard Smithdb2630f2012-10-21 03:28:35 +0000661 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000662 bool IsAddressOfOperand,
663 TypeSourceInfo **RecoveryTSI);
664
665 ExprResult TransformParenDependentScopeDeclRefExpr(
666 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
667 TypeSourceInfo **RecoveryTSI);
668
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000669 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000670
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000671// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
672// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000673#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000674 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000675 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000676#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000677 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000678 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000679#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000680#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000681
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000682#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000683 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000684 OMPClause *Transform ## Class(Class *S);
685#include "clang/Basic/OpenMPKinds.def"
686
Richard Smithee579842017-01-30 20:39:26 +0000687 /// \brief Build a new qualified type given its unqualified type and type
688 /// qualifiers.
689 ///
690 /// By default, this routine adds type qualifiers only to types that can
691 /// have qualifiers, and silently suppresses those qualifiers that are not
692 /// permitted. Subclasses may override this routine to provide different
693 /// behavior.
694 QualType RebuildQualifiedType(QualType T, SourceLocation Loc,
695 Qualifiers Quals);
696
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 /// \brief Build a new pointer type given its pointee type.
698 ///
699 /// By default, performs semantic analysis when building the pointer type.
700 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000701 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702
703 /// \brief Build a new block pointer type given its pointee type.
704 ///
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000707 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708
John McCall70dd5f62009-10-30 00:06:24 +0000709 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710 ///
John McCall70dd5f62009-10-30 00:06:24 +0000711 /// By default, performs semantic analysis when building the
712 /// reference type. Subclasses may override this routine to provide
713 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 ///
John McCall70dd5f62009-10-30 00:06:24 +0000715 /// \param LValue whether the type was written with an lvalue sigil
716 /// or an rvalue sigil.
717 QualType RebuildReferenceType(QualType ReferentType,
718 bool LValue,
719 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000720
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 /// \brief Build a new member pointer type given the pointee type and the
722 /// class type it refers into.
723 ///
724 /// By default, performs semantic analysis when building the member pointer
725 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000726 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
727 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000728
Manman Rene6be26c2016-09-13 17:25:08 +0000729 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
730 SourceLocation ProtocolLAngleLoc,
731 ArrayRef<ObjCProtocolDecl *> Protocols,
732 ArrayRef<SourceLocation> ProtocolLocs,
733 SourceLocation ProtocolRAngleLoc);
734
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000735 /// \brief Build an Objective-C object type.
736 ///
737 /// By default, performs semantic analysis when building the object type.
738 /// Subclasses may override this routine to provide different behavior.
739 QualType RebuildObjCObjectType(QualType BaseType,
740 SourceLocation Loc,
741 SourceLocation TypeArgsLAngleLoc,
742 ArrayRef<TypeSourceInfo *> TypeArgs,
743 SourceLocation TypeArgsRAngleLoc,
744 SourceLocation ProtocolLAngleLoc,
745 ArrayRef<ObjCProtocolDecl *> Protocols,
746 ArrayRef<SourceLocation> ProtocolLocs,
747 SourceLocation ProtocolRAngleLoc);
748
749 /// \brief Build a new Objective-C object pointer type given the pointee type.
750 ///
751 /// By default, directly builds the pointer type, with no additional semantic
752 /// analysis.
753 QualType RebuildObjCObjectPointerType(QualType PointeeType,
754 SourceLocation Star);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new array type given the element type, size
757 /// modifier, size of the array (if known), size expression, and index type
758 /// qualifiers.
759 ///
760 /// By default, performs semantic analysis when building the array type.
761 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000762 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 QualType RebuildArrayType(QualType ElementType,
764 ArrayType::ArraySizeModifier SizeMod,
765 const llvm::APInt *Size,
766 Expr *SizeExpr,
767 unsigned IndexTypeQuals,
768 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// \brief Build a new constant array type given the element type, size
771 /// modifier, (known) size of the array, and index type qualifiers.
772 ///
773 /// By default, performs semantic analysis when building the array type.
774 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000775 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 ArrayType::ArraySizeModifier SizeMod,
777 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000778 unsigned IndexTypeQuals,
779 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780
Douglas Gregord6ff3322009-08-04 16:50:30 +0000781 /// \brief Build a new incomplete array type given the element type, size
782 /// modifier, and index type qualifiers.
783 ///
784 /// By default, performs semantic analysis when building the array type.
785 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000786 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000788 unsigned IndexTypeQuals,
789 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790
Mike Stump11289f42009-09-09 15:08:12 +0000791 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000792 /// size modifier, size expression, and index type qualifiers.
793 ///
794 /// By default, performs semantic analysis when building the array type.
795 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000796 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000798 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000799 unsigned IndexTypeQuals,
800 SourceRange BracketsRange);
801
Mike Stump11289f42009-09-09 15:08:12 +0000802 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 /// size modifier, size expression, and index type qualifiers.
804 ///
805 /// By default, performs semantic analysis when building the array type.
806 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000807 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000808 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000809 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810 unsigned IndexTypeQuals,
811 SourceRange BracketsRange);
812
813 /// \brief Build a new vector type given the element type and
814 /// number of elements.
815 ///
816 /// By default, performs semantic analysis when building the vector type.
817 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000818 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000819 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new extended vector type given the element type and
822 /// number of elements.
823 ///
824 /// By default, performs semantic analysis when building the vector type.
825 /// Subclasses may override this routine to provide different behavior.
826 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
827 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000828
829 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000830 /// given the element type and number of elements.
831 ///
832 /// By default, performs semantic analysis when building the vector type.
833 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000834 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000835 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000836 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000837
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000838 /// \brief Build a new DependentAddressSpaceType or return the pointee
839 /// type variable with the correct address space (retrieved from
840 /// AddrSpaceExpr) applied to it. The former will be returned in cases
841 /// where the address space remains dependent.
842 ///
843 /// By default, performs semantic analysis when building the type with address
844 /// space applied. Subclasses may override this routine to provide different
845 /// behavior.
846 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
847 Expr *AddrSpaceExpr,
848 SourceLocation AttributeLoc);
849
Douglas Gregord6ff3322009-08-04 16:50:30 +0000850 /// \brief Build a new function type.
851 ///
852 /// By default, performs semantic analysis when building the function type.
853 /// Subclasses may override this routine to provide different behavior.
854 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000855 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000856 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000857
John McCall550e0c22009-10-21 00:40:46 +0000858 /// \brief Build a new unprototyped function type.
859 QualType RebuildFunctionNoProtoType(QualType ResultType);
860
John McCallb96ec562009-12-04 22:46:56 +0000861 /// \brief Rebuild an unresolved typename type, given the decl that
862 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000863 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000864
Douglas Gregord6ff3322009-08-04 16:50:30 +0000865 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000866 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000867 return SemaRef.Context.getTypeDeclType(Typedef);
868 }
869
870 /// \brief Build a new class/struct/union type.
871 QualType RebuildRecordType(RecordDecl *Record) {
872 return SemaRef.Context.getTypeDeclType(Record);
873 }
874
875 /// \brief Build a new Enum type.
876 QualType RebuildEnumType(EnumDecl *Enum) {
877 return SemaRef.Context.getTypeDeclType(Enum);
878 }
John McCallfcc33b02009-09-05 00:15:47 +0000879
Mike Stump11289f42009-09-09 15:08:12 +0000880 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000881 ///
882 /// By default, performs semantic analysis when building the typeof type.
883 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000884 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885
Mike Stump11289f42009-09-09 15:08:12 +0000886 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000887 ///
888 /// By default, builds a new TypeOfType with the given underlying type.
889 QualType RebuildTypeOfType(QualType Underlying);
890
Alexis Hunte852b102011-05-24 22:41:36 +0000891 /// \brief Build a new unary transform type.
892 QualType RebuildUnaryTransformType(QualType BaseType,
893 UnaryTransformType::UTTKind UKind,
894 SourceLocation Loc);
895
Richard Smith74aeef52013-04-26 16:15:35 +0000896 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000897 ///
898 /// By default, performs semantic analysis when building the decltype type.
899 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000900 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000901
Richard Smith74aeef52013-04-26 16:15:35 +0000902 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000903 ///
904 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000905 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000906 // Note, IsDependent is always false here: we implicitly convert an 'auto'
907 // which has been deduced to a dependent type into an undeduced 'auto', so
908 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000909 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000910 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000911 }
912
Richard Smith600b5262017-01-26 20:40:47 +0000913 /// By default, builds a new DeducedTemplateSpecializationType with the given
914 /// deduced type.
915 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
916 QualType Deduced) {
917 return SemaRef.Context.getDeducedTemplateSpecializationType(
918 Template, Deduced, /*IsDependent*/ false);
919 }
920
Douglas Gregord6ff3322009-08-04 16:50:30 +0000921 /// \brief Build a new template specialization type.
922 ///
923 /// By default, performs semantic analysis when building the template
924 /// specialization type. Subclasses may override this routine to provide
925 /// different behavior.
926 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000927 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000928 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000929
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000930 /// \brief Build a new parenthesized type.
931 ///
932 /// By default, builds a new ParenType type from the inner type.
933 /// Subclasses may override this routine to provide different behavior.
934 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000935 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000936 }
937
Douglas Gregord6ff3322009-08-04 16:50:30 +0000938 /// \brief Build a new qualified name type.
939 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000940 /// By default, builds a new ElaboratedType type from the keyword,
941 /// the nested-name-specifier and the named type.
942 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000943 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
944 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000945 NestedNameSpecifierLoc QualifierLoc,
946 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000947 return SemaRef.Context.getElaboratedType(Keyword,
948 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000949 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000950 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000951
952 /// \brief Build a new typename type that refers to a template-id.
953 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954 /// By default, builds a new DependentNameType type from the
955 /// nested-name-specifier and the given type. Subclasses may override
956 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000957 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000958 ElaboratedTypeKeyword Keyword,
959 NestedNameSpecifierLoc QualifierLoc,
960 const IdentifierInfo *Name,
961 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000962 TemplateArgumentListInfo &Args,
963 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000964 // Rebuild the template name.
965 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000966 CXXScopeSpec SS;
967 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000968 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000969 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000970 nullptr, AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971
Douglas Gregora7a795b2011-03-01 20:11:18 +0000972 if (InstName.isNull())
973 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000974
Douglas Gregora7a795b2011-03-01 20:11:18 +0000975 // If it's still dependent, make a dependent specialization.
976 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000977 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
978 QualifierLoc.getNestedNameSpecifier(),
979 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000980 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregora7a795b2011-03-01 20:11:18 +0000982 // Otherwise, make an elaborated type wrapping a non-dependent
983 // specialization.
984 QualType T =
985 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
986 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000987
Craig Topperc3ec1492014-05-26 06:22:03 +0000988 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000989 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000990
991 return SemaRef.Context.getElaboratedType(Keyword,
992 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000993 T);
994 }
995
Douglas Gregord6ff3322009-08-04 16:50:30 +0000996 /// \brief Build a new typename type that refers to an identifier.
997 ///
998 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000999 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001000 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001001 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001002 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001003 NestedNameSpecifierLoc QualifierLoc,
1004 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001005 SourceLocation IdLoc,
1006 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001007 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001008 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001009
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001010 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001011 // If the name is still dependent, just build a new dependent name type.
1012 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001013 return SemaRef.Context.getDependentNameType(Keyword,
1014 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001015 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001016 }
1017
Richard Smithee579842017-01-30 20:39:26 +00001018 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1019 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1020 *Id, IdLoc);
1021 // If a dependent name resolves to a deduced template specialization type,
1022 // check that we're in one of the syntactic contexts permitting it.
1023 if (!DeducedTSTContext) {
1024 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1025 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1026 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1027 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1028 Deduced->getTemplateName())
1029 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1030 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1031 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1032 return QualType();
1033 }
1034 }
1035 return T;
1036 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001037
1038 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1039
Abramo Bagnarad7548482010-05-19 21:37:53 +00001040 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001041 // into a non-dependent elaborated-type-specifier. Find the tag we're
1042 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001043 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001044 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1045 if (!DC)
1046 return QualType();
1047
John McCallbf8c5192010-05-27 06:40:31 +00001048 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1049 return QualType();
1050
Craig Topperc3ec1492014-05-26 06:22:03 +00001051 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001052 SemaRef.LookupQualifiedName(Result, DC);
1053 switch (Result.getResultKind()) {
1054 case LookupResult::NotFound:
1055 case LookupResult::NotFoundInCurrentInstantiation:
1056 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001057
Douglas Gregore677daf2010-03-31 22:19:08 +00001058 case LookupResult::Found:
1059 Tag = Result.getAsSingle<TagDecl>();
1060 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001061
Douglas Gregore677daf2010-03-31 22:19:08 +00001062 case LookupResult::FoundOverloaded:
1063 case LookupResult::FoundUnresolvedValue:
1064 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001065
Douglas Gregore677daf2010-03-31 22:19:08 +00001066 case LookupResult::Ambiguous:
1067 // Let the LookupResult structure handle ambiguities.
1068 return QualType();
1069 }
1070
1071 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001072 // Check where the name exists but isn't a tag type and use that to emit
1073 // better diagnostics.
1074 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1075 SemaRef.LookupQualifiedName(Result, DC);
1076 switch (Result.getResultKind()) {
1077 case LookupResult::Found:
1078 case LookupResult::FoundOverloaded:
1079 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001080 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001081 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1082 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1083 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001084 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1085 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001086 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001087 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001088 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001089 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001090 break;
1091 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001092 return QualType();
1093 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001094
Richard Trieucaa33d32011-06-10 03:11:26 +00001095 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001096 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001097 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001098 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1099 return QualType();
1100 }
1101
1102 // Build the elaborated-type-specifier type.
1103 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001104 return SemaRef.Context.getElaboratedType(Keyword,
1105 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001106 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001107 }
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregor822d0302011-01-12 17:07:58 +00001109 /// \brief Build a new pack expansion type.
1110 ///
1111 /// By default, builds a new PackExpansionType type from the given pattern.
1112 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001113 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001114 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001115 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001116 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001117 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1118 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001119 }
1120
Eli Friedman0dfb8892011-10-06 23:00:33 +00001121 /// \brief Build a new atomic type given its value type.
1122 ///
1123 /// By default, performs semantic analysis when building the atomic type.
1124 /// Subclasses may override this routine to provide different behavior.
1125 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1126
Xiuli Pan9c14e282016-01-09 12:53:17 +00001127 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001128 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1129 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001130
Douglas Gregor71dc5092009-08-06 06:41:21 +00001131 /// \brief Build a new template name given a nested name specifier, a flag
1132 /// indicating whether the "template" keyword was provided, and the template
1133 /// that the template name refers to.
1134 ///
1135 /// By default, builds the new template name directly. Subclasses may override
1136 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001137 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001138 bool TemplateKW,
1139 TemplateDecl *Template);
1140
Douglas Gregor71dc5092009-08-06 06:41:21 +00001141 /// \brief Build a new template name given a nested name specifier and the
1142 /// name that is referred to as a template.
1143 ///
1144 /// By default, performs semantic analysis to determine whether the name can
1145 /// be resolved to a specific template, then builds the appropriate kind of
1146 /// template name. Subclasses may override this routine to provide different
1147 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001148 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1149 const IdentifierInfo &Name,
1150 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001151 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001152 NamedDecl *FirstQualifierInScope,
1153 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001154
Douglas Gregor71395fa2009-11-04 00:56:37 +00001155 /// \brief Build a new template name given a nested name specifier and the
1156 /// overloaded operator name that is referred to as a template.
1157 ///
1158 /// By default, performs semantic analysis to determine whether the name can
1159 /// be resolved to a specific template, then builds the appropriate kind of
1160 /// template name. Subclasses may override this routine to provide different
1161 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001162 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001163 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001164 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00001165 QualType ObjectType,
1166 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001167
1168 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001169 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001170 ///
1171 /// By default, performs semantic analysis to determine whether the name can
1172 /// be resolved to a specific template, then builds the appropriate kind of
1173 /// template name. Subclasses may override this routine to provide different
1174 /// behavior.
1175 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1176 const TemplateArgument &ArgPack) {
1177 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1178 }
1179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Build a new compound statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 MultiStmtArg Statements,
1186 SourceLocation RBraceLoc,
1187 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 IsStmtExpr);
1190 }
1191
1192 /// \brief Build a new case statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001197 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001199 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001201 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 ColonLoc);
1203 }
Mike Stump11289f42009-09-09 15:08:12 +00001204
Douglas Gregorebe10102009-08-20 07:17:43 +00001205 /// \brief Attach the body to a new case statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001209 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001210 getSema().ActOnCaseStmtBody(S, Body);
1211 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 /// \brief Build a new default statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001218 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001220 Stmt *SubStmt) {
1221 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001222 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 }
Mike Stump11289f42009-09-09 15:08:12 +00001224
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 /// \brief Build a new label statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001229 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1230 SourceLocation ColonLoc, Stmt *SubStmt) {
1231 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001232 }
Mike Stump11289f42009-09-09 15:08:12 +00001233
Richard Smithc202b282012-04-14 00:33:13 +00001234 /// \brief Build a new label statement.
1235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001238 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1239 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001240 Stmt *SubStmt) {
1241 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1242 }
1243
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 /// \brief Build a new "if" statement.
1245 ///
1246 /// By default, performs semantic analysis to build the new statement.
1247 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001248 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001249 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001250 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001251 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001252 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregorebe10102009-08-20 07:17:43 +00001255 /// \brief Start building a new switch statement.
1256 ///
1257 /// By default, performs semantic analysis to build the new statement.
1258 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001259 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001260 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001261 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001262 }
Mike Stump11289f42009-09-09 15:08:12 +00001263
Douglas Gregorebe10102009-08-20 07:17:43 +00001264 /// \brief Attach the body to the switch statement.
1265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001268 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001269 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001270 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 }
1272
1273 /// \brief Build a new while statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001277 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1278 Sema::ConditionResult Cond, Stmt *Body) {
1279 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001280 }
Mike Stump11289f42009-09-09 15:08:12 +00001281
Douglas Gregorebe10102009-08-20 07:17:43 +00001282 /// \brief Build a new do-while statement.
1283 ///
1284 /// By default, performs semantic analysis to build the new statement.
1285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001286 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001287 SourceLocation WhileLoc, SourceLocation LParenLoc,
1288 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001289 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1290 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001291 }
1292
1293 /// \brief Build a new for statement.
1294 ///
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001297 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001298 Stmt *Init, Sema::ConditionResult Cond,
1299 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1300 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001301 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001302 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001303 }
Mike Stump11289f42009-09-09 15:08:12 +00001304
Douglas Gregorebe10102009-08-20 07:17:43 +00001305 /// \brief Build a new goto statement.
1306 ///
1307 /// By default, performs semantic analysis to build the new statement.
1308 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001309 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1310 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001311 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001312 }
1313
1314 /// \brief Build a new indirect goto statement.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001319 SourceLocation StarLoc,
1320 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001321 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregorebe10102009-08-20 07:17:43 +00001324 /// \brief Build a new return statement.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001328 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001329 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregorebe10102009-08-20 07:17:43 +00001332 /// \brief Build a new declaration statement.
1333 ///
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001336 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001337 SourceLocation StartLoc, SourceLocation EndLoc) {
1338 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001339 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Anders Carlssonaaeef072010-01-24 05:50:09 +00001342 /// \brief Build a new inline asm statement.
1343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001346 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1347 bool IsVolatile, unsigned NumOutputs,
1348 unsigned NumInputs, IdentifierInfo **Names,
1349 MultiExprArg Constraints, MultiExprArg Exprs,
1350 Expr *AsmString, MultiExprArg Clobbers,
1351 SourceLocation RParenLoc) {
1352 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1353 NumInputs, Names, Constraints, Exprs,
1354 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001355 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001356
Chad Rosier32503022012-06-11 20:47:18 +00001357 /// \brief Build a new MS style inline asm statement.
1358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001361 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001362 ArrayRef<Token> AsmToks,
1363 StringRef AsmString,
1364 unsigned NumOutputs, unsigned NumInputs,
1365 ArrayRef<StringRef> Constraints,
1366 ArrayRef<StringRef> Clobbers,
1367 ArrayRef<Expr*> Exprs,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1370 NumOutputs, NumInputs,
1371 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001372 }
1373
Richard Smith9f690bd2015-10-27 06:02:45 +00001374 /// \brief Build a new co_return statement.
1375 ///
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001378 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1379 bool IsImplicit) {
1380 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001381 }
1382
1383 /// \brief Build a new co_await expression.
1384 ///
1385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001387 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1388 bool IsImplicit) {
1389 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1390 }
1391
1392 /// \brief Build a new co_await expression.
1393 ///
1394 /// By default, performs semantic analysis to build the new expression.
1395 /// Subclasses may override this routine to provide different behavior.
1396 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1397 Expr *Result,
1398 UnresolvedLookupExpr *Lookup) {
1399 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001400 }
1401
1402 /// \brief Build a new co_yield expression.
1403 ///
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1407 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1408 }
1409
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001410 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1411 return getSema().BuildCoroutineBodyStmt(Args);
1412 }
1413
James Dennett2a4d13c2012-06-15 07:13:21 +00001414 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001415 ///
1416 /// By default, performs semantic analysis to build the new statement.
1417 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001418 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001419 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001420 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001421 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001422 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001423 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001424 }
1425
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001426 /// \brief Rebuild an Objective-C exception declaration.
1427 ///
1428 /// By default, performs semantic analysis to build the new declaration.
1429 /// Subclasses may override this routine to provide different behavior.
1430 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1431 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001432 return getSema().BuildObjCExceptionDecl(TInfo, T,
1433 ExceptionDecl->getInnerLocStart(),
1434 ExceptionDecl->getLocation(),
1435 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001437
James Dennett2a4d13c2012-06-15 07:13:21 +00001438 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001439 ///
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001442 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001443 SourceLocation RParenLoc,
1444 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001445 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001446 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001447 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001449
James Dennett2a4d13c2012-06-15 07:13:21 +00001450 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001451 ///
1452 /// By default, performs semantic analysis to build the new statement.
1453 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001454 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001455 Stmt *Body) {
1456 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001458
James Dennett2a4d13c2012-06-15 07:13:21 +00001459 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001460 ///
1461 /// By default, performs semantic analysis to build the new statement.
1462 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001463 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001464 Expr *Operand) {
1465 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001467
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001468 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001469 ///
1470 /// By default, performs semantic analysis to build the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001472 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001473 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001474 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001475 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001476 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001477 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001478 return getSema().ActOnOpenMPExecutableDirective(
1479 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001480 }
1481
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001482 /// \brief Build a new OpenMP 'if' clause.
1483 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001484 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001485 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001486 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1487 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001488 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001489 SourceLocation NameModifierLoc,
1490 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001491 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001492 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1493 LParenLoc, NameModifierLoc, ColonLoc,
1494 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001495 }
1496
Alexey Bataev3778b602014-07-17 07:32:53 +00001497 /// \brief Build a new OpenMP 'final' clause.
1498 ///
1499 /// By default, performs semantic analysis to build the new OpenMP clause.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1505 EndLoc);
1506 }
1507
Alexey Bataev568a8332014-03-06 06:15:19 +00001508 /// \brief Build a new OpenMP 'num_threads' clause.
1509 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001510 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation EndLoc) {
1516 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1517 LParenLoc, EndLoc);
1518 }
1519
Alexey Bataev62c87d22014-03-21 04:51:18 +00001520 /// \brief Build a new OpenMP 'safelen' clause.
1521 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001522 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001523 /// Subclasses may override this routine to provide different behavior.
1524 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1528 }
1529
Alexey Bataev66b15b52015-08-21 11:14:16 +00001530 /// \brief Build a new OpenMP 'simdlen' clause.
1531 ///
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1535 SourceLocation LParenLoc,
1536 SourceLocation EndLoc) {
1537 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1538 }
1539
Alexander Musman8bd31e62014-05-27 15:12:19 +00001540 /// \brief Build a new OpenMP 'collapse' clause.
1541 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001542 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1545 SourceLocation LParenLoc,
1546 SourceLocation EndLoc) {
1547 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1548 EndLoc);
1549 }
1550
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001551 /// \brief Build a new OpenMP 'default' clause.
1552 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001553 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001554 /// Subclasses may override this routine to provide different behavior.
1555 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1556 SourceLocation KindKwLoc,
1557 SourceLocation StartLoc,
1558 SourceLocation LParenLoc,
1559 SourceLocation EndLoc) {
1560 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1561 StartLoc, LParenLoc, EndLoc);
1562 }
1563
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001564 /// \brief Build a new OpenMP 'proc_bind' clause.
1565 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001566 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001567 /// Subclasses may override this routine to provide different behavior.
1568 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1569 SourceLocation KindKwLoc,
1570 SourceLocation StartLoc,
1571 SourceLocation LParenLoc,
1572 SourceLocation EndLoc) {
1573 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1574 StartLoc, LParenLoc, EndLoc);
1575 }
1576
Alexey Bataev56dafe82014-06-20 07:16:17 +00001577 /// \brief Build a new OpenMP 'schedule' clause.
1578 ///
1579 /// By default, performs semantic analysis to build the new OpenMP clause.
1580 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001581 OMPClause *RebuildOMPScheduleClause(
1582 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1583 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1584 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1585 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001586 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001587 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1588 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001589 }
1590
Alexey Bataev10e775f2015-07-30 11:36:16 +00001591 /// \brief Build a new OpenMP 'ordered' clause.
1592 ///
1593 /// By default, performs semantic analysis to build the new OpenMP clause.
1594 /// Subclasses may override this routine to provide different behavior.
1595 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1596 SourceLocation EndLoc,
1597 SourceLocation LParenLoc, Expr *Num) {
1598 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1599 }
1600
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001601 /// \brief Build a new OpenMP 'private' clause.
1602 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001603 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001604 /// Subclasses may override this routine to provide different behavior.
1605 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1606 SourceLocation StartLoc,
1607 SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1610 EndLoc);
1611 }
1612
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001613 /// \brief Build a new OpenMP 'firstprivate' clause.
1614 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001615 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001616 /// Subclasses may override this routine to provide different behavior.
1617 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 SourceLocation EndLoc) {
1621 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1622 EndLoc);
1623 }
1624
Alexander Musman1bb328c2014-06-04 13:06:39 +00001625 /// \brief Build a new OpenMP 'lastprivate' clause.
1626 ///
1627 /// By default, performs semantic analysis to build the new OpenMP clause.
1628 /// Subclasses may override this routine to provide different behavior.
1629 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1630 SourceLocation StartLoc,
1631 SourceLocation LParenLoc,
1632 SourceLocation EndLoc) {
1633 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1634 EndLoc);
1635 }
1636
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001637 /// \brief Build a new OpenMP 'shared' clause.
1638 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001639 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001640 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001641 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 SourceLocation EndLoc) {
1645 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1646 EndLoc);
1647 }
1648
Alexey Bataevc5e02582014-06-16 07:08:35 +00001649 /// \brief Build a new OpenMP 'reduction' clause.
1650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1654 SourceLocation StartLoc,
1655 SourceLocation LParenLoc,
1656 SourceLocation ColonLoc,
1657 SourceLocation EndLoc,
1658 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001659 const DeclarationNameInfo &ReductionId,
1660 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001661 return getSema().ActOnOpenMPReductionClause(
1662 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001663 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001664 }
1665
Alexey Bataev169d96a2017-07-18 20:17:46 +00001666 /// Build a new OpenMP 'task_reduction' clause.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1670 OMPClause *RebuildOMPTaskReductionClause(
1671 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1672 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1673 CXXScopeSpec &ReductionIdScopeSpec,
1674 const DeclarationNameInfo &ReductionId,
1675 ArrayRef<Expr *> UnresolvedReductions) {
1676 return getSema().ActOnOpenMPTaskReductionClause(
1677 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1678 ReductionId, UnresolvedReductions);
1679 }
1680
Alexey Bataevfa312f32017-07-21 18:48:21 +00001681 /// Build a new OpenMP 'in_reduction' clause.
1682 ///
1683 /// By default, performs semantic analysis to build the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1685 OMPClause *
1686 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1687 SourceLocation LParenLoc, SourceLocation ColonLoc,
1688 SourceLocation EndLoc,
1689 CXXScopeSpec &ReductionIdScopeSpec,
1690 const DeclarationNameInfo &ReductionId,
1691 ArrayRef<Expr *> UnresolvedReductions) {
1692 return getSema().ActOnOpenMPInReductionClause(
1693 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1694 ReductionId, UnresolvedReductions);
1695 }
1696
Alexander Musman8dba6642014-04-22 13:09:42 +00001697 /// \brief Build a new OpenMP 'linear' clause.
1698 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001699 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001700 /// Subclasses may override this routine to provide different behavior.
1701 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1702 SourceLocation StartLoc,
1703 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001704 OpenMPLinearClauseKind Modifier,
1705 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001706 SourceLocation ColonLoc,
1707 SourceLocation EndLoc) {
1708 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001709 Modifier, ModifierLoc, ColonLoc,
1710 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001711 }
1712
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001713 /// \brief Build a new OpenMP 'aligned' clause.
1714 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001715 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001716 /// Subclasses may override this routine to provide different behavior.
1717 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1718 SourceLocation StartLoc,
1719 SourceLocation LParenLoc,
1720 SourceLocation ColonLoc,
1721 SourceLocation EndLoc) {
1722 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1723 LParenLoc, ColonLoc, EndLoc);
1724 }
1725
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001726 /// \brief Build a new OpenMP 'copyin' clause.
1727 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001728 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001729 /// Subclasses may override this routine to provide different behavior.
1730 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1731 SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1735 EndLoc);
1736 }
1737
Alexey Bataevbae9a792014-06-27 10:37:06 +00001738 /// \brief Build a new OpenMP 'copyprivate' clause.
1739 ///
1740 /// By default, performs semantic analysis to build the new OpenMP clause.
1741 /// Subclasses may override this routine to provide different behavior.
1742 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1743 SourceLocation StartLoc,
1744 SourceLocation LParenLoc,
1745 SourceLocation EndLoc) {
1746 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1747 EndLoc);
1748 }
1749
Alexey Bataev6125da92014-07-21 11:26:11 +00001750 /// \brief Build a new OpenMP 'flush' pseudo clause.
1751 ///
1752 /// By default, performs semantic analysis to build the new OpenMP clause.
1753 /// Subclasses may override this routine to provide different behavior.
1754 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1755 SourceLocation StartLoc,
1756 SourceLocation LParenLoc,
1757 SourceLocation EndLoc) {
1758 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1759 EndLoc);
1760 }
1761
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001762 /// \brief Build a new OpenMP 'depend' pseudo clause.
1763 ///
1764 /// By default, performs semantic analysis to build the new OpenMP clause.
1765 /// Subclasses may override this routine to provide different behavior.
1766 OMPClause *
1767 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1768 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1769 SourceLocation StartLoc, SourceLocation LParenLoc,
1770 SourceLocation EndLoc) {
1771 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1772 StartLoc, LParenLoc, EndLoc);
1773 }
1774
Michael Wonge710d542015-08-07 16:16:36 +00001775 /// \brief Build a new OpenMP 'device' clause.
1776 ///
1777 /// By default, performs semantic analysis to build the new statement.
1778 /// Subclasses may override this routine to provide different behavior.
1779 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001782 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001783 EndLoc);
1784 }
1785
Kelvin Li0bff7af2015-11-23 05:32:03 +00001786 /// \brief Build a new OpenMP 'map' clause.
1787 ///
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001790 OMPClause *
1791 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1792 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1793 SourceLocation MapLoc, SourceLocation ColonLoc,
1794 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1795 SourceLocation LParenLoc, SourceLocation EndLoc) {
1796 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1797 IsMapTypeImplicit, MapLoc, ColonLoc,
1798 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001799 }
1800
Kelvin Li099bb8c2015-11-24 20:50:12 +00001801 /// \brief Build a new OpenMP 'num_teams' clause.
1802 ///
1803 /// By default, performs semantic analysis to build the new statement.
1804 /// Subclasses may override this routine to provide different behavior.
1805 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1806 SourceLocation LParenLoc,
1807 SourceLocation EndLoc) {
1808 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1809 EndLoc);
1810 }
1811
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001812 /// \brief Build a new OpenMP 'thread_limit' clause.
1813 ///
1814 /// By default, performs semantic analysis to build the new statement.
1815 /// Subclasses may override this routine to provide different behavior.
1816 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1817 SourceLocation StartLoc,
1818 SourceLocation LParenLoc,
1819 SourceLocation EndLoc) {
1820 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1821 LParenLoc, EndLoc);
1822 }
1823
Alexey Bataeva0569352015-12-01 10:17:31 +00001824 /// \brief Build a new OpenMP 'priority' clause.
1825 ///
1826 /// By default, performs semantic analysis to build the new statement.
1827 /// Subclasses may override this routine to provide different behavior.
1828 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1829 SourceLocation LParenLoc,
1830 SourceLocation EndLoc) {
1831 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1832 EndLoc);
1833 }
1834
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001835 /// \brief Build a new OpenMP 'grainsize' clause.
1836 ///
1837 /// By default, performs semantic analysis to build the new statement.
1838 /// Subclasses may override this routine to provide different behavior.
1839 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1840 SourceLocation LParenLoc,
1841 SourceLocation EndLoc) {
1842 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1843 EndLoc);
1844 }
1845
Alexey Bataev382967a2015-12-08 12:06:20 +00001846 /// \brief Build a new OpenMP 'num_tasks' clause.
1847 ///
1848 /// By default, performs semantic analysis to build the new statement.
1849 /// Subclasses may override this routine to provide different behavior.
1850 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1851 SourceLocation LParenLoc,
1852 SourceLocation EndLoc) {
1853 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1854 EndLoc);
1855 }
1856
Alexey Bataev28c75412015-12-15 08:19:24 +00001857 /// \brief Build a new OpenMP 'hint' clause.
1858 ///
1859 /// By default, performs semantic analysis to build the new statement.
1860 /// Subclasses may override this routine to provide different behavior.
1861 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1862 SourceLocation LParenLoc,
1863 SourceLocation EndLoc) {
1864 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1865 }
1866
Carlo Bertollib4adf552016-01-15 18:50:31 +00001867 /// \brief Build a new OpenMP 'dist_schedule' clause.
1868 ///
1869 /// By default, performs semantic analysis to build the new OpenMP clause.
1870 /// Subclasses may override this routine to provide different behavior.
1871 OMPClause *
1872 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1873 Expr *ChunkSize, SourceLocation StartLoc,
1874 SourceLocation LParenLoc, SourceLocation KindLoc,
1875 SourceLocation CommaLoc, SourceLocation EndLoc) {
1876 return getSema().ActOnOpenMPDistScheduleClause(
1877 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1878 }
1879
Samuel Antao661c0902016-05-26 17:39:58 +00001880 /// \brief Build a new OpenMP 'to' clause.
1881 ///
1882 /// By default, performs semantic analysis to build the new statement.
1883 /// Subclasses may override this routine to provide different behavior.
1884 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1885 SourceLocation StartLoc,
1886 SourceLocation LParenLoc,
1887 SourceLocation EndLoc) {
1888 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1889 }
1890
Samuel Antaoec172c62016-05-26 17:49:04 +00001891 /// \brief Build a new OpenMP 'from' clause.
1892 ///
1893 /// By default, performs semantic analysis to build the new statement.
1894 /// Subclasses may override this routine to provide different behavior.
1895 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1896 SourceLocation StartLoc,
1897 SourceLocation LParenLoc,
1898 SourceLocation EndLoc) {
1899 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1900 EndLoc);
1901 }
1902
Carlo Bertolli2404b172016-07-13 15:37:16 +00001903 /// Build a new OpenMP 'use_device_ptr' clause.
1904 ///
1905 /// By default, performs semantic analysis to build the new OpenMP clause.
1906 /// Subclasses may override this routine to provide different behavior.
1907 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1908 SourceLocation StartLoc,
1909 SourceLocation LParenLoc,
1910 SourceLocation EndLoc) {
1911 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1912 EndLoc);
1913 }
1914
Carlo Bertolli70594e92016-07-13 17:16:49 +00001915 /// Build a new OpenMP 'is_device_ptr' clause.
1916 ///
1917 /// By default, performs semantic analysis to build the new OpenMP clause.
1918 /// Subclasses may override this routine to provide different behavior.
1919 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1920 SourceLocation StartLoc,
1921 SourceLocation LParenLoc,
1922 SourceLocation EndLoc) {
1923 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1924 EndLoc);
1925 }
1926
James Dennett2a4d13c2012-06-15 07:13:21 +00001927 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001928 ///
1929 /// By default, performs semantic analysis to build the new statement.
1930 /// Subclasses may override this routine to provide different behavior.
1931 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1932 Expr *object) {
1933 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1934 }
1935
James Dennett2a4d13c2012-06-15 07:13:21 +00001936 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001937 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001938 /// By default, performs semantic analysis to build the new statement.
1939 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001940 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001941 Expr *Object, Stmt *Body) {
1942 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001943 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001944
James Dennett2a4d13c2012-06-15 07:13:21 +00001945 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001946 ///
1947 /// By default, performs semantic analysis to build the new statement.
1948 /// Subclasses may override this routine to provide different behavior.
1949 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1950 Stmt *Body) {
1951 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1952 }
John McCall53848232011-07-27 01:07:15 +00001953
Douglas Gregorf68a5082010-04-22 23:10:45 +00001954 /// \brief Build a new Objective-C fast enumeration statement.
1955 ///
1956 /// By default, performs semantic analysis to build the new statement.
1957 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001958 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001959 Stmt *Element,
1960 Expr *Collection,
1961 SourceLocation RParenLoc,
1962 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001963 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001964 Element,
John McCallb268a282010-08-23 23:25:46 +00001965 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001966 RParenLoc);
1967 if (ForEachStmt.isInvalid())
1968 return StmtError();
1969
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001970 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001971 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001972
Douglas Gregorebe10102009-08-20 07:17:43 +00001973 /// \brief Build a new C++ exception declaration.
1974 ///
1975 /// By default, performs semantic analysis to build the new decaration.
1976 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001977 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001978 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001979 SourceLocation StartLoc,
1980 SourceLocation IdLoc,
1981 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001982 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001983 StartLoc, IdLoc, Id);
1984 if (Var)
1985 getSema().CurContext->addDecl(Var);
1986 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001987 }
1988
1989 /// \brief Build a new C++ catch statement.
1990 ///
1991 /// By default, performs semantic analysis to build the new statement.
1992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001994 VarDecl *ExceptionDecl,
1995 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1997 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999
Douglas Gregorebe10102009-08-20 07:17:43 +00002000 /// \brief Build a new C++ try statement.
2001 ///
2002 /// By default, performs semantic analysis to build the new statement.
2003 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2005 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002006 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008
Richard Smith02e85f32011-04-14 22:09:26 +00002009 /// \brief Build a new C++0x range-based for statement.
2010 ///
2011 /// By default, performs semantic analysis to build the new statement.
2012 /// Subclasses may override this routine to provide different behavior.
2013 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00002014 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00002015 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002016 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00002017 Expr *Cond, Expr *Inc,
2018 Stmt *LoopVar,
2019 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002020 // If we've just learned that the range is actually an Objective-C
2021 // collection, treat this as an Objective-C fast enumeration loop.
2022 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2023 if (RangeStmt->isSingleDecl()) {
2024 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002025 if (RangeVar->isInvalidDecl())
2026 return StmtError();
2027
Douglas Gregorf7106af2013-04-08 18:40:13 +00002028 Expr *RangeExpr = RangeVar->getInit();
2029 if (!RangeExpr->isTypeDependent() &&
2030 RangeExpr->getType()->isObjCObjectPointerType())
2031 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2032 RParenLoc);
2033 }
2034 }
2035 }
2036
Richard Smithcfd53b42015-10-22 06:13:50 +00002037 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002038 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00002039 Cond, Inc, LoopVar, RParenLoc,
2040 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002041 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002042
2043 /// \brief Build a new C++0x range-based for statement.
2044 ///
2045 /// By default, performs semantic analysis to build the new statement.
2046 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002047 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002048 bool IsIfExists,
2049 NestedNameSpecifierLoc QualifierLoc,
2050 DeclarationNameInfo NameInfo,
2051 Stmt *Nested) {
2052 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2053 QualifierLoc, NameInfo, Nested);
2054 }
2055
Richard Smith02e85f32011-04-14 22:09:26 +00002056 /// \brief Attach body to a C++0x range-based for statement.
2057 ///
2058 /// By default, performs semantic analysis to finish the new statement.
2059 /// Subclasses may override this routine to provide different behavior.
2060 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2061 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2062 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002063
David Majnemerfad8f482013-10-15 09:33:02 +00002064 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002065 Stmt *TryBlock, Stmt *Handler) {
2066 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002067 }
2068
David Majnemerfad8f482013-10-15 09:33:02 +00002069 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002070 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002071 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002072 }
2073
David Majnemerfad8f482013-10-15 09:33:02 +00002074 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002075 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002076 }
2077
Alexey Bataevec474782014-10-09 08:45:04 +00002078 /// \brief Build a new predefined expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
2082 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2083 PredefinedExpr::IdentType IT) {
2084 return getSema().BuildPredefinedExpr(Loc, IT);
2085 }
2086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 /// \brief Build a new expression that references a declaration.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002092 LookupResult &R,
2093 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002094 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2095 }
2096
2097
2098 /// \brief Build a new expression that references a declaration.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002102 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002103 ValueDecl *VD,
2104 const DeclarationNameInfo &NameInfo,
2105 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002106 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002107 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002108
2109 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002110
2111 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 }
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002115 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002118 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002120 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 }
2122
Douglas Gregorad8a3362009-09-04 17:36:40 +00002123 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002124 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002125 /// By default, performs semantic analysis to build the new expression.
2126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002127 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002128 SourceLocation OperatorLoc,
2129 bool isArrow,
2130 CXXScopeSpec &SS,
2131 TypeSourceInfo *ScopeType,
2132 SourceLocation CCLoc,
2133 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002134 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002141 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002143 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 }
Mike Stump11289f42009-09-09 15:08:12 +00002145
Douglas Gregor882211c2010-04-28 22:16:22 +00002146 /// \brief Build a new builtin offsetof expression.
2147 ///
2148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002150 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002151 TypeSourceInfo *Type,
2152 ArrayRef<Sema::OffsetOfComponent> Components,
2153 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002154 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002155 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002157
2158 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002159 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002160 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002163 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2164 SourceLocation OpLoc,
2165 UnaryExprOrTypeTrait ExprKind,
2166 SourceRange R) {
2167 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 }
2169
Peter Collingbournee190dee2011-03-11 19:24:49 +00002170 /// \brief Build a new sizeof, alignof or vec step expression with an
2171 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002172 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002175 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2176 UnaryExprOrTypeTrait ExprKind,
2177 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002178 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002179 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002181 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002182
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002183 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 }
Mike Stump11289f42009-09-09 15:08:12 +00002185
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002187 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002190 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002192 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002194 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002195 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 RBracketLoc);
2197 }
2198
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002199 /// \brief Build a new array section expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
2203 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2204 Expr *LowerBound,
2205 SourceLocation ColonLoc, Expr *Length,
2206 SourceLocation RBracketLoc) {
2207 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2208 ColonLoc, Length, RBracketLoc);
2209 }
2210
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002217 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002218 Expr *ExecConfig = nullptr) {
2219 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002220 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
2222
2223 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002228 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002229 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002230 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002231 const DeclarationNameInfo &MemberNameInfo,
2232 ValueDecl *Member,
2233 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002234 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002235 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002236 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2237 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002238 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002239 // We have a reference to an unnamed field. This is always the
2240 // base of an anonymous struct/union member access, i.e. the
2241 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002242 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002243 assert(Member->getType()->isRecordType() &&
2244 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002245
Richard Smithcab9a7d2011-10-26 19:06:56 +00002246 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002247 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002248 QualifierLoc.getNestedNameSpecifier(),
2249 FoundDecl, Member);
2250 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002251 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002252 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002253 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002254 MemberExpr *ME = new (getSema().Context)
2255 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2256 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002257 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002258 }
Mike Stump11289f42009-09-09 15:08:12 +00002259
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002260 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002261 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002262
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002263 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002264 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002265
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002266 if (isArrow && !BaseType->isPointerType())
2267 return ExprError();
2268
John McCall16df1e52010-03-30 21:47:33 +00002269 // FIXME: this involves duplicating earlier analysis in a lot of
2270 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002271 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002272 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002273 R.resolveKind();
2274
John McCallb268a282010-08-23 23:25:46 +00002275 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002276 SS, TemplateKWLoc,
2277 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002278 R, ExplicitTemplateArgs,
2279 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 }
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002283 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002287 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002288 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002289 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 }
2291
2292 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002293 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002296 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002297 SourceLocation QuestionLoc,
2298 Expr *LHS,
2299 SourceLocation ColonLoc,
2300 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002301 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2302 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 }
2304
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002306 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002309 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002310 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002312 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002313 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002314 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 }
Mike Stump11289f42009-09-09 15:08:12 +00002316
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002318 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 /// By default, performs semantic analysis to build the new expression.
2320 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002321 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002322 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002324 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002325 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002326 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 }
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002330 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 /// By default, performs semantic analysis to build the new expression.
2332 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002333 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 SourceLocation OpLoc,
2335 SourceLocation AccessorLoc,
2336 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002337
John McCall10eae182009-11-30 22:42:35 +00002338 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002339 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002340 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002341 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002342 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002343 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002344 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002345 /* TemplateArgs */ nullptr,
2346 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002350 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002353 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002354 MultiExprArg Inits,
2355 SourceLocation RBraceLoc,
2356 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002357 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002358 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002359 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002360 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002361
Douglas Gregord3d93062009-11-09 17:16:50 +00002362 // Patch in the result type we were given, which may have been computed
2363 // when the initial InitListExpr was built.
2364 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2365 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002366 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 }
Mike Stump11289f42009-09-09 15:08:12 +00002368
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002370 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002373 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 MultiExprArg ArrayExprs,
2375 SourceLocation EqualOrColonLoc,
2376 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002377 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002378 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002380 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002381 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002383
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002384 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002385 }
Mike Stump11289f42009-09-09 15:08:12 +00002386
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002388 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 /// By default, builds the implicit value initialization without performing
2390 /// any semantic analysis. Subclasses may override this routine to provide
2391 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002392 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002393 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 }
Mike Stump11289f42009-09-09 15:08:12 +00002395
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 /// \brief Build a new \c va_arg expression.
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 RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002401 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002402 SourceLocation RParenLoc) {
2403 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002404 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002405 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 }
2407
2408 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002409 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002412 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002413 MultiExprArg SubExprs,
2414 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002415 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 }
Mike Stump11289f42009-09-09 15:08:12 +00002417
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002419 ///
2420 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 /// rather than attempting to map the label statement itself.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002424 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002425 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 }
Mike Stump11289f42009-09-09 15:08:12 +00002427
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002429 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 /// By default, performs semantic analysis to build the new expression.
2431 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002432 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002433 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002435 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 }
Mike Stump11289f42009-09-09 15:08:12 +00002437
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 /// \brief Build a new __builtin_choose_expr expression.
2439 ///
2440 /// By default, performs semantic analysis to build the new expression.
2441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002442 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002443 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 SourceLocation RParenLoc) {
2445 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002446 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002447 RParenLoc);
2448 }
Mike Stump11289f42009-09-09 15:08:12 +00002449
Peter Collingbourne91147592011-04-15 00:35:48 +00002450 /// \brief Build a new generic selection expression.
2451 ///
2452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
2454 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2455 SourceLocation DefaultLoc,
2456 SourceLocation RParenLoc,
2457 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002458 ArrayRef<TypeSourceInfo *> Types,
2459 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002460 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002461 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002462 }
2463
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 /// \brief Build a new overloaded operator call expression.
2465 ///
2466 /// By default, performs semantic analysis to build the new expression.
2467 /// The semantic analysis provides the behavior of template instantiation,
2468 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002469 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 /// argument-dependent lookup, etc. Subclasses may override this routine to
2471 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002472 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002474 Expr *Callee,
2475 Expr *First,
2476 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002477
2478 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002479 /// reinterpret_cast.
2480 ///
2481 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002482 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002484 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 Stmt::StmtClass Class,
2486 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002487 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 SourceLocation RAngleLoc,
2489 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002490 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002491 SourceLocation RParenLoc) {
2492 switch (Class) {
2493 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002494 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002495 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002496 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002497
2498 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002499 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002500 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002501 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002502
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002504 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002505 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002506 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002507 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002508
Douglas Gregora16548e2009-08-11 05:31:07 +00002509 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002510 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002511 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002512 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002513
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002515 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002516 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002517 }
Mike Stump11289f42009-09-09 15:08:12 +00002518
Douglas Gregora16548e2009-08-11 05:31:07 +00002519 /// \brief Build a new C++ static_cast expression.
2520 ///
2521 /// By default, performs semantic analysis to build the new expression.
2522 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002523 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002525 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002526 SourceLocation RAngleLoc,
2527 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002528 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002529 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002530 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002531 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002532 SourceRange(LAngleLoc, RAngleLoc),
2533 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002534 }
2535
2536 /// \brief Build a new C++ dynamic_cast expression.
2537 ///
2538 /// By default, performs semantic analysis to build the new expression.
2539 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002540 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002542 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002543 SourceLocation RAngleLoc,
2544 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002545 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002547 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002548 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002549 SourceRange(LAngleLoc, RAngleLoc),
2550 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 }
2552
2553 /// \brief Build a new C++ reinterpret_cast expression.
2554 ///
2555 /// By default, performs semantic analysis to build the new expression.
2556 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002557 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002559 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002560 SourceLocation RAngleLoc,
2561 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002562 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002563 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002564 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002565 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002566 SourceRange(LAngleLoc, RAngleLoc),
2567 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 }
2569
2570 /// \brief Build a new C++ const_cast expression.
2571 ///
2572 /// By default, performs semantic analysis to build the new expression.
2573 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002574 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002576 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002577 SourceLocation RAngleLoc,
2578 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002579 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002581 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002582 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002583 SourceRange(LAngleLoc, RAngleLoc),
2584 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002585 }
Mike Stump11289f42009-09-09 15:08:12 +00002586
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 /// \brief Build a new C++ functional-style cast expression.
2588 ///
2589 /// By default, performs semantic analysis to build the new expression.
2590 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002591 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2592 SourceLocation LParenLoc,
2593 Expr *Sub,
2594 SourceLocation RParenLoc) {
2595 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002596 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002597 RParenLoc);
2598 }
Mike Stump11289f42009-09-09 15:08:12 +00002599
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 /// \brief Build a new C++ typeid(type) expression.
2601 ///
2602 /// By default, performs semantic analysis to build the new expression.
2603 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002604 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002605 SourceLocation TypeidLoc,
2606 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002607 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002608 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002609 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002610 }
Mike Stump11289f42009-09-09 15:08:12 +00002611
Francois Pichet9f4f2072010-09-08 12:20:18 +00002612
Douglas Gregora16548e2009-08-11 05:31:07 +00002613 /// \brief Build a new C++ typeid(expr) expression.
2614 ///
2615 /// By default, performs semantic analysis to build the new expression.
2616 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002617 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002618 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002619 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002620 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002621 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002622 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002623 }
2624
Francois Pichet9f4f2072010-09-08 12:20:18 +00002625 /// \brief Build a new C++ __uuidof(type) 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 TypeSourceInfo *Operand,
2632 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002633 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002634 RParenLoc);
2635 }
2636
2637 /// \brief Build a new C++ __uuidof(expr) expression.
2638 ///
2639 /// By default, performs semantic analysis to build the new expression.
2640 /// Subclasses may override this routine to provide different behavior.
2641 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2642 SourceLocation TypeidLoc,
2643 Expr *Operand,
2644 SourceLocation RParenLoc) {
2645 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2646 RParenLoc);
2647 }
2648
Douglas Gregora16548e2009-08-11 05:31:07 +00002649 /// \brief Build a new C++ "this" expression.
2650 ///
2651 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002652 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002654 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002655 QualType ThisType,
2656 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002657 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002658 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 }
2660
2661 /// \brief Build a new C++ throw expression.
2662 ///
2663 /// By default, performs semantic analysis to build the new expression.
2664 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002665 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2666 bool IsThrownVariableInScope) {
2667 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 }
2669
2670 /// \brief Build a new C++ default-argument expression.
2671 ///
2672 /// By default, builds a new default-argument expression, which does not
2673 /// require any semantic analysis. Subclasses may override this routine to
2674 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002675 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002676 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002677 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002678 }
2679
Richard Smith852c9db2013-04-20 22:23:05 +00002680 /// \brief Build a new C++11 default-initialization expression.
2681 ///
2682 /// By default, builds a new default field initialization expression, which
2683 /// does not require any semantic analysis. Subclasses may override this
2684 /// routine to provide different behavior.
2685 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2686 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002687 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002688 }
2689
Douglas Gregora16548e2009-08-11 05:31:07 +00002690 /// \brief Build a new C++ zero-initialization expression.
2691 ///
2692 /// By default, performs semantic analysis to build the new expression.
2693 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002694 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2695 SourceLocation LParenLoc,
2696 SourceLocation RParenLoc) {
2697 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002698 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002699 }
Mike Stump11289f42009-09-09 15:08:12 +00002700
Douglas Gregora16548e2009-08-11 05:31:07 +00002701 /// \brief Build a new C++ "new" expression.
2702 ///
2703 /// By default, performs semantic analysis to build the new expression.
2704 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002705 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002706 bool UseGlobal,
2707 SourceLocation PlacementLParen,
2708 MultiExprArg PlacementArgs,
2709 SourceLocation PlacementRParen,
2710 SourceRange TypeIdParens,
2711 QualType AllocatedType,
2712 TypeSourceInfo *AllocatedTypeInfo,
2713 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002714 SourceRange DirectInitRange,
2715 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002716 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002717 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002718 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002720 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002721 AllocatedType,
2722 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002723 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002724 DirectInitRange,
2725 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002726 }
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 /// \brief Build a new C++ "delete" expression.
2729 ///
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002732 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002733 bool IsGlobalDelete,
2734 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002735 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002736 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002737 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002738 }
Mike Stump11289f42009-09-09 15:08:12 +00002739
Douglas Gregor29c42f22012-02-24 07:38:34 +00002740 /// \brief Build a new type trait expression.
2741 ///
2742 /// By default, performs semantic analysis to build the new expression.
2743 /// Subclasses may override this routine to provide different behavior.
2744 ExprResult RebuildTypeTrait(TypeTrait Trait,
2745 SourceLocation StartLoc,
2746 ArrayRef<TypeSourceInfo *> Args,
2747 SourceLocation RParenLoc) {
2748 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2749 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002750
John Wiegley6242b6a2011-04-28 00:16:57 +00002751 /// \brief Build a new array type 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2756 SourceLocation StartLoc,
2757 TypeSourceInfo *TSInfo,
2758 Expr *DimExpr,
2759 SourceLocation RParenLoc) {
2760 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2761 }
2762
John Wiegleyf9f65842011-04-25 06:54:41 +00002763 /// \brief Build a new expression trait expression.
2764 ///
2765 /// By default, performs semantic analysis to build the new expression.
2766 /// Subclasses may override this routine to provide different behavior.
2767 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2768 SourceLocation StartLoc,
2769 Expr *Queried,
2770 SourceLocation RParenLoc) {
2771 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2772 }
2773
Mike Stump11289f42009-09-09 15:08:12 +00002774 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002775 /// expression.
2776 ///
2777 /// By default, performs semantic analysis to build the new expression.
2778 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002779 ExprResult RebuildDependentScopeDeclRefExpr(
2780 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002781 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002782 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002783 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002784 bool IsAddressOfOperand,
2785 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002786 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002787 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002788
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002789 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002790 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2791 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002792
Reid Kleckner32506ed2014-06-12 23:03:48 +00002793 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002794 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002795 }
2796
2797 /// \brief Build a new template-id expression.
2798 ///
2799 /// By default, performs semantic analysis to build the new expression.
2800 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002801 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002802 SourceLocation TemplateKWLoc,
2803 LookupResult &R,
2804 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002805 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002806 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2807 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002808 }
2809
2810 /// \brief Build a new object-construction expression.
2811 ///
2812 /// By default, performs semantic analysis to build the new expression.
2813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002814 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002815 SourceLocation Loc,
2816 CXXConstructorDecl *Constructor,
2817 bool IsElidable,
2818 MultiExprArg Args,
2819 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002820 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002821 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002822 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002823 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002824 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002825 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002826 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002827 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002828 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002829
Richard Smithc83bf822016-06-10 00:58:19 +00002830 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002831 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002832 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002833 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002834 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002835 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002836 RequiresZeroInit, ConstructKind,
2837 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002838 }
2839
Richard Smith5179eb72016-06-28 19:03:57 +00002840 /// \brief Build a new implicit construction via inherited constructor
2841 /// expression.
2842 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2843 CXXConstructorDecl *Constructor,
2844 bool ConstructsVBase,
2845 bool InheritedFromVBase) {
2846 return new (getSema().Context) CXXInheritedCtorInitExpr(
2847 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2848 }
2849
Douglas Gregora16548e2009-08-11 05:31:07 +00002850 /// \brief Build a new object-construction expression.
2851 ///
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002854 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2855 SourceLocation LParenLoc,
2856 MultiExprArg Args,
2857 SourceLocation RParenLoc) {
2858 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002859 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002860 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002861 RParenLoc);
2862 }
2863
2864 /// \brief Build a new object-construction expression.
2865 ///
2866 /// By default, performs semantic analysis to build the new expression.
2867 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002868 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2869 SourceLocation LParenLoc,
2870 MultiExprArg Args,
2871 SourceLocation RParenLoc) {
2872 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002873 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002874 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002875 RParenLoc);
2876 }
Mike Stump11289f42009-09-09 15:08:12 +00002877
Douglas Gregora16548e2009-08-11 05:31:07 +00002878 /// \brief Build a new member reference expression.
2879 ///
2880 /// By default, performs semantic analysis to build the new expression.
2881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002882 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002883 QualType BaseType,
2884 bool IsArrow,
2885 SourceLocation OperatorLoc,
2886 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002887 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002888 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002889 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002890 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002891 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002892 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002893
John McCallb268a282010-08-23 23:25:46 +00002894 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002895 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002896 SS, TemplateKWLoc,
2897 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002898 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002899 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002900 }
2901
John McCall10eae182009-11-30 22:42:35 +00002902 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002903 ///
2904 /// By default, performs semantic analysis to build the new expression.
2905 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002906 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2907 SourceLocation OperatorLoc,
2908 bool IsArrow,
2909 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002910 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002911 NamedDecl *FirstQualifierInScope,
2912 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002913 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002914 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002915 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002916
John McCallb268a282010-08-23 23:25:46 +00002917 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002918 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002919 SS, TemplateKWLoc,
2920 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002921 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002922 }
Mike Stump11289f42009-09-09 15:08:12 +00002923
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002924 /// \brief Build a new noexcept expression.
2925 ///
2926 /// By default, performs semantic analysis to build the new expression.
2927 /// Subclasses may override this routine to provide different behavior.
2928 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2929 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2930 }
2931
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002932 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002933 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2934 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002935 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002936 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002937 Optional<unsigned> Length,
2938 ArrayRef<TemplateArgument> PartialArgs) {
2939 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2940 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002941 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002942
Patrick Beard0caa3942012-04-19 00:25:12 +00002943 /// \brief Build a new Objective-C boxed expression.
2944 ///
2945 /// By default, performs semantic analysis to build the new expression.
2946 /// Subclasses may override this routine to provide different behavior.
2947 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2948 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002950
Ted Kremeneke65b0862012-03-06 20:05:56 +00002951 /// \brief Build a new Objective-C array literal.
2952 ///
2953 /// By default, performs semantic analysis to build the new expression.
2954 /// Subclasses may override this routine to provide different behavior.
2955 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2956 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002957 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002958 MultiExprArg(Elements, NumElements));
2959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
2961 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002962 Expr *Base, Expr *Key,
2963 ObjCMethodDecl *getterMethod,
2964 ObjCMethodDecl *setterMethod) {
2965 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2966 getterMethod, setterMethod);
2967 }
2968
2969 /// \brief Build a new Objective-C dictionary literal.
2970 ///
2971 /// By default, performs semantic analysis to build the new expression.
2972 /// Subclasses may override this routine to provide different behavior.
2973 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002974 MutableArrayRef<ObjCDictionaryElement> Elements) {
2975 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002977
James Dennett2a4d13c2012-06-15 07:13:21 +00002978 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002979 ///
2980 /// By default, performs semantic analysis to build the new expression.
2981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002982 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002983 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002984 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002985 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002986 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002987
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002988 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002989 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002990 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002991 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002992 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002993 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002994 MultiExprArg Args,
2995 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002996 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2997 ReceiverTypeInfo->getType(),
2998 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002999 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003000 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003001 }
3002
3003 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003004 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003005 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003006 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003007 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003008 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003009 MultiExprArg Args,
3010 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003011 return SemaRef.BuildInstanceMessage(Receiver,
3012 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003013 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003014 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003015 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003016 }
3017
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003018 /// \brief Build a new Objective-C instance/class message to 'super'.
3019 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3020 Selector Sel,
3021 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003022 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003023 ObjCMethodDecl *Method,
3024 SourceLocation LBracLoc,
3025 MultiExprArg Args,
3026 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003027 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003028 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003029 SuperLoc,
3030 Sel, Method, LBracLoc, SelectorLocs,
3031 RBracLoc, Args)
3032 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003033 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003034 SuperLoc,
3035 Sel, Method, LBracLoc, SelectorLocs,
3036 RBracLoc, Args);
3037
3038
3039 }
3040
Douglas Gregord51d90d2010-04-26 20:11:03 +00003041 /// \brief Build a new Objective-C ivar reference expression.
3042 ///
3043 /// By default, performs semantic analysis to build the new expression.
3044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003045 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003046 SourceLocation IvarLoc,
3047 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003048 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003049 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003050 ExprResult Result = getSema().BuildMemberReferenceExpr(
3051 BaseArg, BaseArg->getType(),
3052 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3053 /*FirstQualifierInScope=*/nullptr, NameInfo,
3054 /*TemplateArgs=*/nullptr,
3055 /*S=*/nullptr);
3056 if (IsFreeIvar && Result.isUsable())
3057 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3058 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003059 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003060
3061 /// \brief Build a new Objective-C property reference expression.
3062 ///
3063 /// By default, performs semantic analysis to build the new expression.
3064 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003065 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003066 ObjCPropertyDecl *Property,
3067 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003068 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003069 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3070 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3071 /*FIXME:*/PropertyLoc,
3072 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003073 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003074 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003075 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003076 /*TemplateArgs=*/nullptr,
3077 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003078 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003079
John McCallb7bd14f2010-12-02 01:19:52 +00003080 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003081 ///
3082 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003083 /// Subclasses may override this routine to provide different behavior.
3084 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3085 ObjCMethodDecl *Getter,
3086 ObjCMethodDecl *Setter,
3087 SourceLocation PropertyLoc) {
3088 // Since these expressions can only be value-dependent, we do not
3089 // need to perform semantic analysis again.
3090 return Owned(
3091 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3092 VK_LValue, OK_ObjCProperty,
3093 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003094 }
3095
Douglas Gregord51d90d2010-04-26 20:11:03 +00003096 /// \brief Build a new Objective-C "isa" expression.
3097 ///
3098 /// By default, performs semantic analysis to build the new expression.
3099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003100 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003101 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003102 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003103 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3104 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003105 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003106 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003107 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003108 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003109 /*TemplateArgs=*/nullptr,
3110 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003111 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003112
Douglas Gregora16548e2009-08-11 05:31:07 +00003113 /// \brief Build a new shuffle vector expression.
3114 ///
3115 /// By default, performs semantic analysis to build the new expression.
3116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003117 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003118 MultiExprArg SubExprs,
3119 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003120 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003121 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003122 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3123 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3124 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003125 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003126
Douglas Gregora16548e2009-08-11 05:31:07 +00003127 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003128 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003129 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3130 SemaRef.Context.BuiltinFnTy,
3131 VK_RValue, BuiltinLoc);
3132 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3133 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003134 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003135
3136 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003137 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003138 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003139 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003140
Douglas Gregora16548e2009-08-11 05:31:07 +00003141 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003142 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003143 }
John McCall31f82722010-11-12 08:19:04 +00003144
Hal Finkelc4d7c822013-09-18 03:29:45 +00003145 /// \brief Build a new convert vector expression.
3146 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3147 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3148 SourceLocation RParenLoc) {
3149 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3150 BuiltinLoc, RParenLoc);
3151 }
3152
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003153 /// \brief Build a new template argument pack expansion.
3154 ///
3155 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003156 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003157 /// different behavior.
3158 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003159 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003160 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003161 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003162 case TemplateArgument::Expression: {
3163 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003164 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3165 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003166 if (Result.isInvalid())
3167 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003168
Douglas Gregor98318c22011-01-03 21:37:45 +00003169 return TemplateArgumentLoc(Result.get(), Result.get());
3170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003171
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003172 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003173 return TemplateArgumentLoc(TemplateArgument(
3174 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003175 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003176 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003177 Pattern.getTemplateNameLoc(),
3178 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003179
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003180 case TemplateArgument::Null:
3181 case TemplateArgument::Integral:
3182 case TemplateArgument::Declaration:
3183 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003184 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003185 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003186 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003187
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003188 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003189 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003190 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003191 EllipsisLoc,
3192 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003193 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3194 Expansion);
3195 break;
3196 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003198 return TemplateArgumentLoc();
3199 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003200
Douglas Gregor968f23a2011-01-03 19:31:53 +00003201 /// \brief Build a new expression pack expansion.
3202 ///
3203 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003204 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003205 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003206 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003207 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003208 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003209 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003210
Richard Smith0f0af192014-11-08 05:07:16 +00003211 /// \brief Build a new C++1z fold-expression.
3212 ///
3213 /// By default, performs semantic analysis in order to build a new fold
3214 /// expression.
3215 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3216 BinaryOperatorKind Operator,
3217 SourceLocation EllipsisLoc, Expr *RHS,
3218 SourceLocation RParenLoc) {
3219 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3220 RHS, RParenLoc);
3221 }
3222
3223 /// \brief Build an empty C++1z fold-expression with the given operator.
3224 ///
3225 /// By default, produces the fallback value for the fold-expression, or
3226 /// produce an error if there is no fallback value.
3227 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3228 BinaryOperatorKind Operator) {
3229 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3230 }
3231
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003232 /// \brief Build a new atomic operation expression.
3233 ///
3234 /// By default, performs semantic analysis to build the new expression.
3235 /// Subclasses may override this routine to provide different behavior.
3236 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3237 MultiExprArg SubExprs,
3238 QualType RetTy,
3239 AtomicExpr::AtomicOp Op,
3240 SourceLocation RParenLoc) {
3241 // Just create the expression; there is not any interesting semantic
3242 // analysis here because we can't actually build an AtomicExpr until
3243 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003244 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003245 RParenLoc);
3246 }
3247
John McCall31f82722010-11-12 08:19:04 +00003248private:
Douglas Gregor14454802011-02-25 02:25:35 +00003249 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3250 QualType ObjectType,
3251 NamedDecl *FirstQualifierInScope,
3252 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003253
3254 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3255 QualType ObjectType,
3256 NamedDecl *FirstQualifierInScope,
3257 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003258
3259 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3260 NamedDecl *FirstQualifierInScope,
3261 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003262
3263 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3264 DependentNameTypeLoc TL,
3265 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266};
Douglas Gregora16548e2009-08-11 05:31:07 +00003267
Douglas Gregorebe10102009-08-20 07:17:43 +00003268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003269StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003270 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003271 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003272
Douglas Gregorebe10102009-08-20 07:17:43 +00003273 switch (S->getStmtClass()) {
3274 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003275
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 // Transform individual statement nodes
3277#define STMT(Node, Parent) \
3278 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003279#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003280#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003281#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003282
Douglas Gregorebe10102009-08-20 07:17:43 +00003283 // Transform expressions by calling TransformExpr.
3284#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003285#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003286#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003287#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003288 {
John McCalldadc5752010-08-24 06:29:42 +00003289 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003290 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003291 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003292
Richard Smith945f8d32013-01-14 22:39:08 +00003293 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003294 }
Mike Stump11289f42009-09-09 15:08:12 +00003295 }
3296
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003297 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003298}
Mike Stump11289f42009-09-09 15:08:12 +00003299
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003300template<typename Derived>
3301OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3302 if (!S)
3303 return S;
3304
3305 switch (S->getClauseKind()) {
3306 default: break;
3307 // Transform individual clause nodes
3308#define OPENMP_CLAUSE(Name, Class) \
3309 case OMPC_ ## Name : \
3310 return getDerived().Transform ## Class(cast<Class>(S));
3311#include "clang/Basic/OpenMPKinds.def"
3312 }
3313
3314 return S;
3315}
3316
Mike Stump11289f42009-09-09 15:08:12 +00003317
Douglas Gregore922c772009-08-04 22:27:00 +00003318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003319ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003320 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003321 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003322
3323 switch (E->getStmtClass()) {
3324 case Stmt::NoStmtClass: break;
3325#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003326#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003327#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003328 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003329#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003330 }
3331
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003332 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003333}
3334
3335template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003336ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003337 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003338 // Initializers are instantiated like expressions, except that various outer
3339 // layers are stripped.
3340 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003341 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003342
3343 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3344 Init = ExprTemp->getSubExpr();
3345
Richard Smith410306b2016-12-12 02:53:20 +00003346 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3347 Init = AIL->getCommonExpr();
3348
Richard Smithe6ca4752013-05-30 22:40:16 +00003349 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3350 Init = MTE->GetTemporaryExpr();
3351
Richard Smithd59b8322012-12-19 01:39:02 +00003352 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3353 Init = Binder->getSubExpr();
3354
3355 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3356 Init = ICE->getSubExprAsWritten();
3357
Richard Smithcc1b96d2013-06-12 22:31:48 +00003358 if (CXXStdInitializerListExpr *ILE =
3359 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003360 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003361
Richard Smithc6abd962014-07-25 01:12:44 +00003362 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003363 // InitListExprs. Other forms of copy-initialization will be a no-op if
3364 // the initializer is already the right type.
3365 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003366 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003367 return getDerived().TransformExpr(Init);
3368
3369 // Revert value-initialization back to empty parens.
3370 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3371 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003372 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003373 Parens.getEnd());
3374 }
3375
3376 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3377 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003378 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003379 SourceLocation());
3380
3381 // Revert initialization by constructor back to a parenthesized or braced list
3382 // of expressions. Any other form of initializer can just be reused directly.
3383 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003384 return getDerived().TransformExpr(Init);
3385
Richard Smithf8adcdc2014-07-17 05:12:35 +00003386 // If the initialization implicitly converted an initializer list to a
3387 // std::initializer_list object, unwrap the std::initializer_list too.
3388 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003389 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003390
Richard Smithd59b8322012-12-19 01:39:02 +00003391 SmallVector<Expr*, 8> NewArgs;
3392 bool ArgChanged = false;
3393 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003394 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003395 return ExprError();
3396
3397 // If this was list initialization, revert to list form.
3398 if (Construct->isListInitialization())
3399 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3400 Construct->getLocEnd(),
3401 Construct->getType());
3402
Richard Smithd59b8322012-12-19 01:39:02 +00003403 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003404 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003405 if (Parens.isInvalid()) {
3406 // This was a variable declaration's initialization for which no initializer
3407 // was specified.
3408 assert(NewArgs.empty() &&
3409 "no parens or braces but have direct init with arguments?");
3410 return ExprEmpty();
3411 }
Richard Smithd59b8322012-12-19 01:39:02 +00003412 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3413 Parens.getEnd());
3414}
3415
3416template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003417bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003418 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003419 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003420 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003421 bool *ArgChanged) {
3422 for (unsigned I = 0; I != NumInputs; ++I) {
3423 // If requested, drop call arguments that need to be dropped.
3424 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3425 if (ArgChanged)
3426 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregora3efea12011-01-03 19:04:46 +00003428 break;
3429 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Douglas Gregor968f23a2011-01-03 19:31:53 +00003431 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3432 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Chris Lattner01cf8db2011-07-20 06:58:45 +00003434 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003435 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3436 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor968f23a2011-01-03 19:31:53 +00003438 // Determine whether the set of unexpanded parameter packs can and should
3439 // be expanded.
3440 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003441 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003442 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3443 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003444 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3445 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003446 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003447 Expand, RetainExpansion,
3448 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003449 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
Douglas Gregor968f23a2011-01-03 19:31:53 +00003451 if (!Expand) {
3452 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003453 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003454 // expansion.
3455 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3456 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3457 if (OutPattern.isInvalid())
3458 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
3460 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003461 Expansion->getEllipsisLoc(),
3462 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003463 if (Out.isInvalid())
3464 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003465
Douglas Gregor968f23a2011-01-03 19:31:53 +00003466 if (ArgChanged)
3467 *ArgChanged = true;
3468 Outputs.push_back(Out.get());
3469 continue;
3470 }
John McCall542e7c62011-07-06 07:30:07 +00003471
3472 // Record right away that the argument was changed. This needs
3473 // to happen even if the array expands to nothing.
3474 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003475
Douglas Gregor968f23a2011-01-03 19:31:53 +00003476 // The transform has determined that we should perform an elementwise
3477 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003478 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003479 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3480 ExprResult Out = getDerived().TransformExpr(Pattern);
3481 if (Out.isInvalid())
3482 return true;
3483
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003484 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003485 Out = getDerived().RebuildPackExpansion(
3486 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003487 if (Out.isInvalid())
3488 return true;
3489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor968f23a2011-01-03 19:31:53 +00003491 Outputs.push_back(Out.get());
3492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Richard Smith9467be42014-06-06 17:33:35 +00003494 // If we're supposed to retain a pack expansion, do so by temporarily
3495 // forgetting the partially-substituted parameter pack.
3496 if (RetainExpansion) {
3497 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3498
3499 ExprResult Out = getDerived().TransformExpr(Pattern);
3500 if (Out.isInvalid())
3501 return true;
3502
3503 Out = getDerived().RebuildPackExpansion(
3504 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3505 if (Out.isInvalid())
3506 return true;
3507
3508 Outputs.push_back(Out.get());
3509 }
3510
Douglas Gregor968f23a2011-01-03 19:31:53 +00003511 continue;
3512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Richard Smithd59b8322012-12-19 01:39:02 +00003514 ExprResult Result =
3515 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3516 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003517 if (Result.isInvalid())
3518 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregora3efea12011-01-03 19:04:46 +00003520 if (Result.get() != Inputs[I] && ArgChanged)
3521 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003522
3523 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregora3efea12011-01-03 19:04:46 +00003526 return false;
3527}
3528
Richard Smith03a4aa32016-06-23 19:02:52 +00003529template <typename Derived>
3530Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3531 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3532 if (Var) {
3533 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3534 getDerived().TransformDefinition(Var->getLocation(), Var));
3535
3536 if (!ConditionVar)
3537 return Sema::ConditionError();
3538
3539 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3540 }
3541
3542 if (Expr) {
3543 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3544
3545 if (CondExpr.isInvalid())
3546 return Sema::ConditionError();
3547
3548 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3549 }
3550
3551 return Sema::ConditionResult();
3552}
3553
Douglas Gregora3efea12011-01-03 19:04:46 +00003554template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003555NestedNameSpecifierLoc
3556TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3557 NestedNameSpecifierLoc NNS,
3558 QualType ObjectType,
3559 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003560 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003561 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003562 Qualifier = Qualifier.getPrefix())
3563 Qualifiers.push_back(Qualifier);
3564
3565 CXXScopeSpec SS;
3566 while (!Qualifiers.empty()) {
3567 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3568 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003569
Douglas Gregor14454802011-02-25 02:25:35 +00003570 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003571 case NestedNameSpecifier::Identifier: {
3572 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3573 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3574 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3575 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003576 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003577 }
Douglas Gregor14454802011-02-25 02:25:35 +00003578 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003579
Douglas Gregor14454802011-02-25 02:25:35 +00003580 case NestedNameSpecifier::Namespace: {
3581 NamespaceDecl *NS
3582 = cast_or_null<NamespaceDecl>(
3583 getDerived().TransformDecl(
3584 Q.getLocalBeginLoc(),
3585 QNNS->getAsNamespace()));
3586 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3587 break;
3588 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
Douglas Gregor14454802011-02-25 02:25:35 +00003590 case NestedNameSpecifier::NamespaceAlias: {
3591 NamespaceAliasDecl *Alias
3592 = cast_or_null<NamespaceAliasDecl>(
3593 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3594 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003595 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003596 Q.getLocalEndLoc());
3597 break;
3598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
Douglas Gregor14454802011-02-25 02:25:35 +00003600 case NestedNameSpecifier::Global:
3601 // There is no meaningful transformation that one could perform on the
3602 // global scope.
3603 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3604 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Nikola Smiljanic67860242014-09-26 00:28:20 +00003606 case NestedNameSpecifier::Super: {
3607 CXXRecordDecl *RD =
3608 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3609 SourceLocation(), QNNS->getAsRecordDecl()));
3610 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3611 break;
3612 }
3613
Douglas Gregor14454802011-02-25 02:25:35 +00003614 case NestedNameSpecifier::TypeSpecWithTemplate:
3615 case NestedNameSpecifier::TypeSpec: {
3616 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3617 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor14454802011-02-25 02:25:35 +00003619 if (!TL)
3620 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003621
Douglas Gregor14454802011-02-25 02:25:35 +00003622 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003623 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003624 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003625 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003626 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003627 if (TL.getType()->isEnumeralType())
3628 SemaRef.Diag(TL.getBeginLoc(),
3629 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003630 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3631 Q.getLocalEndLoc());
3632 break;
3633 }
Richard Trieude756fb2011-05-07 01:36:37 +00003634 // If the nested-name-specifier is an invalid type def, don't emit an
3635 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003636 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3637 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003638 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003639 << TL.getType() << SS.getRange();
3640 }
Douglas Gregor14454802011-02-25 02:25:35 +00003641 return NestedNameSpecifierLoc();
3642 }
Douglas Gregore16af532011-02-28 18:50:33 +00003643 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003644
Douglas Gregore16af532011-02-28 18:50:33 +00003645 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003646 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003647 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003648 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003649
Douglas Gregor14454802011-02-25 02:25:35 +00003650 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003651 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003652 !getDerived().AlwaysRebuild())
3653 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
3655 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003656 // nested-name-specifier, do so.
3657 if (SS.location_size() == NNS.getDataLength() &&
3658 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3659 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3660
3661 // Allocate new nested-name-specifier location information.
3662 return SS.getWithLocInContext(SemaRef.Context);
3663}
3664
3665template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003666DeclarationNameInfo
3667TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003668::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003669 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003670 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003671 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003672
3673 switch (Name.getNameKind()) {
3674 case DeclarationName::Identifier:
3675 case DeclarationName::ObjCZeroArgSelector:
3676 case DeclarationName::ObjCOneArgSelector:
3677 case DeclarationName::ObjCMultiArgSelector:
3678 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003679 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003680 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003681 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003682
Richard Smith35845152017-02-07 01:37:30 +00003683 case DeclarationName::CXXDeductionGuideName: {
3684 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3685 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3686 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3687 if (!NewTemplate)
3688 return DeclarationNameInfo();
3689
3690 DeclarationNameInfo NewNameInfo(NameInfo);
3691 NewNameInfo.setName(
3692 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3693 return NewNameInfo;
3694 }
3695
Douglas Gregorf816bd72009-09-03 22:13:48 +00003696 case DeclarationName::CXXConstructorName:
3697 case DeclarationName::CXXDestructorName:
3698 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003699 TypeSourceInfo *NewTInfo;
3700 CanQualType NewCanTy;
3701 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003702 NewTInfo = getDerived().TransformType(OldTInfo);
3703 if (!NewTInfo)
3704 return DeclarationNameInfo();
3705 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003706 }
3707 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003708 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003709 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003710 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003711 if (NewT.isNull())
3712 return DeclarationNameInfo();
3713 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3714 }
Mike Stump11289f42009-09-09 15:08:12 +00003715
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003716 DeclarationName NewName
3717 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3718 NewCanTy);
3719 DeclarationNameInfo NewNameInfo(NameInfo);
3720 NewNameInfo.setName(NewName);
3721 NewNameInfo.setNamedTypeInfo(NewTInfo);
3722 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003723 }
Mike Stump11289f42009-09-09 15:08:12 +00003724 }
3725
David Blaikie83d382b2011-09-23 05:06:16 +00003726 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003727}
3728
3729template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003730TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003731TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3732 TemplateName Name,
3733 SourceLocation NameLoc,
3734 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003735 NamedDecl *FirstQualifierInScope,
3736 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003737 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3738 TemplateDecl *Template = QTN->getTemplateDecl();
3739 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003740
Douglas Gregor9db53502011-03-02 18:07:45 +00003741 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003742 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003743 Template));
3744 if (!TransTemplate)
3745 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
Douglas Gregor9db53502011-03-02 18:07:45 +00003747 if (!getDerived().AlwaysRebuild() &&
3748 SS.getScopeRep() == QTN->getQualifier() &&
3749 TransTemplate == Template)
3750 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003751
Douglas Gregor9db53502011-03-02 18:07:45 +00003752 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3753 TransTemplate);
3754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
Douglas Gregor9db53502011-03-02 18:07:45 +00003756 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3757 if (SS.getScopeRep()) {
3758 // These apply to the scope specifier, not the template.
3759 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003760 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003761 }
3762
Douglas Gregor9db53502011-03-02 18:07:45 +00003763 if (!getDerived().AlwaysRebuild() &&
3764 SS.getScopeRep() == DTN->getQualifier() &&
3765 ObjectType.isNull())
3766 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003767
Douglas Gregor9db53502011-03-02 18:07:45 +00003768 if (DTN->isIdentifier()) {
3769 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003770 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003771 NameLoc,
3772 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003773 FirstQualifierInScope,
3774 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003776
Douglas Gregor9db53502011-03-02 18:07:45 +00003777 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003778 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003779 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003780
Douglas Gregor9db53502011-03-02 18:07:45 +00003781 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3782 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003783 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003784 Template));
3785 if (!TransTemplate)
3786 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003787
Douglas Gregor9db53502011-03-02 18:07:45 +00003788 if (!getDerived().AlwaysRebuild() &&
3789 TransTemplate == Template)
3790 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
Douglas Gregor9db53502011-03-02 18:07:45 +00003792 return TemplateName(TransTemplate);
3793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003794
Douglas Gregor9db53502011-03-02 18:07:45 +00003795 if (SubstTemplateTemplateParmPackStorage *SubstPack
3796 = Name.getAsSubstTemplateTemplateParmPack()) {
3797 TemplateTemplateParmDecl *TransParam
3798 = cast_or_null<TemplateTemplateParmDecl>(
3799 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3800 if (!TransParam)
3801 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003802
Douglas Gregor9db53502011-03-02 18:07:45 +00003803 if (!getDerived().AlwaysRebuild() &&
3804 TransParam == SubstPack->getParameterPack())
3805 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003806
3807 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003808 SubstPack->getArgumentPack());
3809 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003810
Douglas Gregor9db53502011-03-02 18:07:45 +00003811 // These should be getting filtered out before they reach the AST.
3812 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003813}
3814
3815template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003816void TreeTransform<Derived>::InventTemplateArgumentLoc(
3817 const TemplateArgument &Arg,
3818 TemplateArgumentLoc &Output) {
3819 SourceLocation Loc = getDerived().getBaseLocation();
3820 switch (Arg.getKind()) {
3821 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003822 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003823 break;
3824
3825 case TemplateArgument::Type:
3826 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003827 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003828
John McCall0ad16662009-10-29 08:12:44 +00003829 break;
3830
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003831 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003832 case TemplateArgument::TemplateExpansion: {
3833 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003834 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003835 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3836 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3837 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3838 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003839
Douglas Gregor9d802122011-03-02 17:09:35 +00003840 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003841 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003842 Builder.getWithLocInContext(SemaRef.Context),
3843 Loc);
3844 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003845 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003846 Builder.getWithLocInContext(SemaRef.Context),
3847 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003848
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003849 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003850 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003851
John McCall0ad16662009-10-29 08:12:44 +00003852 case TemplateArgument::Expression:
3853 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3854 break;
3855
3856 case TemplateArgument::Declaration:
3857 case TemplateArgument::Integral:
3858 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003859 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003860 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003861 break;
3862 }
3863}
3864
3865template<typename Derived>
3866bool TreeTransform<Derived>::TransformTemplateArgument(
3867 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003868 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003869 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003870 switch (Arg.getKind()) {
3871 case TemplateArgument::Null:
3872 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003873 case TemplateArgument::Pack:
3874 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003875 case TemplateArgument::NullPtr:
3876 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003877
Douglas Gregore922c772009-08-04 22:27:00 +00003878 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003879 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003880 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003881 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003882
3883 DI = getDerived().TransformType(DI);
3884 if (!DI) return true;
3885
3886 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3887 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003888 }
Mike Stump11289f42009-09-09 15:08:12 +00003889
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003890 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003891 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3892 if (QualifierLoc) {
3893 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3894 if (!QualifierLoc)
3895 return true;
3896 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003897
Douglas Gregordf846d12011-03-02 18:46:51 +00003898 CXXScopeSpec SS;
3899 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003900 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003901 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3902 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003903 if (Template.isNull())
3904 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003905
Douglas Gregor9d802122011-03-02 17:09:35 +00003906 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003907 Input.getTemplateNameLoc());
3908 return false;
3909 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003910
3911 case TemplateArgument::TemplateExpansion:
3912 llvm_unreachable("Caller should expand pack expansions");
3913
Douglas Gregore922c772009-08-04 22:27:00 +00003914 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003915 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003916 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003917 getSema(), Uneval
3918 ? Sema::ExpressionEvaluationContext::Unevaluated
3919 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003920
John McCall0ad16662009-10-29 08:12:44 +00003921 Expr *InputExpr = Input.getSourceExpression();
3922 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3923
Chris Lattnercdb591a2011-04-25 20:37:58 +00003924 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003925 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003926 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003927 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003928 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003929 }
Douglas Gregore922c772009-08-04 22:27:00 +00003930 }
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregore922c772009-08-04 22:27:00 +00003932 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003933 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003934}
3935
Douglas Gregorfe921a72010-12-20 23:36:19 +00003936/// \brief Iterator adaptor that invents template argument location information
3937/// for each of the template arguments in its underlying iterator.
3938template<typename Derived, typename InputIterator>
3939class TemplateArgumentLocInventIterator {
3940 TreeTransform<Derived> &Self;
3941 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003942
Douglas Gregorfe921a72010-12-20 23:36:19 +00003943public:
3944 typedef TemplateArgumentLoc value_type;
3945 typedef TemplateArgumentLoc reference;
3946 typedef typename std::iterator_traits<InputIterator>::difference_type
3947 difference_type;
3948 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003949
Douglas Gregorfe921a72010-12-20 23:36:19 +00003950 class pointer {
3951 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003952
Douglas Gregorfe921a72010-12-20 23:36:19 +00003953 public:
3954 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003955
Douglas Gregorfe921a72010-12-20 23:36:19 +00003956 const TemplateArgumentLoc *operator->() const { return &Arg; }
3957 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003958
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003959 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003960
Douglas Gregorfe921a72010-12-20 23:36:19 +00003961 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3962 InputIterator Iter)
3963 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003964
Douglas Gregorfe921a72010-12-20 23:36:19 +00003965 TemplateArgumentLocInventIterator &operator++() {
3966 ++Iter;
3967 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003968 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003969
Douglas Gregorfe921a72010-12-20 23:36:19 +00003970 TemplateArgumentLocInventIterator operator++(int) {
3971 TemplateArgumentLocInventIterator Old(*this);
3972 ++(*this);
3973 return Old;
3974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003975
Douglas Gregorfe921a72010-12-20 23:36:19 +00003976 reference operator*() const {
3977 TemplateArgumentLoc Result;
3978 Self.InventTemplateArgumentLoc(*Iter, Result);
3979 return Result;
3980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003981
Douglas Gregorfe921a72010-12-20 23:36:19 +00003982 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003983
Douglas Gregorfe921a72010-12-20 23:36:19 +00003984 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3985 const TemplateArgumentLocInventIterator &Y) {
3986 return X.Iter == Y.Iter;
3987 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003988
Douglas Gregorfe921a72010-12-20 23:36:19 +00003989 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3990 const TemplateArgumentLocInventIterator &Y) {
3991 return X.Iter != Y.Iter;
3992 }
3993};
Chad Rosier1dcde962012-08-08 18:46:20 +00003994
Douglas Gregor42cafa82010-12-20 17:42:22 +00003995template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003996template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003997bool TreeTransform<Derived>::TransformTemplateArguments(
3998 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3999 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004000 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004001 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004002 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004003
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004004 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4005 // Unpack argument packs, which we translate them into separate
4006 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004007 // FIXME: We could do much better if we could guarantee that the
4008 // TemplateArgumentLocInfo for the pack expansion would be usable for
4009 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004010 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004011 TemplateArgument::pack_iterator>
4012 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004013 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004014 In.getArgument().pack_begin()),
4015 PackLocIterator(*this,
4016 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004017 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004018 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004019
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004020 continue;
4021 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004022
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004023 if (In.getArgument().isPackExpansion()) {
4024 // We have a pack expansion, for which we will be substituting into
4025 // the pattern.
4026 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004027 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004028 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004029 = getSema().getTemplateArgumentPackExpansionPattern(
4030 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004031
Chris Lattner01cf8db2011-07-20 06:58:45 +00004032 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004033 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4034 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004035
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004036 // Determine whether the set of unexpanded parameter packs can and should
4037 // be expanded.
4038 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004039 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004040 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004041 if (getDerived().TryExpandParameterPacks(Ellipsis,
4042 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004043 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004044 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004045 RetainExpansion,
4046 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004047 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004048
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004049 if (!Expand) {
4050 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004051 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004052 // expansion.
4053 TemplateArgumentLoc OutPattern;
4054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004055 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004056 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004057
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004058 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4059 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004060 if (Out.getArgument().isNull())
4061 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004063 Outputs.addArgument(Out);
4064 continue;
4065 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004066
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004067 // The transform has determined that we should perform an elementwise
4068 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004069 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4071
Richard Smithd784e682015-09-23 21:41:42 +00004072 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004073 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004075 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004076 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4077 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004078 if (Out.getArgument().isNull())
4079 return true;
4080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004081
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004082 Outputs.addArgument(Out);
4083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004084
Douglas Gregor48d24112011-01-10 20:53:55 +00004085 // If we're supposed to retain a pack expansion, do so by temporarily
4086 // forgetting the partially-substituted parameter pack.
4087 if (RetainExpansion) {
4088 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004089
Richard Smithd784e682015-09-23 21:41:42 +00004090 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004091 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004092
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004093 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4094 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004095 if (Out.getArgument().isNull())
4096 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004097
Douglas Gregor48d24112011-01-10 20:53:55 +00004098 Outputs.addArgument(Out);
4099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004100
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004101 continue;
4102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004103
4104 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004105 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004106 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004107
Douglas Gregor42cafa82010-12-20 17:42:22 +00004108 Outputs.addArgument(Out);
4109 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004110
Douglas Gregor42cafa82010-12-20 17:42:22 +00004111 return false;
4112
4113}
4114
Douglas Gregord6ff3322009-08-04 16:50:30 +00004115//===----------------------------------------------------------------------===//
4116// Type transformation
4117//===----------------------------------------------------------------------===//
4118
4119template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004120QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004121 if (getDerived().AlreadyTransformed(T))
4122 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004123
John McCall550e0c22009-10-21 00:40:46 +00004124 // Temporary workaround. All of these transformations should
4125 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004126 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4127 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004128
John McCall31f82722010-11-12 08:19:04 +00004129 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004130
John McCall550e0c22009-10-21 00:40:46 +00004131 if (!NewDI)
4132 return QualType();
4133
4134 return NewDI->getType();
4135}
4136
4137template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004138TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004139 // Refine the base location to the type's location.
4140 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4141 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004142 if (getDerived().AlreadyTransformed(DI->getType()))
4143 return DI;
4144
4145 TypeLocBuilder TLB;
4146
4147 TypeLoc TL = DI->getTypeLoc();
4148 TLB.reserve(TL.getFullDataSize());
4149
John McCall31f82722010-11-12 08:19:04 +00004150 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004151 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004152 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004153
John McCallbcd03502009-12-07 02:54:59 +00004154 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004155}
4156
4157template<typename Derived>
4158QualType
John McCall31f82722010-11-12 08:19:04 +00004159TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004160 switch (T.getTypeLocClass()) {
4161#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004162#define TYPELOC(CLASS, PARENT) \
4163 case TypeLoc::CLASS: \
4164 return getDerived().Transform##CLASS##Type(TLB, \
4165 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004166#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004167 }
Mike Stump11289f42009-09-09 15:08:12 +00004168
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004169 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004170}
4171
Richard Smithee579842017-01-30 20:39:26 +00004172template<typename Derived>
4173QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4174 if (!isa<DependentNameType>(T))
4175 return TransformType(T);
4176
4177 if (getDerived().AlreadyTransformed(T))
4178 return T;
4179 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4180 getDerived().getBaseLocation());
4181 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4182 return NewDI ? NewDI->getType() : QualType();
4183}
4184
4185template<typename Derived>
4186TypeSourceInfo *
4187TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4188 if (!isa<DependentNameType>(DI->getType()))
4189 return TransformType(DI);
4190
4191 // Refine the base location to the type's location.
4192 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4193 getDerived().getBaseEntity());
4194 if (getDerived().AlreadyTransformed(DI->getType()))
4195 return DI;
4196
4197 TypeLocBuilder TLB;
4198
4199 TypeLoc TL = DI->getTypeLoc();
4200 TLB.reserve(TL.getFullDataSize());
4201
Richard Smithee579842017-01-30 20:39:26 +00004202 auto QTL = TL.getAs<QualifiedTypeLoc>();
4203 if (QTL)
4204 TL = QTL.getUnqualifiedLoc();
4205
4206 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4207
4208 QualType Result = getDerived().TransformDependentNameType(
4209 TLB, DNTL, /*DeducedTSTContext*/true);
4210 if (Result.isNull())
4211 return nullptr;
4212
4213 if (QTL) {
4214 Result = getDerived().RebuildQualifiedType(
4215 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4216 TLB.TypeWasModifiedSafely(Result);
4217 }
4218
4219 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4220}
4221
John McCall550e0c22009-10-21 00:40:46 +00004222template<typename Derived>
4223QualType
4224TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004225 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004226 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004227
John McCall31f82722010-11-12 08:19:04 +00004228 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004229 if (Result.isNull())
4230 return QualType();
4231
Richard Smithee579842017-01-30 20:39:26 +00004232 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4233
4234 // RebuildQualifiedType might have updated the type, but not in a way
4235 // that invalidates the TypeLoc. (There's no location information for
4236 // qualifiers.)
4237 TLB.TypeWasModifiedSafely(Result);
4238
4239 return Result;
4240}
4241
4242template<typename Derived>
4243QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4244 SourceLocation Loc,
4245 Qualifiers Quals) {
4246 // C++ [dcl.fct]p7:
4247 // [When] adding cv-qualifications on top of the function type [...] the
4248 // cv-qualifiers are ignored.
4249 // C++ [dcl.ref]p1:
4250 // when the cv-qualifiers are introduced through the use of a typedef-name
4251 // or decltype-specifier [...] the cv-qualifiers are ignored.
4252 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4253 // applied to a reference type.
4254 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4255 if (T->isFunctionType() || T->isReferenceType())
4256 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004257
John McCall31168b02011-06-15 23:02:42 +00004258 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004259 // resulting type.
4260 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004261 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004262 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004263 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004264 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004265 // A lifetime qualifier applied to a substituted template parameter
4266 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004267 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004268 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004269 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004270 QualType Replacement = SubstTypeParam->getReplacementType();
4271 Qualifiers Qs = Replacement.getQualifiers();
4272 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004273 Replacement = SemaRef.Context.getQualifiedType(
4274 Replacement.getUnqualifiedType(), Qs);
4275 T = SemaRef.Context.getSubstTemplateTypeParmType(
4276 SubstTypeParam->getReplacedParameter(), Replacement);
4277 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004278 // 'auto' types behave the same way as template parameters.
4279 QualType Deduced = AutoTy->getDeducedType();
4280 Qualifiers Qs = Deduced.getQualifiers();
4281 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004282 Deduced =
4283 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4284 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4285 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004286 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004287 // Otherwise, complain about the addition of a qualifier to an
4288 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004289 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4290 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004291 Quals.removeObjCLifetime();
4292 }
4293 }
4294 }
John McCall550e0c22009-10-21 00:40:46 +00004295
Richard Smithee579842017-01-30 20:39:26 +00004296 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004297}
4298
Douglas Gregor14454802011-02-25 02:25:35 +00004299template<typename Derived>
4300TypeLoc
4301TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4302 QualType ObjectType,
4303 NamedDecl *UnqualLookup,
4304 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004305 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004306 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004307
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004308 TypeSourceInfo *TSI =
4309 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4310 if (TSI)
4311 return TSI->getTypeLoc();
4312 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004313}
4314
Douglas Gregor579c15f2011-03-02 18:32:08 +00004315template<typename Derived>
4316TypeSourceInfo *
4317TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4318 QualType ObjectType,
4319 NamedDecl *UnqualLookup,
4320 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004321 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004322 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004323
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004324 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4325 UnqualLookup, SS);
4326}
4327
4328template <typename Derived>
4329TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4330 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4331 CXXScopeSpec &SS) {
4332 QualType T = TL.getType();
4333 assert(!getDerived().AlreadyTransformed(T));
4334
Douglas Gregor579c15f2011-03-02 18:32:08 +00004335 TypeLocBuilder TLB;
4336 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004337
Douglas Gregor579c15f2011-03-02 18:32:08 +00004338 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004339 TemplateSpecializationTypeLoc SpecTL =
4340 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004341
Richard Smithfd3dae02017-01-20 00:20:39 +00004342 TemplateName Template = getDerived().TransformTemplateName(
4343 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4344 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004345 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004346 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
4348 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004349 Template);
4350 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004351 DependentTemplateSpecializationTypeLoc SpecTL =
4352 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004353
Douglas Gregor579c15f2011-03-02 18:32:08 +00004354 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004355 = getDerived().RebuildTemplateName(SS,
4356 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004357 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004358 ObjectType, UnqualLookup,
4359 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004360 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004361 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004362
4363 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004364 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004365 Template,
4366 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004367 } else {
4368 // Nothing special needs to be done for these.
4369 Result = getDerived().TransformType(TLB, TL);
4370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004371
4372 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004373 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004374
Douglas Gregor579c15f2011-03-02 18:32:08 +00004375 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4376}
4377
John McCall550e0c22009-10-21 00:40:46 +00004378template <class TyLoc> static inline
4379QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4380 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4381 NewT.setNameLoc(T.getNameLoc());
4382 return T.getType();
4383}
4384
John McCall550e0c22009-10-21 00:40:46 +00004385template<typename Derived>
4386QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004387 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004388 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4389 NewT.setBuiltinLoc(T.getBuiltinLoc());
4390 if (T.needsExtraLocalData())
4391 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4392 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004393}
Mike Stump11289f42009-09-09 15:08:12 +00004394
Douglas Gregord6ff3322009-08-04 16:50:30 +00004395template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004396QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004397 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004398 // FIXME: recurse?
4399 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004400}
Mike Stump11289f42009-09-09 15:08:12 +00004401
Reid Kleckner0503a872013-12-05 01:23:43 +00004402template <typename Derived>
4403QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4404 AdjustedTypeLoc TL) {
4405 // Adjustments applied during transformation are handled elsewhere.
4406 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4407}
4408
Douglas Gregord6ff3322009-08-04 16:50:30 +00004409template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004410QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4411 DecayedTypeLoc TL) {
4412 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4413 if (OriginalType.isNull())
4414 return QualType();
4415
4416 QualType Result = TL.getType();
4417 if (getDerived().AlwaysRebuild() ||
4418 OriginalType != TL.getOriginalLoc().getType())
4419 Result = SemaRef.Context.getDecayedType(OriginalType);
4420 TLB.push<DecayedTypeLoc>(Result);
4421 // Nothing to set for DecayedTypeLoc.
4422 return Result;
4423}
4424
4425template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004426QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004427 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004428 QualType PointeeType
4429 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004430 if (PointeeType.isNull())
4431 return QualType();
4432
4433 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004434 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004435 // A dependent pointer type 'T *' has is being transformed such
4436 // that an Objective-C class type is being replaced for 'T'. The
4437 // resulting pointer type is an ObjCObjectPointerType, not a
4438 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004439 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004440
John McCall8b07ec22010-05-15 11:32:37 +00004441 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4442 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004443 return Result;
4444 }
John McCall31f82722010-11-12 08:19:04 +00004445
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004446 if (getDerived().AlwaysRebuild() ||
4447 PointeeType != TL.getPointeeLoc().getType()) {
4448 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4449 if (Result.isNull())
4450 return QualType();
4451 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004452
John McCall31168b02011-06-15 23:02:42 +00004453 // Objective-C ARC can add lifetime qualifiers to the type that we're
4454 // pointing to.
4455 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004456
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004457 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4458 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004459 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004460}
Mike Stump11289f42009-09-09 15:08:12 +00004461
4462template<typename Derived>
4463QualType
John McCall550e0c22009-10-21 00:40:46 +00004464TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004465 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004466 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004467 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4468 if (PointeeType.isNull())
4469 return QualType();
4470
4471 QualType Result = TL.getType();
4472 if (getDerived().AlwaysRebuild() ||
4473 PointeeType != TL.getPointeeLoc().getType()) {
4474 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004475 TL.getSigilLoc());
4476 if (Result.isNull())
4477 return QualType();
4478 }
4479
Douglas Gregor049211a2010-04-22 16:50:51 +00004480 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004481 NewT.setSigilLoc(TL.getSigilLoc());
4482 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004483}
4484
John McCall70dd5f62009-10-30 00:06:24 +00004485/// Transforms a reference type. Note that somewhat paradoxically we
4486/// don't care whether the type itself is an l-value type or an r-value
4487/// type; we only care if the type was *written* as an l-value type
4488/// or an r-value type.
4489template<typename Derived>
4490QualType
4491TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004492 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004493 const ReferenceType *T = TL.getTypePtr();
4494
4495 // Note that this works with the pointee-as-written.
4496 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4497 if (PointeeType.isNull())
4498 return QualType();
4499
4500 QualType Result = TL.getType();
4501 if (getDerived().AlwaysRebuild() ||
4502 PointeeType != T->getPointeeTypeAsWritten()) {
4503 Result = getDerived().RebuildReferenceType(PointeeType,
4504 T->isSpelledAsLValue(),
4505 TL.getSigilLoc());
4506 if (Result.isNull())
4507 return QualType();
4508 }
4509
John McCall31168b02011-06-15 23:02:42 +00004510 // Objective-C ARC can add lifetime qualifiers to the type that we're
4511 // referring to.
4512 TLB.TypeWasModifiedSafely(
4513 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4514
John McCall70dd5f62009-10-30 00:06:24 +00004515 // r-value references can be rebuilt as l-value references.
4516 ReferenceTypeLoc NewTL;
4517 if (isa<LValueReferenceType>(Result))
4518 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4519 else
4520 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4521 NewTL.setSigilLoc(TL.getSigilLoc());
4522
4523 return Result;
4524}
4525
Mike Stump11289f42009-09-09 15:08:12 +00004526template<typename Derived>
4527QualType
John McCall550e0c22009-10-21 00:40:46 +00004528TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004529 LValueReferenceTypeLoc TL) {
4530 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004531}
4532
Mike Stump11289f42009-09-09 15:08:12 +00004533template<typename Derived>
4534QualType
John McCall550e0c22009-10-21 00:40:46 +00004535TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004536 RValueReferenceTypeLoc TL) {
4537 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004538}
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregord6ff3322009-08-04 16:50:30 +00004540template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004541QualType
John McCall550e0c22009-10-21 00:40:46 +00004542TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004543 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004544 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545 if (PointeeType.isNull())
4546 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004547
Abramo Bagnara509357842011-03-05 14:42:21 +00004548 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004549 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004550 if (OldClsTInfo) {
4551 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4552 if (!NewClsTInfo)
4553 return QualType();
4554 }
4555
4556 const MemberPointerType *T = TL.getTypePtr();
4557 QualType OldClsType = QualType(T->getClass(), 0);
4558 QualType NewClsType;
4559 if (NewClsTInfo)
4560 NewClsType = NewClsTInfo->getType();
4561 else {
4562 NewClsType = getDerived().TransformType(OldClsType);
4563 if (NewClsType.isNull())
4564 return QualType();
4565 }
Mike Stump11289f42009-09-09 15:08:12 +00004566
John McCall550e0c22009-10-21 00:40:46 +00004567 QualType Result = TL.getType();
4568 if (getDerived().AlwaysRebuild() ||
4569 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004570 NewClsType != OldClsType) {
4571 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004572 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004573 if (Result.isNull())
4574 return QualType();
4575 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004576
Reid Kleckner0503a872013-12-05 01:23:43 +00004577 // If we had to adjust the pointee type when building a member pointer, make
4578 // sure to push TypeLoc info for it.
4579 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4580 if (MPT && PointeeType != MPT->getPointeeType()) {
4581 assert(isa<AdjustedType>(MPT->getPointeeType()));
4582 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4583 }
4584
John McCall550e0c22009-10-21 00:40:46 +00004585 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4586 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004587 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004588
4589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590}
4591
Mike Stump11289f42009-09-09 15:08:12 +00004592template<typename Derived>
4593QualType
John McCall550e0c22009-10-21 00:40:46 +00004594TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004595 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004596 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004597 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004598 if (ElementType.isNull())
4599 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004600
John McCall550e0c22009-10-21 00:40:46 +00004601 QualType Result = TL.getType();
4602 if (getDerived().AlwaysRebuild() ||
4603 ElementType != T->getElementType()) {
4604 Result = getDerived().RebuildConstantArrayType(ElementType,
4605 T->getSizeModifier(),
4606 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004607 T->getIndexTypeCVRQualifiers(),
4608 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004609 if (Result.isNull())
4610 return QualType();
4611 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004612
4613 // We might have either a ConstantArrayType or a VariableArrayType now:
4614 // a ConstantArrayType is allowed to have an element type which is a
4615 // VariableArrayType if the type is dependent. Fortunately, all array
4616 // types have the same location layout.
4617 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004618 NewTL.setLBracketLoc(TL.getLBracketLoc());
4619 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004620
John McCall550e0c22009-10-21 00:40:46 +00004621 Expr *Size = TL.getSizeExpr();
4622 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004623 EnterExpressionEvaluationContext Unevaluated(
4624 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004625 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4626 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004627 }
4628 NewTL.setSizeExpr(Size);
4629
4630 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004631}
Mike Stump11289f42009-09-09 15:08:12 +00004632
Douglas Gregord6ff3322009-08-04 16:50:30 +00004633template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004634QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004635 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004636 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004637 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004638 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004639 if (ElementType.isNull())
4640 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004641
John McCall550e0c22009-10-21 00:40:46 +00004642 QualType Result = TL.getType();
4643 if (getDerived().AlwaysRebuild() ||
4644 ElementType != T->getElementType()) {
4645 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004646 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004647 T->getIndexTypeCVRQualifiers(),
4648 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004649 if (Result.isNull())
4650 return QualType();
4651 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004652
John McCall550e0c22009-10-21 00:40:46 +00004653 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4654 NewTL.setLBracketLoc(TL.getLBracketLoc());
4655 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004656 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004657
4658 return Result;
4659}
4660
4661template<typename Derived>
4662QualType
4663TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004664 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004665 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004666 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4667 if (ElementType.isNull())
4668 return QualType();
4669
Tim Shenb34d0ef2017-02-14 23:46:37 +00004670 ExprResult SizeResult;
4671 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004672 EnterExpressionEvaluationContext Context(
4673 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004674 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4675 }
4676 if (SizeResult.isInvalid())
4677 return QualType();
4678 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004679 if (SizeResult.isInvalid())
4680 return QualType();
4681
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004682 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004683
4684 QualType Result = TL.getType();
4685 if (getDerived().AlwaysRebuild() ||
4686 ElementType != T->getElementType() ||
4687 Size != T->getSizeExpr()) {
4688 Result = getDerived().RebuildVariableArrayType(ElementType,
4689 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004690 Size,
John McCall550e0c22009-10-21 00:40:46 +00004691 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004692 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004693 if (Result.isNull())
4694 return QualType();
4695 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004696
Serge Pavlov774c6d02014-02-06 03:49:11 +00004697 // We might have constant size array now, but fortunately it has the same
4698 // location layout.
4699 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004700 NewTL.setLBracketLoc(TL.getLBracketLoc());
4701 NewTL.setRBracketLoc(TL.getRBracketLoc());
4702 NewTL.setSizeExpr(Size);
4703
4704 return Result;
4705}
4706
4707template<typename Derived>
4708QualType
4709TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004710 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004711 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004712 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4713 if (ElementType.isNull())
4714 return QualType();
4715
Richard Smith764d2fe2011-12-20 02:08:33 +00004716 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004717 EnterExpressionEvaluationContext Unevaluated(
4718 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004719
John McCall33ddac02011-01-19 10:06:00 +00004720 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4721 Expr *origSize = TL.getSizeExpr();
4722 if (!origSize) origSize = T->getSizeExpr();
4723
4724 ExprResult sizeResult
4725 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004726 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004727 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004728 return QualType();
4729
John McCall33ddac02011-01-19 10:06:00 +00004730 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004731
4732 QualType Result = TL.getType();
4733 if (getDerived().AlwaysRebuild() ||
4734 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004735 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004736 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4737 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004738 size,
John McCall550e0c22009-10-21 00:40:46 +00004739 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004740 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004741 if (Result.isNull())
4742 return QualType();
4743 }
John McCall550e0c22009-10-21 00:40:46 +00004744
4745 // We might have any sort of array type now, but fortunately they
4746 // all have the same location layout.
4747 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4748 NewTL.setLBracketLoc(TL.getLBracketLoc());
4749 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004750 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004751
4752 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004753}
Mike Stump11289f42009-09-09 15:08:12 +00004754
4755template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004756QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004757 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004758 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004759 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004760
4761 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004762 QualType ElementType = getDerived().TransformType(T->getElementType());
4763 if (ElementType.isNull())
4764 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004765
Richard Smith764d2fe2011-12-20 02:08:33 +00004766 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004767 EnterExpressionEvaluationContext Unevaluated(
4768 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004769
John McCalldadc5752010-08-24 06:29:42 +00004770 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004771 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004772 if (Size.isInvalid())
4773 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004774
John McCall550e0c22009-10-21 00:40:46 +00004775 QualType Result = TL.getType();
4776 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004777 ElementType != T->getElementType() ||
4778 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004779 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004780 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004781 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004782 if (Result.isNull())
4783 return QualType();
4784 }
John McCall550e0c22009-10-21 00:40:46 +00004785
4786 // Result might be dependent or not.
4787 if (isa<DependentSizedExtVectorType>(Result)) {
4788 DependentSizedExtVectorTypeLoc NewTL
4789 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4790 NewTL.setNameLoc(TL.getNameLoc());
4791 } else {
4792 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4793 NewTL.setNameLoc(TL.getNameLoc());
4794 }
4795
4796 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004797}
Mike Stump11289f42009-09-09 15:08:12 +00004798
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004799template <typename Derived>
4800QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4801 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4802 const DependentAddressSpaceType *T = TL.getTypePtr();
4803
4804 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4805
4806 if (pointeeType.isNull())
4807 return QualType();
4808
4809 // Address spaces are constant expressions.
4810 EnterExpressionEvaluationContext Unevaluated(
4811 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4812
4813 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4814 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4815 if (AddrSpace.isInvalid())
4816 return QualType();
4817
4818 QualType Result = TL.getType();
4819 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4820 AddrSpace.get() != T->getAddrSpaceExpr()) {
4821 Result = getDerived().RebuildDependentAddressSpaceType(
4822 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4823 if (Result.isNull())
4824 return QualType();
4825 }
4826
4827 // Result might be dependent or not.
4828 if (isa<DependentAddressSpaceType>(Result)) {
4829 DependentAddressSpaceTypeLoc NewTL =
4830 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4831
4832 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4833 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4834 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4835
4836 } else {
4837 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4838 Result, getDerived().getBaseLocation());
4839 TransformType(TLB, DI->getTypeLoc());
4840 }
4841
4842 return Result;
4843}
4844
4845template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004846QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004847 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004848 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004849 QualType ElementType = getDerived().TransformType(T->getElementType());
4850 if (ElementType.isNull())
4851 return QualType();
4852
John McCall550e0c22009-10-21 00:40:46 +00004853 QualType Result = TL.getType();
4854 if (getDerived().AlwaysRebuild() ||
4855 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004856 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004857 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004858 if (Result.isNull())
4859 return QualType();
4860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004861
John McCall550e0c22009-10-21 00:40:46 +00004862 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4863 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCall550e0c22009-10-21 00:40:46 +00004865 return Result;
4866}
4867
4868template<typename Derived>
4869QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004870 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004871 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004872 QualType ElementType = getDerived().TransformType(T->getElementType());
4873 if (ElementType.isNull())
4874 return QualType();
4875
4876 QualType Result = TL.getType();
4877 if (getDerived().AlwaysRebuild() ||
4878 ElementType != T->getElementType()) {
4879 Result = getDerived().RebuildExtVectorType(ElementType,
4880 T->getNumElements(),
4881 /*FIXME*/ SourceLocation());
4882 if (Result.isNull())
4883 return QualType();
4884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004885
John McCall550e0c22009-10-21 00:40:46 +00004886 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4887 NewTL.setNameLoc(TL.getNameLoc());
4888
4889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004890}
Mike Stump11289f42009-09-09 15:08:12 +00004891
David Blaikie05785d12013-02-20 22:23:23 +00004892template <typename Derived>
4893ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4894 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4895 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004896 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004897 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004898
Douglas Gregor715e4612011-01-14 22:40:04 +00004899 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004900 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004901 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004902 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004903 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004904
Douglas Gregor715e4612011-01-14 22:40:04 +00004905 TypeLocBuilder TLB;
4906 TypeLoc NewTL = OldDI->getTypeLoc();
4907 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004908
4909 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004910 OldExpansionTL.getPatternLoc());
4911 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004912 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004913
4914 Result = RebuildPackExpansionType(Result,
4915 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004916 OldExpansionTL.getEllipsisLoc(),
4917 NumExpansions);
4918 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004919 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004920
Douglas Gregor715e4612011-01-14 22:40:04 +00004921 PackExpansionTypeLoc NewExpansionTL
4922 = TLB.push<PackExpansionTypeLoc>(Result);
4923 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4924 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4925 } else
4926 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004927 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004928 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004929
John McCall8fb0d9d2011-05-01 22:35:37 +00004930 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004931 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004932
4933 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4934 OldParm->getDeclContext(),
4935 OldParm->getInnerLocStart(),
4936 OldParm->getLocation(),
4937 OldParm->getIdentifier(),
4938 NewDI->getType(),
4939 NewDI,
4940 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004941 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004942 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4943 OldParm->getFunctionScopeIndex() + indexAdjustment);
4944 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004945}
4946
David Majnemer59f77922016-06-24 04:05:48 +00004947template <typename Derived>
4948bool TreeTransform<Derived>::TransformFunctionTypeParams(
4949 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4950 const QualType *ParamTypes,
4951 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4952 SmallVectorImpl<QualType> &OutParamTypes,
4953 SmallVectorImpl<ParmVarDecl *> *PVars,
4954 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004955 int indexAdjustment = 0;
4956
David Majnemer59f77922016-06-24 04:05:48 +00004957 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004958 for (unsigned i = 0; i != NumParams; ++i) {
4959 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004960 assert(OldParm->getFunctionScopeIndex() == i);
4961
David Blaikie05785d12013-02-20 22:23:23 +00004962 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004963 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004964 if (OldParm->isParameterPack()) {
4965 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004966 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004967
Douglas Gregor5499af42011-01-05 23:12:31 +00004968 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004969 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004970 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004971 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4972 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004973 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4974
Douglas Gregor5499af42011-01-05 23:12:31 +00004975 // Determine whether we should expand the parameter packs.
4976 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004977 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004978 Optional<unsigned> OrigNumExpansions =
4979 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004980 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004981 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4982 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004983 Unexpanded,
4984 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004985 RetainExpansion,
4986 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004987 return true;
4988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004989
Douglas Gregor5499af42011-01-05 23:12:31 +00004990 if (ShouldExpand) {
4991 // Expand the function parameter pack into multiple, separate
4992 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004993 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004994 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004995 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004996 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004997 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004998 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004999 OrigNumExpansions,
5000 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005001 if (!NewParm)
5002 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005003
John McCallc8e321d2016-03-01 02:09:25 +00005004 if (ParamInfos)
5005 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005006 OutParamTypes.push_back(NewParm->getType());
5007 if (PVars)
5008 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005009 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005010
5011 // If we're supposed to retain a pack expansion, do so by temporarily
5012 // forgetting the partially-substituted parameter pack.
5013 if (RetainExpansion) {
5014 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005015 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005016 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005017 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005018 OrigNumExpansions,
5019 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005020 if (!NewParm)
5021 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005022
John McCallc8e321d2016-03-01 02:09:25 +00005023 if (ParamInfos)
5024 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005025 OutParamTypes.push_back(NewParm->getType());
5026 if (PVars)
5027 PVars->push_back(NewParm);
5028 }
5029
John McCall8fb0d9d2011-05-01 22:35:37 +00005030 // The next parameter should have the same adjustment as the
5031 // last thing we pushed, but we post-incremented indexAdjustment
5032 // on every push. Also, if we push nothing, the adjustment should
5033 // go down by one.
5034 indexAdjustment--;
5035
Douglas Gregor5499af42011-01-05 23:12:31 +00005036 // We're done with the pack expansion.
5037 continue;
5038 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005039
5040 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005041 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5043 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005044 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005045 NumExpansions,
5046 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005047 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005048 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005049 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005050 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005051
John McCall58f10c32010-03-11 09:03:00 +00005052 if (!NewParm)
5053 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005054
John McCallc8e321d2016-03-01 02:09:25 +00005055 if (ParamInfos)
5056 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005057 OutParamTypes.push_back(NewParm->getType());
5058 if (PVars)
5059 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005060 continue;
5061 }
John McCall58f10c32010-03-11 09:03:00 +00005062
5063 // Deal with the possibility that we don't have a parameter
5064 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005065 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005066 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005067 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005068 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005069 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005070 = dyn_cast<PackExpansionType>(OldType)) {
5071 // We have a function parameter pack that may need to be expanded.
5072 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005073 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005074 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005075
Douglas Gregor5499af42011-01-05 23:12:31 +00005076 // Determine whether we should expand the parameter packs.
5077 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005078 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005079 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005080 Unexpanded,
5081 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005082 RetainExpansion,
5083 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005084 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005086
Douglas Gregor5499af42011-01-05 23:12:31 +00005087 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005088 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005089 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005090 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005091 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5092 QualType NewType = getDerived().TransformType(Pattern);
5093 if (NewType.isNull())
5094 return true;
John McCall58f10c32010-03-11 09:03:00 +00005095
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005096 if (NewType->containsUnexpandedParameterPack()) {
5097 NewType =
5098 getSema().getASTContext().getPackExpansionType(NewType, None);
5099
5100 if (NewType.isNull())
5101 return true;
5102 }
5103
John McCallc8e321d2016-03-01 02:09:25 +00005104 if (ParamInfos)
5105 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005106 OutParamTypes.push_back(NewType);
5107 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005108 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005109 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005110
Douglas Gregor5499af42011-01-05 23:12:31 +00005111 // We're done with the pack expansion.
5112 continue;
5113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005114
Douglas Gregor48d24112011-01-10 20:53:55 +00005115 // If we're supposed to retain a pack expansion, do so by temporarily
5116 // forgetting the partially-substituted parameter pack.
5117 if (RetainExpansion) {
5118 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5119 QualType NewType = getDerived().TransformType(Pattern);
5120 if (NewType.isNull())
5121 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005122
John McCallc8e321d2016-03-01 02:09:25 +00005123 if (ParamInfos)
5124 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005125 OutParamTypes.push_back(NewType);
5126 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005127 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005128 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005129
Chad Rosier1dcde962012-08-08 18:46:20 +00005130 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005131 // expansion.
5132 OldType = Expansion->getPattern();
5133 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005134 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5135 NewType = getDerived().TransformType(OldType);
5136 } else {
5137 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005138 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005139
Douglas Gregor5499af42011-01-05 23:12:31 +00005140 if (NewType.isNull())
5141 return true;
5142
5143 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005144 NewType = getSema().Context.getPackExpansionType(NewType,
5145 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005146
John McCallc8e321d2016-03-01 02:09:25 +00005147 if (ParamInfos)
5148 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005149 OutParamTypes.push_back(NewType);
5150 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005151 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005152 }
5153
John McCall8fb0d9d2011-05-01 22:35:37 +00005154#ifndef NDEBUG
5155 if (PVars) {
5156 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5157 if (ParmVarDecl *parm = (*PVars)[i])
5158 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005159 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005160#endif
5161
5162 return false;
5163}
John McCall58f10c32010-03-11 09:03:00 +00005164
5165template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005166QualType
John McCall550e0c22009-10-21 00:40:46 +00005167TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005168 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005169 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005170 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005171 return getDerived().TransformFunctionProtoType(
5172 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005173 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5174 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5175 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005176 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005177}
5178
Richard Smith2e321552014-11-12 02:00:47 +00005179template<typename Derived> template<typename Fn>
5180QualType TreeTransform<Derived>::TransformFunctionProtoType(
5181 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5182 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005183
Douglas Gregor4afc2362010-08-31 00:26:14 +00005184 // Transform the parameters and return type.
5185 //
Richard Smithf623c962012-04-17 00:58:00 +00005186 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005187 // When the function has a trailing return type, we instantiate the
5188 // parameters before the return type, since the return type can then refer
5189 // to the parameters themselves (via decltype, sizeof, etc.).
5190 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005191 SmallVector<QualType, 4> ParamTypes;
5192 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005193 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005194 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005195
Douglas Gregor7fb25412010-10-01 18:44:50 +00005196 QualType ResultType;
5197
Richard Smith1226c602012-08-14 22:51:13 +00005198 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005199 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005200 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005201 TL.getTypePtr()->param_type_begin(),
5202 T->getExtParameterInfosOrNull(),
5203 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005204 return QualType();
5205
Douglas Gregor3024f072012-04-16 07:05:22 +00005206 {
5207 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005208 // If a declaration declares a member function or member function
5209 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005210 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005211 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005212 // declarator.
5213 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005214
Alp Toker42a16a62014-01-25 23:51:36 +00005215 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005216 if (ResultType.isNull())
5217 return QualType();
5218 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005219 }
5220 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005221 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005222 if (ResultType.isNull())
5223 return QualType();
5224
Alp Toker9cacbab2014-01-20 20:26:09 +00005225 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005226 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005227 TL.getTypePtr()->param_type_begin(),
5228 T->getExtParameterInfosOrNull(),
5229 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005230 return QualType();
5231 }
5232
Richard Smith2e321552014-11-12 02:00:47 +00005233 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5234
5235 bool EPIChanged = false;
5236 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5237 return QualType();
5238
John McCallc8e321d2016-03-01 02:09:25 +00005239 // Handle extended parameter information.
5240 if (auto NewExtParamInfos =
5241 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5242 if (!EPI.ExtParameterInfos ||
5243 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5244 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5245 EPIChanged = true;
5246 }
5247 EPI.ExtParameterInfos = NewExtParamInfos;
5248 } else if (EPI.ExtParameterInfos) {
5249 EPIChanged = true;
5250 EPI.ExtParameterInfos = nullptr;
5251 }
Richard Smithf623c962012-04-17 00:58:00 +00005252
John McCall550e0c22009-10-21 00:40:46 +00005253 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005254 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005255 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005256 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005257 if (Result.isNull())
5258 return QualType();
5259 }
Mike Stump11289f42009-09-09 15:08:12 +00005260
John McCall550e0c22009-10-21 00:40:46 +00005261 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005262 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005263 NewTL.setLParenLoc(TL.getLParenLoc());
5264 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005265 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005266 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005267 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5268 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005269
5270 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005271}
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregord6ff3322009-08-04 16:50:30 +00005273template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005274bool TreeTransform<Derived>::TransformExceptionSpec(
5275 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5276 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5277 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5278
5279 // Instantiate a dynamic noexcept expression, if any.
5280 if (ESI.Type == EST_ComputedNoexcept) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005281 EnterExpressionEvaluationContext Unevaluated(
5282 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005283 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5284 if (NoexceptExpr.isInvalid())
5285 return true;
5286
Richard Smith03a4aa32016-06-23 19:02:52 +00005287 // FIXME: This is bogus, a noexcept expression is not a condition.
5288 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005289 if (NoexceptExpr.isInvalid())
5290 return true;
5291
5292 if (!NoexceptExpr.get()->isValueDependent()) {
5293 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5294 NoexceptExpr.get(), nullptr,
5295 diag::err_noexcept_needs_constant_expression,
5296 /*AllowFold*/false);
5297 if (NoexceptExpr.isInvalid())
5298 return true;
5299 }
5300
5301 if (ESI.NoexceptExpr != NoexceptExpr.get())
5302 Changed = true;
5303 ESI.NoexceptExpr = NoexceptExpr.get();
5304 }
5305
5306 if (ESI.Type != EST_Dynamic)
5307 return false;
5308
5309 // Instantiate a dynamic exception specification's type.
5310 for (QualType T : ESI.Exceptions) {
5311 if (const PackExpansionType *PackExpansion =
5312 T->getAs<PackExpansionType>()) {
5313 Changed = true;
5314
5315 // We have a pack expansion. Instantiate it.
5316 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5317 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5318 Unexpanded);
5319 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5320
5321 // Determine whether the set of unexpanded parameter packs can and
5322 // should
5323 // be expanded.
5324 bool Expand = false;
5325 bool RetainExpansion = false;
5326 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5327 // FIXME: Track the location of the ellipsis (and track source location
5328 // information for the types in the exception specification in general).
5329 if (getDerived().TryExpandParameterPacks(
5330 Loc, SourceRange(), Unexpanded, Expand,
5331 RetainExpansion, NumExpansions))
5332 return true;
5333
5334 if (!Expand) {
5335 // We can't expand this pack expansion into separate arguments yet;
5336 // just substitute into the pattern and create a new pack expansion
5337 // type.
5338 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5339 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5340 if (U.isNull())
5341 return true;
5342
5343 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5344 Exceptions.push_back(U);
5345 continue;
5346 }
5347
5348 // Substitute into the pack expansion pattern for each slice of the
5349 // pack.
5350 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5351 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5352
5353 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5354 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5355 return true;
5356
5357 Exceptions.push_back(U);
5358 }
5359 } else {
5360 QualType U = getDerived().TransformType(T);
5361 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5362 return true;
5363 if (T != U)
5364 Changed = true;
5365
5366 Exceptions.push_back(U);
5367 }
5368 }
5369
5370 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005371 if (ESI.Exceptions.empty())
5372 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005373 return false;
5374}
5375
5376template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005377QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005378 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005379 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005380 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005381 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005382 if (ResultType.isNull())
5383 return QualType();
5384
5385 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005386 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005387 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5388
5389 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005390 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005391 NewTL.setLParenLoc(TL.getLParenLoc());
5392 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005393 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005394
5395 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005396}
Mike Stump11289f42009-09-09 15:08:12 +00005397
John McCallb96ec562009-12-04 22:46:56 +00005398template<typename Derived> QualType
5399TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005400 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005401 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005402 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005403 if (!D)
5404 return QualType();
5405
5406 QualType Result = TL.getType();
5407 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005408 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005409 if (Result.isNull())
5410 return QualType();
5411 }
5412
5413 // We might get an arbitrary type spec type back. We should at
5414 // least always get a type spec type, though.
5415 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5416 NewTL.setNameLoc(TL.getNameLoc());
5417
5418 return Result;
5419}
5420
Douglas Gregord6ff3322009-08-04 16:50:30 +00005421template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005422QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005423 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005424 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005425 TypedefNameDecl *Typedef
5426 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5427 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005428 if (!Typedef)
5429 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005430
John McCall550e0c22009-10-21 00:40:46 +00005431 QualType Result = TL.getType();
5432 if (getDerived().AlwaysRebuild() ||
5433 Typedef != T->getDecl()) {
5434 Result = getDerived().RebuildTypedefType(Typedef);
5435 if (Result.isNull())
5436 return QualType();
5437 }
Mike Stump11289f42009-09-09 15:08:12 +00005438
John McCall550e0c22009-10-21 00:40:46 +00005439 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5440 NewTL.setNameLoc(TL.getNameLoc());
5441
5442 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443}
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregord6ff3322009-08-04 16:50:30 +00005445template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005446QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005447 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005448 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005449 EnterExpressionEvaluationContext Unevaluated(
5450 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5451 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005452
John McCalldadc5752010-08-24 06:29:42 +00005453 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005454 if (E.isInvalid())
5455 return QualType();
5456
Eli Friedmane4f22df2012-02-29 04:03:55 +00005457 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5458 if (E.isInvalid())
5459 return QualType();
5460
John McCall550e0c22009-10-21 00:40:46 +00005461 QualType Result = TL.getType();
5462 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005463 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005464 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005465 if (Result.isNull())
5466 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005467 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005468 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005469
John McCall550e0c22009-10-21 00:40:46 +00005470 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005471 NewTL.setTypeofLoc(TL.getTypeofLoc());
5472 NewTL.setLParenLoc(TL.getLParenLoc());
5473 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005474
5475 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005476}
Mike Stump11289f42009-09-09 15:08:12 +00005477
5478template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005479QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005480 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005481 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5482 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5483 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005484 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005485
John McCall550e0c22009-10-21 00:40:46 +00005486 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005487 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5488 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005489 if (Result.isNull())
5490 return QualType();
5491 }
Mike Stump11289f42009-09-09 15:08:12 +00005492
John McCall550e0c22009-10-21 00:40:46 +00005493 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005494 NewTL.setTypeofLoc(TL.getTypeofLoc());
5495 NewTL.setLParenLoc(TL.getLParenLoc());
5496 NewTL.setRParenLoc(TL.getRParenLoc());
5497 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005498
5499 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005500}
Mike Stump11289f42009-09-09 15:08:12 +00005501
5502template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005503QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005504 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005505 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005506
Douglas Gregore922c772009-08-04 22:27:00 +00005507 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005508 EnterExpressionEvaluationContext Unevaluated(
5509 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5510 /*IsDecltype=*/true);
Mike Stump11289f42009-09-09 15:08:12 +00005511
John McCalldadc5752010-08-24 06:29:42 +00005512 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005513 if (E.isInvalid())
5514 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005515
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005516 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005517 if (E.isInvalid())
5518 return QualType();
5519
John McCall550e0c22009-10-21 00:40:46 +00005520 QualType Result = TL.getType();
5521 if (getDerived().AlwaysRebuild() ||
5522 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005523 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005524 if (Result.isNull())
5525 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005526 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005527 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005528
John McCall550e0c22009-10-21 00:40:46 +00005529 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5530 NewTL.setNameLoc(TL.getNameLoc());
5531
5532 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005533}
5534
5535template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005536QualType TreeTransform<Derived>::TransformUnaryTransformType(
5537 TypeLocBuilder &TLB,
5538 UnaryTransformTypeLoc TL) {
5539 QualType Result = TL.getType();
5540 if (Result->isDependentType()) {
5541 const UnaryTransformType *T = TL.getTypePtr();
5542 QualType NewBase =
5543 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5544 Result = getDerived().RebuildUnaryTransformType(NewBase,
5545 T->getUTTKind(),
5546 TL.getKWLoc());
5547 if (Result.isNull())
5548 return QualType();
5549 }
5550
5551 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5552 NewTL.setKWLoc(TL.getKWLoc());
5553 NewTL.setParensRange(TL.getParensRange());
5554 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5555 return Result;
5556}
5557
5558template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005559QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5560 AutoTypeLoc TL) {
5561 const AutoType *T = TL.getTypePtr();
5562 QualType OldDeduced = T->getDeducedType();
5563 QualType NewDeduced;
5564 if (!OldDeduced.isNull()) {
5565 NewDeduced = getDerived().TransformType(OldDeduced);
5566 if (NewDeduced.isNull())
5567 return QualType();
5568 }
5569
5570 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005571 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5572 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005573 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005574 if (Result.isNull())
5575 return QualType();
5576 }
5577
5578 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5579 NewTL.setNameLoc(TL.getNameLoc());
5580
5581 return Result;
5582}
5583
5584template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005585QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5586 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5587 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5588
5589 CXXScopeSpec SS;
5590 TemplateName TemplateName = getDerived().TransformTemplateName(
5591 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5592 if (TemplateName.isNull())
5593 return QualType();
5594
5595 QualType OldDeduced = T->getDeducedType();
5596 QualType NewDeduced;
5597 if (!OldDeduced.isNull()) {
5598 NewDeduced = getDerived().TransformType(OldDeduced);
5599 if (NewDeduced.isNull())
5600 return QualType();
5601 }
5602
5603 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5604 TemplateName, NewDeduced);
5605 if (Result.isNull())
5606 return QualType();
5607
5608 DeducedTemplateSpecializationTypeLoc NewTL =
5609 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5610 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5611
5612 return Result;
5613}
5614
5615template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005616QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005617 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005618 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005619 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005620 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5621 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005622 if (!Record)
5623 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005624
John McCall550e0c22009-10-21 00:40:46 +00005625 QualType Result = TL.getType();
5626 if (getDerived().AlwaysRebuild() ||
5627 Record != T->getDecl()) {
5628 Result = getDerived().RebuildRecordType(Record);
5629 if (Result.isNull())
5630 return QualType();
5631 }
Mike Stump11289f42009-09-09 15:08:12 +00005632
John McCall550e0c22009-10-21 00:40:46 +00005633 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5634 NewTL.setNameLoc(TL.getNameLoc());
5635
5636 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005637}
Mike Stump11289f42009-09-09 15:08:12 +00005638
5639template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005640QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005641 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005642 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005643 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005644 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5645 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005646 if (!Enum)
5647 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005648
John McCall550e0c22009-10-21 00:40:46 +00005649 QualType Result = TL.getType();
5650 if (getDerived().AlwaysRebuild() ||
5651 Enum != T->getDecl()) {
5652 Result = getDerived().RebuildEnumType(Enum);
5653 if (Result.isNull())
5654 return QualType();
5655 }
Mike Stump11289f42009-09-09 15:08:12 +00005656
John McCall550e0c22009-10-21 00:40:46 +00005657 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5658 NewTL.setNameLoc(TL.getNameLoc());
5659
5660 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005661}
John McCallfcc33b02009-09-05 00:15:47 +00005662
John McCalle78aac42010-03-10 03:28:59 +00005663template<typename Derived>
5664QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5665 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005666 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005667 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5668 TL.getTypePtr()->getDecl());
5669 if (!D) return QualType();
5670
5671 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5672 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5673 return T;
5674}
5675
Douglas Gregord6ff3322009-08-04 16:50:30 +00005676template<typename Derived>
5677QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005678 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005679 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005680 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005681}
5682
Mike Stump11289f42009-09-09 15:08:12 +00005683template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005684QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005685 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005686 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005687 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005688
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005689 // Substitute into the replacement type, which itself might involve something
5690 // that needs to be transformed. This only tends to occur with default
5691 // template arguments of template template parameters.
5692 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5693 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5694 if (Replacement.isNull())
5695 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005696
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005697 // Always canonicalize the replacement type.
5698 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5699 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005700 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005701 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005702
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005703 // Propagate type-source information.
5704 SubstTemplateTypeParmTypeLoc NewTL
5705 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5706 NewTL.setNameLoc(TL.getNameLoc());
5707 return Result;
5708
John McCallcebee162009-10-18 09:09:24 +00005709}
5710
5711template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005712QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5713 TypeLocBuilder &TLB,
5714 SubstTemplateTypeParmPackTypeLoc TL) {
5715 return TransformTypeSpecType(TLB, TL);
5716}
5717
5718template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005719QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005720 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005721 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005722 const TemplateSpecializationType *T = TL.getTypePtr();
5723
Douglas Gregordf846d12011-03-02 18:46:51 +00005724 // The nested-name-specifier never matters in a TemplateSpecializationType,
5725 // because we can't have a dependent nested-name-specifier anyway.
5726 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005727 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005728 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5729 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005730 if (Template.isNull())
5731 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005732
John McCall31f82722010-11-12 08:19:04 +00005733 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5734}
5735
Eli Friedman0dfb8892011-10-06 23:00:33 +00005736template<typename Derived>
5737QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5738 AtomicTypeLoc TL) {
5739 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5740 if (ValueType.isNull())
5741 return QualType();
5742
5743 QualType Result = TL.getType();
5744 if (getDerived().AlwaysRebuild() ||
5745 ValueType != TL.getValueLoc().getType()) {
5746 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5747 if (Result.isNull())
5748 return QualType();
5749 }
5750
5751 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5752 NewTL.setKWLoc(TL.getKWLoc());
5753 NewTL.setLParenLoc(TL.getLParenLoc());
5754 NewTL.setRParenLoc(TL.getRParenLoc());
5755
5756 return Result;
5757}
5758
Xiuli Pan9c14e282016-01-09 12:53:17 +00005759template <typename Derived>
5760QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5761 PipeTypeLoc TL) {
5762 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5763 if (ValueType.isNull())
5764 return QualType();
5765
5766 QualType Result = TL.getType();
5767 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005768 const PipeType *PT = Result->getAs<PipeType>();
5769 bool isReadPipe = PT->isReadOnly();
5770 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005771 if (Result.isNull())
5772 return QualType();
5773 }
5774
5775 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5776 NewTL.setKWLoc(TL.getKWLoc());
5777
5778 return Result;
5779}
5780
Chad Rosier1dcde962012-08-08 18:46:20 +00005781 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005782 /// container that provides a \c getArgLoc() member function.
5783 ///
5784 /// This iterator is intended to be used with the iterator form of
5785 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5786 template<typename ArgLocContainer>
5787 class TemplateArgumentLocContainerIterator {
5788 ArgLocContainer *Container;
5789 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005790
Douglas Gregorfe921a72010-12-20 23:36:19 +00005791 public:
5792 typedef TemplateArgumentLoc value_type;
5793 typedef TemplateArgumentLoc reference;
5794 typedef int difference_type;
5795 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005796
Douglas Gregorfe921a72010-12-20 23:36:19 +00005797 class pointer {
5798 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005799
Douglas Gregorfe921a72010-12-20 23:36:19 +00005800 public:
5801 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005802
Douglas Gregorfe921a72010-12-20 23:36:19 +00005803 const TemplateArgumentLoc *operator->() const {
5804 return &Arg;
5805 }
5806 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005807
5808
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005809 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005810
Douglas Gregorfe921a72010-12-20 23:36:19 +00005811 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5812 unsigned Index)
5813 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005814
Douglas Gregorfe921a72010-12-20 23:36:19 +00005815 TemplateArgumentLocContainerIterator &operator++() {
5816 ++Index;
5817 return *this;
5818 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005819
Douglas Gregorfe921a72010-12-20 23:36:19 +00005820 TemplateArgumentLocContainerIterator operator++(int) {
5821 TemplateArgumentLocContainerIterator Old(*this);
5822 ++(*this);
5823 return Old;
5824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005825
Douglas Gregorfe921a72010-12-20 23:36:19 +00005826 TemplateArgumentLoc operator*() const {
5827 return Container->getArgLoc(Index);
5828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005829
Douglas Gregorfe921a72010-12-20 23:36:19 +00005830 pointer operator->() const {
5831 return pointer(Container->getArgLoc(Index));
5832 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005833
Douglas Gregorfe921a72010-12-20 23:36:19 +00005834 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005835 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005836 return X.Container == Y.Container && X.Index == Y.Index;
5837 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005838
Douglas Gregorfe921a72010-12-20 23:36:19 +00005839 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005840 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005841 return !(X == Y);
5842 }
5843 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005844
5845
John McCall31f82722010-11-12 08:19:04 +00005846template <typename Derived>
5847QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5848 TypeLocBuilder &TLB,
5849 TemplateSpecializationTypeLoc TL,
5850 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005851 TemplateArgumentListInfo NewTemplateArgs;
5852 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5853 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005854 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5855 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005856 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005857 ArgIterator(TL, TL.getNumArgs()),
5858 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005859 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005860
John McCall0ad16662009-10-29 08:12:44 +00005861 // FIXME: maybe don't rebuild if all the template arguments are the same.
5862
5863 QualType Result =
5864 getDerived().RebuildTemplateSpecializationType(Template,
5865 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005866 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005867
5868 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005869 // Specializations of template template parameters are represented as
5870 // TemplateSpecializationTypes, and substitution of type alias templates
5871 // within a dependent context can transform them into
5872 // DependentTemplateSpecializationTypes.
5873 if (isa<DependentTemplateSpecializationType>(Result)) {
5874 DependentTemplateSpecializationTypeLoc NewTL
5875 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005876 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005877 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005878 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005879 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005880 NewTL.setLAngleLoc(TL.getLAngleLoc());
5881 NewTL.setRAngleLoc(TL.getRAngleLoc());
5882 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5883 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5884 return Result;
5885 }
5886
John McCall0ad16662009-10-29 08:12:44 +00005887 TemplateSpecializationTypeLoc NewTL
5888 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005889 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005890 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5891 NewTL.setLAngleLoc(TL.getLAngleLoc());
5892 NewTL.setRAngleLoc(TL.getRAngleLoc());
5893 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5894 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005895 }
Mike Stump11289f42009-09-09 15:08:12 +00005896
John McCall0ad16662009-10-29 08:12:44 +00005897 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005898}
Mike Stump11289f42009-09-09 15:08:12 +00005899
Douglas Gregor5a064722011-02-28 17:23:35 +00005900template <typename Derived>
5901QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5902 TypeLocBuilder &TLB,
5903 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005904 TemplateName Template,
5905 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005906 TemplateArgumentListInfo NewTemplateArgs;
5907 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5908 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5909 typedef TemplateArgumentLocContainerIterator<
5910 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005911 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005912 ArgIterator(TL, TL.getNumArgs()),
5913 NewTemplateArgs))
5914 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005915
Douglas Gregor5a064722011-02-28 17:23:35 +00005916 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005917
Douglas Gregor5a064722011-02-28 17:23:35 +00005918 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5919 QualType Result
5920 = getSema().Context.getDependentTemplateSpecializationType(
5921 TL.getTypePtr()->getKeyword(),
5922 DTN->getQualifier(),
5923 DTN->getIdentifier(),
5924 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005925
Douglas Gregor5a064722011-02-28 17:23:35 +00005926 DependentTemplateSpecializationTypeLoc NewTL
5927 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005928 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005929 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005930 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005931 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005932 NewTL.setLAngleLoc(TL.getLAngleLoc());
5933 NewTL.setRAngleLoc(TL.getRAngleLoc());
5934 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5935 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5936 return Result;
5937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005938
5939 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005940 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005941 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005942 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005943
Douglas Gregor5a064722011-02-28 17:23:35 +00005944 if (!Result.isNull()) {
5945 /// FIXME: Wrap this in an elaborated-type-specifier?
5946 TemplateSpecializationTypeLoc NewTL
5947 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005948 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005949 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005950 NewTL.setLAngleLoc(TL.getLAngleLoc());
5951 NewTL.setRAngleLoc(TL.getRAngleLoc());
5952 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5953 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005955
Douglas Gregor5a064722011-02-28 17:23:35 +00005956 return Result;
5957}
5958
Mike Stump11289f42009-09-09 15:08:12 +00005959template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005960QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005961TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005962 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005963 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005964
Douglas Gregor844cb502011-03-01 18:12:44 +00005965 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005966 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005967 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005968 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005969 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5970 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005971 return QualType();
5972 }
Mike Stump11289f42009-09-09 15:08:12 +00005973
John McCall31f82722010-11-12 08:19:04 +00005974 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5975 if (NamedT.isNull())
5976 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005977
Richard Smith3f1b5d02011-05-05 21:57:07 +00005978 // C++0x [dcl.type.elab]p2:
5979 // If the identifier resolves to a typedef-name or the simple-template-id
5980 // resolves to an alias template specialization, the
5981 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005982 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5983 if (const TemplateSpecializationType *TST =
5984 NamedT->getAs<TemplateSpecializationType>()) {
5985 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005986 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5987 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005988 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005989 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005990 << TAT << Sema::NTK_TypeAliasTemplate
5991 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005992 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5993 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005994 }
5995 }
5996
John McCall550e0c22009-10-21 00:40:46 +00005997 QualType Result = TL.getType();
5998 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005999 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006000 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006001 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006002 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006003 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006004 if (Result.isNull())
6005 return QualType();
6006 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006007
Abramo Bagnara6150c882010-05-11 21:36:43 +00006008 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006009 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006010 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006012}
Mike Stump11289f42009-09-09 15:08:12 +00006013
6014template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006015QualType TreeTransform<Derived>::TransformAttributedType(
6016 TypeLocBuilder &TLB,
6017 AttributedTypeLoc TL) {
6018 const AttributedType *oldType = TL.getTypePtr();
6019 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6020 if (modifiedType.isNull())
6021 return QualType();
6022
6023 QualType result = TL.getType();
6024
6025 // FIXME: dependent operand expressions?
6026 if (getDerived().AlwaysRebuild() ||
6027 modifiedType != oldType->getModifiedType()) {
6028 // TODO: this is really lame; we should really be rebuilding the
6029 // equivalent type from first principles.
6030 QualType equivalentType
6031 = getDerived().TransformType(oldType->getEquivalentType());
6032 if (equivalentType.isNull())
6033 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006034
6035 // Check whether we can add nullability; it is only represented as
6036 // type sugar, and therefore cannot be diagnosed in any other way.
6037 if (auto nullability = oldType->getImmediateNullability()) {
6038 if (!modifiedType->canHaveNullability()) {
6039 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00006040 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006041 return QualType();
6042 }
6043 }
6044
John McCall81904512011-01-06 01:58:22 +00006045 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
6046 modifiedType,
6047 equivalentType);
6048 }
6049
6050 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
6051 newTL.setAttrNameLoc(TL.getAttrNameLoc());
6052 if (TL.hasAttrOperand())
6053 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6054 if (TL.hasAttrExprOperand())
6055 newTL.setAttrExprOperand(TL.getAttrExprOperand());
6056 else if (TL.hasAttrEnumOperand())
6057 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
6058
6059 return result;
6060}
6061
6062template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006063QualType
6064TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6065 ParenTypeLoc TL) {
6066 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6067 if (Inner.isNull())
6068 return QualType();
6069
6070 QualType Result = TL.getType();
6071 if (getDerived().AlwaysRebuild() ||
6072 Inner != TL.getInnerLoc().getType()) {
6073 Result = getDerived().RebuildParenType(Inner);
6074 if (Result.isNull())
6075 return QualType();
6076 }
6077
6078 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6079 NewTL.setLParenLoc(TL.getLParenLoc());
6080 NewTL.setRParenLoc(TL.getRParenLoc());
6081 return Result;
6082}
6083
6084template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006085QualType TreeTransform<Derived>::TransformDependentNameType(
6086 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6087 return TransformDependentNameType(TLB, TL, false);
6088}
6089
6090template<typename Derived>
6091QualType TreeTransform<Derived>::TransformDependentNameType(
6092 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006093 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006094
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006095 NestedNameSpecifierLoc QualifierLoc
6096 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6097 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006098 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006099
John McCallc392f372010-06-11 00:33:02 +00006100 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006101 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006102 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006103 QualifierLoc,
6104 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006105 TL.getNameLoc(),
6106 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006107 if (Result.isNull())
6108 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006109
Abramo Bagnarad7548482010-05-19 21:37:53 +00006110 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6111 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006112 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6113
Abramo Bagnarad7548482010-05-19 21:37:53 +00006114 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006115 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006116 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006117 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006118 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006119 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006120 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006121 NewTL.setNameLoc(TL.getNameLoc());
6122 }
John McCall550e0c22009-10-21 00:40:46 +00006123 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006124}
Mike Stump11289f42009-09-09 15:08:12 +00006125
Douglas Gregord6ff3322009-08-04 16:50:30 +00006126template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006127QualType TreeTransform<Derived>::
6128 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006129 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006130 NestedNameSpecifierLoc QualifierLoc;
6131 if (TL.getQualifierLoc()) {
6132 QualifierLoc
6133 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6134 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006135 return QualType();
6136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006137
John McCall31f82722010-11-12 08:19:04 +00006138 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006139 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006140}
6141
6142template<typename Derived>
6143QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006144TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6145 DependentTemplateSpecializationTypeLoc TL,
6146 NestedNameSpecifierLoc QualifierLoc) {
6147 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006148
Douglas Gregora7a795b2011-03-01 20:11:18 +00006149 TemplateArgumentListInfo NewTemplateArgs;
6150 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6151 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006152
Douglas Gregora7a795b2011-03-01 20:11:18 +00006153 typedef TemplateArgumentLocContainerIterator<
6154 DependentTemplateSpecializationTypeLoc> ArgIterator;
6155 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6156 ArgIterator(TL, TL.getNumArgs()),
6157 NewTemplateArgs))
6158 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006159
Richard Smithfd3dae02017-01-20 00:20:39 +00006160 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6161 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6162 TL.getTemplateNameLoc(), NewTemplateArgs,
6163 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006164 if (Result.isNull())
6165 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006166
Douglas Gregora7a795b2011-03-01 20:11:18 +00006167 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6168 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006169
Douglas Gregora7a795b2011-03-01 20:11:18 +00006170 // Copy information relevant to the template specialization.
6171 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006172 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006173 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006174 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006175 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6176 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006177 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006178 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006179
Douglas Gregora7a795b2011-03-01 20:11:18 +00006180 // Copy information relevant to the elaborated type.
6181 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006182 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006183 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006184 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6185 DependentTemplateSpecializationTypeLoc SpecTL
6186 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006187 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006188 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006189 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006190 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006191 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6192 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006193 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006194 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006195 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006196 TemplateSpecializationTypeLoc SpecTL
6197 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006198 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006199 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006200 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6201 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006202 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006203 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006204 }
6205 return Result;
6206}
6207
6208template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006209QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6210 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006211 QualType Pattern
6212 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006213 if (Pattern.isNull())
6214 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006215
6216 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006217 if (getDerived().AlwaysRebuild() ||
6218 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006219 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006220 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006221 TL.getEllipsisLoc(),
6222 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006223 if (Result.isNull())
6224 return QualType();
6225 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006226
Douglas Gregor822d0302011-01-12 17:07:58 +00006227 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6228 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6229 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006230}
6231
6232template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006233QualType
6234TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006235 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006236 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006237 TLB.pushFullCopy(TL);
6238 return TL.getType();
6239}
6240
6241template<typename Derived>
6242QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006243TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6244 ObjCTypeParamTypeLoc TL) {
6245 const ObjCTypeParamType *T = TL.getTypePtr();
6246 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6247 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6248 if (!OTP)
6249 return QualType();
6250
6251 QualType Result = TL.getType();
6252 if (getDerived().AlwaysRebuild() ||
6253 OTP != T->getDecl()) {
6254 Result = getDerived().RebuildObjCTypeParamType(OTP,
6255 TL.getProtocolLAngleLoc(),
6256 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6257 TL.getNumProtocols()),
6258 TL.getProtocolLocs(),
6259 TL.getProtocolRAngleLoc());
6260 if (Result.isNull())
6261 return QualType();
6262 }
6263
6264 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6265 if (TL.getNumProtocols()) {
6266 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6267 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6268 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6269 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6270 }
6271 return Result;
6272}
6273
6274template<typename Derived>
6275QualType
John McCall8b07ec22010-05-15 11:32:37 +00006276TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006277 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006278 // Transform base type.
6279 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6280 if (BaseType.isNull())
6281 return QualType();
6282
6283 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6284
6285 // Transform type arguments.
6286 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6287 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6288 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6289 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6290 QualType TypeArg = TypeArgInfo->getType();
6291 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6292 AnyChanged = true;
6293
6294 // We have a pack expansion. Instantiate it.
6295 const auto *PackExpansion = PackExpansionLoc.getType()
6296 ->castAs<PackExpansionType>();
6297 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6298 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6299 Unexpanded);
6300 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6301
6302 // Determine whether the set of unexpanded parameter packs can
6303 // and should be expanded.
6304 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6305 bool Expand = false;
6306 bool RetainExpansion = false;
6307 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6308 if (getDerived().TryExpandParameterPacks(
6309 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6310 Unexpanded, Expand, RetainExpansion, NumExpansions))
6311 return QualType();
6312
6313 if (!Expand) {
6314 // We can't expand this pack expansion into separate arguments yet;
6315 // just substitute into the pattern and create a new pack expansion
6316 // type.
6317 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6318
6319 TypeLocBuilder TypeArgBuilder;
6320 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6321 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6322 PatternLoc);
6323 if (NewPatternType.isNull())
6324 return QualType();
6325
6326 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6327 NewPatternType, NumExpansions);
6328 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6329 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6330 NewTypeArgInfos.push_back(
6331 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6332 continue;
6333 }
6334
6335 // Substitute into the pack expansion pattern for each slice of the
6336 // pack.
6337 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6338 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6339
6340 TypeLocBuilder TypeArgBuilder;
6341 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6342
6343 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6344 PatternLoc);
6345 if (NewTypeArg.isNull())
6346 return QualType();
6347
6348 NewTypeArgInfos.push_back(
6349 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6350 }
6351
6352 continue;
6353 }
6354
6355 TypeLocBuilder TypeArgBuilder;
6356 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6357 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6358 if (NewTypeArg.isNull())
6359 return QualType();
6360
6361 // If nothing changed, just keep the old TypeSourceInfo.
6362 if (NewTypeArg == TypeArg) {
6363 NewTypeArgInfos.push_back(TypeArgInfo);
6364 continue;
6365 }
6366
6367 NewTypeArgInfos.push_back(
6368 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6369 AnyChanged = true;
6370 }
6371
6372 QualType Result = TL.getType();
6373 if (getDerived().AlwaysRebuild() || AnyChanged) {
6374 // Rebuild the type.
6375 Result = getDerived().RebuildObjCObjectType(
6376 BaseType,
6377 TL.getLocStart(),
6378 TL.getTypeArgsLAngleLoc(),
6379 NewTypeArgInfos,
6380 TL.getTypeArgsRAngleLoc(),
6381 TL.getProtocolLAngleLoc(),
6382 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6383 TL.getNumProtocols()),
6384 TL.getProtocolLocs(),
6385 TL.getProtocolRAngleLoc());
6386
6387 if (Result.isNull())
6388 return QualType();
6389 }
6390
6391 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006392 NewT.setHasBaseTypeAsWritten(true);
6393 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6394 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6395 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6396 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6397 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6398 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6399 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6400 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6401 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006402}
Mike Stump11289f42009-09-09 15:08:12 +00006403
6404template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006405QualType
6406TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006407 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006408 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6409 if (PointeeType.isNull())
6410 return QualType();
6411
6412 QualType Result = TL.getType();
6413 if (getDerived().AlwaysRebuild() ||
6414 PointeeType != TL.getPointeeLoc().getType()) {
6415 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6416 TL.getStarLoc());
6417 if (Result.isNull())
6418 return QualType();
6419 }
6420
6421 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6422 NewT.setStarLoc(TL.getStarLoc());
6423 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006424}
6425
Douglas Gregord6ff3322009-08-04 16:50:30 +00006426//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006427// Statement transformation
6428//===----------------------------------------------------------------------===//
6429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006430StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006431TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006432 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006433}
6434
6435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006436StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006437TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6438 return getDerived().TransformCompoundStmt(S, false);
6439}
6440
6441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006442StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006443TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006444 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006445 Sema::CompoundScopeRAII CompoundScope(getSema());
6446
John McCall1ababa62010-08-27 19:56:05 +00006447 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006448 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006449 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006450 for (auto *B : S->body()) {
6451 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006452 if (Result.isInvalid()) {
6453 // Immediately fail if this was a DeclStmt, since it's very
6454 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006455 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006456 return StmtError();
6457
6458 // Otherwise, just keep processing substatements and fail later.
6459 SubStmtInvalid = true;
6460 continue;
6461 }
Mike Stump11289f42009-09-09 15:08:12 +00006462
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006463 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006464 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006465 }
Mike Stump11289f42009-09-09 15:08:12 +00006466
John McCall1ababa62010-08-27 19:56:05 +00006467 if (SubStmtInvalid)
6468 return StmtError();
6469
Douglas Gregorebe10102009-08-20 07:17:43 +00006470 if (!getDerived().AlwaysRebuild() &&
6471 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006472 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006473
6474 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006475 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006476 S->getRBracLoc(),
6477 IsStmtExpr);
6478}
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregorebe10102009-08-20 07:17:43 +00006480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006481StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006482TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006483 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006484 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006485 EnterExpressionEvaluationContext Unevaluated(
6486 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006487
Eli Friedman06577382009-11-19 03:14:00 +00006488 // Transform the left-hand case value.
6489 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006490 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006491 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006492 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006493
Eli Friedman06577382009-11-19 03:14:00 +00006494 // Transform the right-hand case value (for the GNU case-range extension).
6495 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006496 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006497 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006499 }
Mike Stump11289f42009-09-09 15:08:12 +00006500
Douglas Gregorebe10102009-08-20 07:17:43 +00006501 // Build the case statement.
6502 // Case statements are always rebuilt so that they will attached to their
6503 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006504 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006505 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006506 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006507 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006508 S->getColonLoc());
6509 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006510 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006511
Douglas Gregorebe10102009-08-20 07:17:43 +00006512 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006513 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006514 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006515 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregorebe10102009-08-20 07:17:43 +00006517 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006518 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006519}
6520
6521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006522StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006523TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006524 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006525 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006526 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006527 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006528
Douglas Gregorebe10102009-08-20 07:17:43 +00006529 // Default statements are always rebuilt
6530 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006531 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006532}
Mike Stump11289f42009-09-09 15:08:12 +00006533
Douglas Gregorebe10102009-08-20 07:17:43 +00006534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006535StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006536TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006537 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006538 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006539 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006540
Chris Lattnercab02a62011-02-17 20:34:02 +00006541 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6542 S->getDecl());
6543 if (!LD)
6544 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006545
6546
Douglas Gregorebe10102009-08-20 07:17:43 +00006547 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006548 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006549 cast<LabelDecl>(LD), SourceLocation(),
6550 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006551}
Mike Stump11289f42009-09-09 15:08:12 +00006552
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006553template <typename Derived>
6554const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6555 if (!R)
6556 return R;
6557
6558 switch (R->getKind()) {
6559// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6560#define ATTR(X)
6561#define PRAGMA_SPELLING_ATTR(X) \
6562 case attr::X: \
6563 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6564#include "clang/Basic/AttrList.inc"
6565 default:
6566 return R;
6567 }
6568}
6569
6570template <typename Derived>
6571StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6572 bool AttrsChanged = false;
6573 SmallVector<const Attr *, 1> Attrs;
6574
6575 // Visit attributes and keep track if any are transformed.
6576 for (const auto *I : S->getAttrs()) {
6577 const Attr *R = getDerived().TransformAttr(I);
6578 AttrsChanged |= (I != R);
6579 Attrs.push_back(R);
6580 }
6581
Richard Smithc202b282012-04-14 00:33:13 +00006582 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6583 if (SubStmt.isInvalid())
6584 return StmtError();
6585
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006586 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006587 return S;
6588
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006589 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006590 SubStmt.get());
6591}
6592
6593template<typename Derived>
6594StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006595TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006596 // Transform the initialization statement
6597 StmtResult Init = getDerived().TransformStmt(S->getInit());
6598 if (Init.isInvalid())
6599 return StmtError();
6600
Douglas Gregorebe10102009-08-20 07:17:43 +00006601 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006602 Sema::ConditionResult Cond = getDerived().TransformCondition(
6603 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006604 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6605 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006606 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006607 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006608
Richard Smithb130fe72016-06-23 19:16:49 +00006609 // If this is a constexpr if, determine which arm we should instantiate.
6610 llvm::Optional<bool> ConstexprConditionValue;
6611 if (S->isConstexpr())
6612 ConstexprConditionValue = Cond.getKnownValue();
6613
Douglas Gregorebe10102009-08-20 07:17:43 +00006614 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006615 StmtResult Then;
6616 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6617 Then = getDerived().TransformStmt(S->getThen());
6618 if (Then.isInvalid())
6619 return StmtError();
6620 } else {
6621 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6622 }
Mike Stump11289f42009-09-09 15:08:12 +00006623
Douglas Gregorebe10102009-08-20 07:17:43 +00006624 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006625 StmtResult Else;
6626 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6627 Else = getDerived().TransformStmt(S->getElse());
6628 if (Else.isInvalid())
6629 return StmtError();
6630 }
Mike Stump11289f42009-09-09 15:08:12 +00006631
Douglas Gregorebe10102009-08-20 07:17:43 +00006632 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006633 Init.get() == S->getInit() &&
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 Then.get() == S->getThen() &&
6636 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006637 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006638
Richard Smithb130fe72016-06-23 19:16:49 +00006639 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006640 Init.get(), Then.get(), S->getElseLoc(),
6641 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006642}
6643
6644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006645StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006646TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006647 // Transform the initialization statement
6648 StmtResult Init = getDerived().TransformStmt(S->getInit());
6649 if (Init.isInvalid())
6650 return StmtError();
6651
Douglas Gregorebe10102009-08-20 07:17:43 +00006652 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006653 Sema::ConditionResult Cond = getDerived().TransformCondition(
6654 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6655 Sema::ConditionKind::Switch);
6656 if (Cond.isInvalid())
6657 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006658
Douglas Gregorebe10102009-08-20 07:17:43 +00006659 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006660 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006661 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006662 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006663 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregorebe10102009-08-20 07:17:43 +00006665 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006666 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006667 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006668 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006669
Douglas Gregorebe10102009-08-20 07:17:43 +00006670 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006671 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6672 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006673}
Mike Stump11289f42009-09-09 15:08:12 +00006674
Douglas Gregorebe10102009-08-20 07:17:43 +00006675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006676StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006677TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006678 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006679 Sema::ConditionResult Cond = getDerived().TransformCondition(
6680 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6681 Sema::ConditionKind::Boolean);
6682 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006683 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006684
Douglas Gregorebe10102009-08-20 07:17:43 +00006685 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006686 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006687 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006688 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregorebe10102009-08-20 07:17:43 +00006690 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006691 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006692 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006693 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006694
Richard Smith03a4aa32016-06-23 19:02:52 +00006695 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006696}
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregorebe10102009-08-20 07:17:43 +00006698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006699StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006700TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006701 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006702 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006703 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006704 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006705
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006706 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006707 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006708 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006710
Douglas Gregorebe10102009-08-20 07:17:43 +00006711 if (!getDerived().AlwaysRebuild() &&
6712 Cond.get() == S->getCond() &&
6713 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006714 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006715
John McCallb268a282010-08-23 23:25:46 +00006716 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6717 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006718 S->getRParenLoc());
6719}
Mike Stump11289f42009-09-09 15:08:12 +00006720
Douglas Gregorebe10102009-08-20 07:17:43 +00006721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006722StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006723TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006724 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006725 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006726 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006727 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006728
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006729 // In OpenMP loop region loop control variable must be captured and be
6730 // private. Perform analysis of first part (if any).
6731 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6732 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6733
Douglas Gregorebe10102009-08-20 07:17:43 +00006734 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006735 Sema::ConditionResult Cond = getDerived().TransformCondition(
6736 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6737 Sema::ConditionKind::Boolean);
6738 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006740
Douglas Gregorebe10102009-08-20 07:17:43 +00006741 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006742 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006743 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006744 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006745
Richard Smith945f8d32013-01-14 22:39:08 +00006746 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006747 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006748 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006749
Douglas Gregorebe10102009-08-20 07:17:43 +00006750 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006751 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006752 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006753 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregorebe10102009-08-20 07:17:43 +00006755 if (!getDerived().AlwaysRebuild() &&
6756 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006757 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006758 Inc.get() == S->getInc() &&
6759 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006760 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregorebe10102009-08-20 07:17:43 +00006762 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006763 Init.get(), Cond, FullInc,
6764 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006765}
6766
6767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006768StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006769TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006770 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6771 S->getLabel());
6772 if (!LD)
6773 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006774
Douglas Gregorebe10102009-08-20 07:17:43 +00006775 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006776 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006777 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006778}
6779
6780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006781StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006782TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006783 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006784 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006786 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006787
Douglas Gregorebe10102009-08-20 07:17:43 +00006788 if (!getDerived().AlwaysRebuild() &&
6789 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006790 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006791
6792 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006793 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006794}
6795
6796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006798TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006799 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006800}
Mike Stump11289f42009-09-09 15:08:12 +00006801
Douglas Gregorebe10102009-08-20 07:17:43 +00006802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006803StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006804TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006805 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006806}
Mike Stump11289f42009-09-09 15:08:12 +00006807
Douglas Gregorebe10102009-08-20 07:17:43 +00006808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006809StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006810TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006811 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6812 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006813 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006814 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006815
Mike Stump11289f42009-09-09 15:08:12 +00006816 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006817 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006818 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006819}
Mike Stump11289f42009-09-09 15:08:12 +00006820
Douglas Gregorebe10102009-08-20 07:17:43 +00006821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006822StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006823TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006824 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006825 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006826 for (auto *D : S->decls()) {
6827 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006828 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006829 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006830
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006831 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006832 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregorebe10102009-08-20 07:17:43 +00006834 Decls.push_back(Transformed);
6835 }
Mike Stump11289f42009-09-09 15:08:12 +00006836
Douglas Gregorebe10102009-08-20 07:17:43 +00006837 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006838 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006839
Rafael Espindolaab417692013-07-09 12:05:01 +00006840 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006841}
Mike Stump11289f42009-09-09 15:08:12 +00006842
Douglas Gregorebe10102009-08-20 07:17:43 +00006843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006844StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006845TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006846
Benjamin Kramerf0623432012-08-23 22:51:59 +00006847 SmallVector<Expr*, 8> Constraints;
6848 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006849 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006850
John McCalldadc5752010-08-24 06:29:42 +00006851 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006852 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006853
6854 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006855
Anders Carlssonaaeef072010-01-24 05:50:09 +00006856 // Go through the outputs.
6857 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006858 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006859
Anders Carlssonaaeef072010-01-24 05:50:09 +00006860 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006861 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006862
Anders Carlssonaaeef072010-01-24 05:50:09 +00006863 // Transform the output expr.
6864 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006865 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006866 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006868
Anders Carlssonaaeef072010-01-24 05:50:09 +00006869 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006870
John McCallb268a282010-08-23 23:25:46 +00006871 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006873
Anders Carlssonaaeef072010-01-24 05:50:09 +00006874 // Go through the inputs.
6875 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006876 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006877
Anders Carlssonaaeef072010-01-24 05:50:09 +00006878 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006879 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006880
Anders Carlssonaaeef072010-01-24 05:50:09 +00006881 // Transform the input expr.
6882 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006883 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006884 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006885 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006886
Anders Carlssonaaeef072010-01-24 05:50:09 +00006887 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006888
John McCallb268a282010-08-23 23:25:46 +00006889 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006891
Anders Carlssonaaeef072010-01-24 05:50:09 +00006892 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006893 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006894
6895 // Go through the clobbers.
6896 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006897 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006898
6899 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006900 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006901 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6902 S->isVolatile(), S->getNumOutputs(),
6903 S->getNumInputs(), Names.data(),
6904 Constraints, Exprs, AsmString.get(),
6905 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006906}
6907
Chad Rosier32503022012-06-11 20:47:18 +00006908template<typename Derived>
6909StmtResult
6910TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006911 ArrayRef<Token> AsmToks =
6912 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006913
John McCallf413f5e2013-05-03 00:10:13 +00006914 bool HadError = false, HadChange = false;
6915
6916 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6917 SmallVector<Expr*, 8> TransformedExprs;
6918 TransformedExprs.reserve(SrcExprs.size());
6919 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6920 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6921 if (!Result.isUsable()) {
6922 HadError = true;
6923 } else {
6924 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006925 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006926 }
6927 }
6928
6929 if (HadError) return StmtError();
6930 if (!HadChange && !getDerived().AlwaysRebuild())
6931 return Owned(S);
6932
Chad Rosierb6f46c12012-08-15 16:53:30 +00006933 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006934 AsmToks, S->getAsmString(),
6935 S->getNumOutputs(), S->getNumInputs(),
6936 S->getAllConstraints(), S->getClobbers(),
6937 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006938}
Douglas Gregorebe10102009-08-20 07:17:43 +00006939
Richard Smith9f690bd2015-10-27 06:02:45 +00006940// C++ Coroutines TS
6941
6942template<typename Derived>
6943StmtResult
6944TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006945 auto *ScopeInfo = SemaRef.getCurFunction();
6946 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00006947 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006948 ScopeInfo->NeedsCoroutineSuspends &&
6949 ScopeInfo->CoroutineSuspends.first == nullptr &&
6950 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00006951 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006952
6953 // Set that we have (possibly-invalid) suspend points before we do anything
6954 // that may fail.
6955 ScopeInfo->setNeedsCoroutineSuspends(false);
6956
6957 // The new CoroutinePromise object needs to be built and put into the current
6958 // FunctionScopeInfo before any transformations or rebuilding occurs.
Eric Fiselierbee782b2017-04-03 19:21:00 +00006959 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6960 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006961 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006962 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6963 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006964
6965 // Transform the implicit coroutine statements we built during the initial
6966 // parse.
6967 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6968 if (InitSuspend.isInvalid())
6969 return StmtError();
6970 StmtResult FinalSuspend =
6971 getDerived().TransformStmt(S->getFinalSuspendStmt());
6972 if (FinalSuspend.isInvalid())
6973 return StmtError();
6974 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6975 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006976
6977 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6978 if (BodyRes.isInvalid())
6979 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006980
Eric Fiselierbee782b2017-04-03 19:21:00 +00006981 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6982 if (Builder.isInvalid())
6983 return StmtError();
6984
6985 Expr *ReturnObject = S->getReturnValueInit();
6986 assert(ReturnObject && "the return object is expected to be valid");
6987 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6988 /*NoCopyInit*/ false);
6989 if (Res.isInvalid())
6990 return StmtError();
6991 Builder.ReturnValue = Res.get();
6992
6993 if (S->hasDependentPromiseType()) {
6994 assert(!Promise->getType()->isDependentType() &&
6995 "the promise type must no longer be dependent");
6996 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6997 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6998 "these nodes should not have been built yet");
6999 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007000 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007001 } else {
7002 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7003 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7004 if (Res.isInvalid())
7005 return StmtError();
7006 Builder.OnFallthrough = Res.get();
7007 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007008
Eric Fiselierbee782b2017-04-03 19:21:00 +00007009 if (auto *OnException = S->getExceptionHandler()) {
7010 StmtResult Res = getDerived().TransformStmt(OnException);
7011 if (Res.isInvalid())
7012 return StmtError();
7013 Builder.OnException = Res.get();
7014 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007015
Eric Fiselierbee782b2017-04-03 19:21:00 +00007016 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7017 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7018 if (Res.isInvalid())
7019 return StmtError();
7020 Builder.ReturnStmtOnAllocFailure = Res.get();
7021 }
7022
7023 // Transform any additional statements we may have already built
7024 assert(S->getAllocate() && S->getDeallocate() &&
7025 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007026 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7027 if (AllocRes.isInvalid())
7028 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007029 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007030
7031 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7032 if (DeallocRes.isInvalid())
7033 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007034 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007035
7036 assert(S->getResultDecl() && "ResultDecl must already be built");
7037 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7038 if (ResultDecl.isInvalid())
7039 return StmtError();
7040 Builder.ResultDecl = ResultDecl.get();
7041
7042 if (auto *ReturnStmt = S->getReturnStmt()) {
7043 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7044 if (Res.isInvalid())
7045 return StmtError();
7046 Builder.ReturnStmt = Res.get();
7047 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007048 }
Eric Fiselierde7943b2017-06-03 00:22:18 +00007049 if (!Builder.buildParameterMoves())
7050 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007051
Eric Fiselierbee782b2017-04-03 19:21:00 +00007052 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007053}
7054
7055template<typename Derived>
7056StmtResult
7057TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7058 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7059 /*NotCopyInit*/false);
7060 if (Result.isInvalid())
7061 return StmtError();
7062
7063 // Always rebuild; we don't know if this needs to be injected into a new
7064 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007065 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7066 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007067}
7068
7069template<typename Derived>
7070ExprResult
7071TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7072 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7073 /*NotCopyInit*/false);
7074 if (Result.isInvalid())
7075 return ExprError();
7076
7077 // Always rebuild; we don't know if this needs to be injected into a new
7078 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007079 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7080 E->isImplicit());
7081}
7082
7083template <typename Derived>
7084ExprResult
7085TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7086 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7087 /*NotCopyInit*/ false);
7088 if (OperandResult.isInvalid())
7089 return ExprError();
7090
7091 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7092 E->getOperatorCoawaitLookup());
7093
7094 if (LookupResult.isInvalid())
7095 return ExprError();
7096
7097 // Always rebuild; we don't know if this needs to be injected into a new
7098 // context or if the promise type has changed.
7099 return getDerived().RebuildDependentCoawaitExpr(
7100 E->getKeywordLoc(), OperandResult.get(),
7101 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007102}
7103
7104template<typename Derived>
7105ExprResult
7106TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7107 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7108 /*NotCopyInit*/false);
7109 if (Result.isInvalid())
7110 return ExprError();
7111
7112 // Always rebuild; we don't know if this needs to be injected into a new
7113 // context or if the promise type has changed.
7114 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7115}
7116
7117// Objective-C Statements.
7118
Douglas Gregorebe10102009-08-20 07:17:43 +00007119template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007120StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007121TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007122 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007123 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007124 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007125 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007126
Douglas Gregor96c79492010-04-23 22:50:49 +00007127 // Transform the @catch statements (if present).
7128 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007129 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007130 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007131 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007132 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007133 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007134 if (Catch.get() != S->getCatchStmt(I))
7135 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007136 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007137 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007138
Douglas Gregor306de2f2010-04-22 23:59:56 +00007139 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007140 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007141 if (S->getFinallyStmt()) {
7142 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7143 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007144 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007145 }
7146
7147 // If nothing changed, just retain this statement.
7148 if (!getDerived().AlwaysRebuild() &&
7149 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007150 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007151 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007152 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007153
Douglas Gregor306de2f2010-04-22 23:59:56 +00007154 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007155 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007156 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007157}
Mike Stump11289f42009-09-09 15:08:12 +00007158
Douglas Gregorebe10102009-08-20 07:17:43 +00007159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007160StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007161TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007162 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007163 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007164 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007165 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007166 if (FromVar->getTypeSourceInfo()) {
7167 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7168 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007169 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007171
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007172 QualType T;
7173 if (TSInfo)
7174 T = TSInfo->getType();
7175 else {
7176 T = getDerived().TransformType(FromVar->getType());
7177 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007178 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007179 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007180
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007181 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7182 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007183 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007184 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007185
John McCalldadc5752010-08-24 06:29:42 +00007186 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007187 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007188 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007189
7190 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007191 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007192 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007193}
Mike Stump11289f42009-09-09 15:08:12 +00007194
Douglas Gregorebe10102009-08-20 07:17:43 +00007195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007196StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007197TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007198 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007199 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007200 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007201 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007202
Douglas Gregor306de2f2010-04-22 23:59:56 +00007203 // If nothing changed, just retain this statement.
7204 if (!getDerived().AlwaysRebuild() &&
7205 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007206 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007207
7208 // Build a new statement.
7209 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007210 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007211}
Mike Stump11289f42009-09-09 15:08:12 +00007212
Douglas Gregorebe10102009-08-20 07:17:43 +00007213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007214StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007215TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007216 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007217 if (S->getThrowExpr()) {
7218 Operand = getDerived().TransformExpr(S->getThrowExpr());
7219 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007220 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007222
Douglas Gregor2900c162010-04-22 21:44:01 +00007223 if (!getDerived().AlwaysRebuild() &&
7224 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007225 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007226
John McCallb268a282010-08-23 23:25:46 +00007227 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007228}
Mike Stump11289f42009-09-09 15:08:12 +00007229
Douglas Gregorebe10102009-08-20 07:17:43 +00007230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007231StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007232TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007233 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007234 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007235 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007236 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007237 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007238 Object =
7239 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7240 Object.get());
7241 if (Object.isInvalid())
7242 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007243
Douglas Gregor6148de72010-04-22 22:01:21 +00007244 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007245 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007246 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007247 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007248
Douglas Gregor6148de72010-04-22 22:01:21 +00007249 // If nothing change, just retain the current statement.
7250 if (!getDerived().AlwaysRebuild() &&
7251 Object.get() == S->getSynchExpr() &&
7252 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007253 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007254
7255 // Build a new statement.
7256 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007257 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007258}
7259
7260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007261StmtResult
John McCall31168b02011-06-15 23:02:42 +00007262TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7263 ObjCAutoreleasePoolStmt *S) {
7264 // Transform the body.
7265 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7266 if (Body.isInvalid())
7267 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007268
John McCall31168b02011-06-15 23:02:42 +00007269 // If nothing changed, just retain this statement.
7270 if (!getDerived().AlwaysRebuild() &&
7271 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007272 return S;
John McCall31168b02011-06-15 23:02:42 +00007273
7274 // Build a new statement.
7275 return getDerived().RebuildObjCAutoreleasePoolStmt(
7276 S->getAtLoc(), Body.get());
7277}
7278
7279template<typename Derived>
7280StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007281TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007282 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007283 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007284 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007285 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007286 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007287
Douglas Gregorf68a5082010-04-22 23:10:45 +00007288 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007289 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007290 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007291 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007292
Douglas Gregorf68a5082010-04-22 23:10:45 +00007293 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007294 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007295 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007296 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007297
Douglas Gregorf68a5082010-04-22 23:10:45 +00007298 // If nothing changed, just retain this statement.
7299 if (!getDerived().AlwaysRebuild() &&
7300 Element.get() == S->getElement() &&
7301 Collection.get() == S->getCollection() &&
7302 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007303 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007304
Douglas Gregorf68a5082010-04-22 23:10:45 +00007305 // Build a new statement.
7306 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007307 Element.get(),
7308 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007309 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007310 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007311}
7312
David Majnemer5f7efef2013-10-15 09:50:08 +00007313template <typename Derived>
7314StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007315 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007316 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007317 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7318 TypeSourceInfo *T =
7319 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007320 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007322
David Majnemer5f7efef2013-10-15 09:50:08 +00007323 Var = getDerived().RebuildExceptionDecl(
7324 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7325 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007326 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007327 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007328 }
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregorebe10102009-08-20 07:17:43 +00007330 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007331 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007332 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007333 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007334
David Majnemer5f7efef2013-10-15 09:50:08 +00007335 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007336 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007337 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007338
David Majnemer5f7efef2013-10-15 09:50:08 +00007339 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007340}
Mike Stump11289f42009-09-09 15:08:12 +00007341
David Majnemer5f7efef2013-10-15 09:50:08 +00007342template <typename Derived>
7343StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007344 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007345 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007346 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007347 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007348
Douglas Gregorebe10102009-08-20 07:17:43 +00007349 // Transform the handlers.
7350 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007351 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007352 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007353 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007354 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007355 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007356
Douglas Gregorebe10102009-08-20 07:17:43 +00007357 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007358 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007359 }
Mike Stump11289f42009-09-09 15:08:12 +00007360
David Majnemer5f7efef2013-10-15 09:50:08 +00007361 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007362 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007363 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007364
John McCallb268a282010-08-23 23:25:46 +00007365 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007366 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007367}
Mike Stump11289f42009-09-09 15:08:12 +00007368
Richard Smith02e85f32011-04-14 22:09:26 +00007369template<typename Derived>
7370StmtResult
7371TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7372 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7373 if (Range.isInvalid())
7374 return StmtError();
7375
Richard Smith01694c32016-03-20 10:33:40 +00007376 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7377 if (Begin.isInvalid())
7378 return StmtError();
7379 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7380 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007381 return StmtError();
7382
7383 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7384 if (Cond.isInvalid())
7385 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007386 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007387 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007388 if (Cond.isInvalid())
7389 return StmtError();
7390 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007391 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007392
7393 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7394 if (Inc.isInvalid())
7395 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007396 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007397 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007398
7399 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7400 if (LoopVar.isInvalid())
7401 return StmtError();
7402
7403 StmtResult NewStmt = S;
7404 if (getDerived().AlwaysRebuild() ||
7405 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007406 Begin.get() != S->getBeginStmt() ||
7407 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007408 Cond.get() != S->getCond() ||
7409 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007410 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007411 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007412 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007413 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007414 Begin.get(), End.get(),
7415 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007416 Inc.get(), LoopVar.get(),
7417 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007418 if (NewStmt.isInvalid())
7419 return StmtError();
7420 }
Richard Smith02e85f32011-04-14 22:09:26 +00007421
7422 StmtResult Body = getDerived().TransformStmt(S->getBody());
7423 if (Body.isInvalid())
7424 return StmtError();
7425
7426 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7427 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007428 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007429 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007430 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007431 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007432 Begin.get(), End.get(),
7433 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007434 Inc.get(), LoopVar.get(),
7435 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007436 if (NewStmt.isInvalid())
7437 return StmtError();
7438 }
Richard Smith02e85f32011-04-14 22:09:26 +00007439
7440 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007441 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007442
7443 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7444}
7445
John Wiegley1c0675e2011-04-28 01:08:34 +00007446template<typename Derived>
7447StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007448TreeTransform<Derived>::TransformMSDependentExistsStmt(
7449 MSDependentExistsStmt *S) {
7450 // Transform the nested-name-specifier, if any.
7451 NestedNameSpecifierLoc QualifierLoc;
7452 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007453 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007454 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7455 if (!QualifierLoc)
7456 return StmtError();
7457 }
7458
7459 // Transform the declaration name.
7460 DeclarationNameInfo NameInfo = S->getNameInfo();
7461 if (NameInfo.getName()) {
7462 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7463 if (!NameInfo.getName())
7464 return StmtError();
7465 }
7466
7467 // Check whether anything changed.
7468 if (!getDerived().AlwaysRebuild() &&
7469 QualifierLoc == S->getQualifierLoc() &&
7470 NameInfo.getName() == S->getNameInfo().getName())
7471 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007472
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007473 // Determine whether this name exists, if we can.
7474 CXXScopeSpec SS;
7475 SS.Adopt(QualifierLoc);
7476 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007477 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007478 case Sema::IER_Exists:
7479 if (S->isIfExists())
7480 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007481
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007482 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7483
7484 case Sema::IER_DoesNotExist:
7485 if (S->isIfNotExists())
7486 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007487
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007488 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007489
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007490 case Sema::IER_Dependent:
7491 Dependent = true;
7492 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007493
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007494 case Sema::IER_Error:
7495 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007497
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007498 // We need to continue with the instantiation, so do so now.
7499 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7500 if (SubStmt.isInvalid())
7501 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007502
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007503 // If we have resolved the name, just transform to the substatement.
7504 if (!Dependent)
7505 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007506
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007507 // The name is still dependent, so build a dependent expression again.
7508 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7509 S->isIfExists(),
7510 QualifierLoc,
7511 NameInfo,
7512 SubStmt.get());
7513}
7514
7515template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007516ExprResult
7517TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7518 NestedNameSpecifierLoc QualifierLoc;
7519 if (E->getQualifierLoc()) {
7520 QualifierLoc
7521 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7522 if (!QualifierLoc)
7523 return ExprError();
7524 }
7525
7526 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7527 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7528 if (!PD)
7529 return ExprError();
7530
7531 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7532 if (Base.isInvalid())
7533 return ExprError();
7534
7535 return new (SemaRef.getASTContext())
7536 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7537 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7538 QualifierLoc, E->getMemberLoc());
7539}
7540
David Majnemerfad8f482013-10-15 09:33:02 +00007541template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007542ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7543 MSPropertySubscriptExpr *E) {
7544 auto BaseRes = getDerived().TransformExpr(E->getBase());
7545 if (BaseRes.isInvalid())
7546 return ExprError();
7547 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7548 if (IdxRes.isInvalid())
7549 return ExprError();
7550
7551 if (!getDerived().AlwaysRebuild() &&
7552 BaseRes.get() == E->getBase() &&
7553 IdxRes.get() == E->getIdx())
7554 return E;
7555
7556 return getDerived().RebuildArraySubscriptExpr(
7557 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7558}
7559
7560template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007561StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007562 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007563 if (TryBlock.isInvalid())
7564 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007565
7566 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007567 if (Handler.isInvalid())
7568 return StmtError();
7569
David Majnemerfad8f482013-10-15 09:33:02 +00007570 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7571 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007572 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007573
Warren Huntf6be4cb2014-07-25 20:52:51 +00007574 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7575 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007576}
7577
David Majnemerfad8f482013-10-15 09:33:02 +00007578template <typename Derived>
7579StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007580 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007581 if (Block.isInvalid())
7582 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007583
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007584 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007585}
7586
David Majnemerfad8f482013-10-15 09:33:02 +00007587template <typename Derived>
7588StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007589 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007590 if (FilterExpr.isInvalid())
7591 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007592
David Majnemer7e755502013-10-15 09:30:14 +00007593 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007594 if (Block.isInvalid())
7595 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007596
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007597 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7598 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007599}
7600
David Majnemerfad8f482013-10-15 09:33:02 +00007601template <typename Derived>
7602StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7603 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007604 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7605 else
7606 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7607}
7608
Nico Weber9b982072014-07-07 00:12:30 +00007609template<typename Derived>
7610StmtResult
7611TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7612 return S;
7613}
7614
Alexander Musman64d33f12014-06-04 07:53:32 +00007615//===----------------------------------------------------------------------===//
7616// OpenMP directive transformation
7617//===----------------------------------------------------------------------===//
7618template <typename Derived>
7619StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7620 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007622 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007623 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007624 ArrayRef<OMPClause *> Clauses = D->clauses();
7625 TClauses.reserve(Clauses.size());
7626 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7627 I != E; ++I) {
7628 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007629 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007630 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007631 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007632 if (Clause)
7633 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007634 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007635 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007636 }
7637 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007638 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007639 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007640 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7641 /*CurScope=*/nullptr);
7642 StmtResult Body;
7643 {
7644 Sema::CompoundScopeRAII CompoundScope(getSema());
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007645 int ThisCaptureLevel =
7646 Sema::getOpenMPCaptureLevels(D->getDirectiveKind());
7647 Stmt *CS = D->getAssociatedStmt();
7648 while (--ThisCaptureLevel >= 0)
7649 CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7650 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007651 }
7652 AssociatedStmt =
7653 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007654 if (AssociatedStmt.isInvalid()) {
7655 return StmtError();
7656 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007657 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007658 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007659 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007660 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007661
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007662 // Transform directive name for 'omp critical' directive.
7663 DeclarationNameInfo DirName;
7664 if (D->getDirectiveKind() == OMPD_critical) {
7665 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7666 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7667 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007668 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7669 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7670 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007671 } else if (D->getDirectiveKind() == OMPD_cancel) {
7672 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007673 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007674
Alexander Musman64d33f12014-06-04 07:53:32 +00007675 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007676 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7677 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007678}
7679
Alexander Musman64d33f12014-06-04 07:53:32 +00007680template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007681StmtResult
7682TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7683 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007684 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7685 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007686 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7687 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7688 return Res;
7689}
7690
Alexander Musman64d33f12014-06-04 07:53:32 +00007691template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007692StmtResult
7693TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7694 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007695 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7696 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007697 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7698 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007699 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007700}
7701
Alexey Bataevf29276e2014-06-18 04:14:57 +00007702template <typename Derived>
7703StmtResult
7704TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7705 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007706 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7707 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007708 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7709 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7710 return Res;
7711}
7712
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007713template <typename Derived>
7714StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007715TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7716 DeclarationNameInfo DirName;
7717 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7718 D->getLocStart());
7719 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7720 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7721 return Res;
7722}
7723
7724template <typename Derived>
7725StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007726TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7727 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007728 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7729 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007730 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7731 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7732 return Res;
7733}
7734
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007735template <typename Derived>
7736StmtResult
7737TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7738 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007739 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7740 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007741 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7742 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7743 return Res;
7744}
7745
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007746template <typename Derived>
7747StmtResult
7748TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7749 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007750 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7751 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007752 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7753 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7754 return Res;
7755}
7756
Alexey Bataev4acb8592014-07-07 13:01:15 +00007757template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007758StmtResult
7759TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7760 DeclarationNameInfo DirName;
7761 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7762 D->getLocStart());
7763 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7764 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7765 return Res;
7766}
7767
7768template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007769StmtResult
7770TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7771 getDerived().getSema().StartOpenMPDSABlock(
7772 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7773 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7774 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7775 return Res;
7776}
7777
7778template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007779StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7780 OMPParallelForDirective *D) {
7781 DeclarationNameInfo DirName;
7782 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7783 nullptr, D->getLocStart());
7784 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7785 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7786 return Res;
7787}
7788
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007789template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007790StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7791 OMPParallelForSimdDirective *D) {
7792 DeclarationNameInfo DirName;
7793 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7794 nullptr, D->getLocStart());
7795 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7796 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7797 return Res;
7798}
7799
7800template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007801StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7802 OMPParallelSectionsDirective *D) {
7803 DeclarationNameInfo DirName;
7804 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7805 nullptr, D->getLocStart());
7806 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7807 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7808 return Res;
7809}
7810
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007811template <typename Derived>
7812StmtResult
7813TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7814 DeclarationNameInfo DirName;
7815 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7816 D->getLocStart());
7817 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7818 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7819 return Res;
7820}
7821
Alexey Bataev68446b72014-07-18 07:47:19 +00007822template <typename Derived>
7823StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7824 OMPTaskyieldDirective *D) {
7825 DeclarationNameInfo DirName;
7826 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7827 D->getLocStart());
7828 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7829 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7830 return Res;
7831}
7832
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007833template <typename Derived>
7834StmtResult
7835TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7836 DeclarationNameInfo DirName;
7837 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7838 D->getLocStart());
7839 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7840 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7841 return Res;
7842}
7843
Alexey Bataev2df347a2014-07-18 10:17:07 +00007844template <typename Derived>
7845StmtResult
7846TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7847 DeclarationNameInfo DirName;
7848 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7849 D->getLocStart());
7850 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7851 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7852 return Res;
7853}
7854
Alexey Bataev6125da92014-07-21 11:26:11 +00007855template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007856StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7857 OMPTaskgroupDirective *D) {
7858 DeclarationNameInfo DirName;
7859 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7860 D->getLocStart());
7861 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7862 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7863 return Res;
7864}
7865
7866template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007867StmtResult
7868TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7869 DeclarationNameInfo DirName;
7870 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7871 D->getLocStart());
7872 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7873 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7874 return Res;
7875}
7876
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007877template <typename Derived>
7878StmtResult
7879TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7880 DeclarationNameInfo DirName;
7881 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7882 D->getLocStart());
7883 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7884 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7885 return Res;
7886}
7887
Alexey Bataev0162e452014-07-22 10:10:35 +00007888template <typename Derived>
7889StmtResult
7890TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7891 DeclarationNameInfo DirName;
7892 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7893 D->getLocStart());
7894 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7895 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7896 return Res;
7897}
7898
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007899template <typename Derived>
7900StmtResult
7901TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7902 DeclarationNameInfo DirName;
7903 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7904 D->getLocStart());
7905 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7906 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7907 return Res;
7908}
7909
Alexey Bataev13314bf2014-10-09 04:18:56 +00007910template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007911StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7912 OMPTargetDataDirective *D) {
7913 DeclarationNameInfo DirName;
7914 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7915 D->getLocStart());
7916 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7917 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7918 return Res;
7919}
7920
7921template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007922StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7923 OMPTargetEnterDataDirective *D) {
7924 DeclarationNameInfo DirName;
7925 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7926 nullptr, D->getLocStart());
7927 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7928 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7929 return Res;
7930}
7931
7932template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007933StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7934 OMPTargetExitDataDirective *D) {
7935 DeclarationNameInfo DirName;
7936 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7937 nullptr, D->getLocStart());
7938 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7939 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7940 return Res;
7941}
7942
7943template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007944StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7945 OMPTargetParallelDirective *D) {
7946 DeclarationNameInfo DirName;
7947 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7948 nullptr, D->getLocStart());
7949 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7950 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7951 return Res;
7952}
7953
7954template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007955StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7956 OMPTargetParallelForDirective *D) {
7957 DeclarationNameInfo DirName;
7958 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7959 nullptr, D->getLocStart());
7960 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7961 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7962 return Res;
7963}
7964
7965template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007966StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7967 OMPTargetUpdateDirective *D) {
7968 DeclarationNameInfo DirName;
7969 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7970 nullptr, D->getLocStart());
7971 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7972 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7973 return Res;
7974}
7975
7976template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007977StmtResult
7978TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7979 DeclarationNameInfo DirName;
7980 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7981 D->getLocStart());
7982 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7983 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7984 return Res;
7985}
7986
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007987template <typename Derived>
7988StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7989 OMPCancellationPointDirective *D) {
7990 DeclarationNameInfo DirName;
7991 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7992 nullptr, D->getLocStart());
7993 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7994 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7995 return Res;
7996}
7997
Alexey Bataev80909872015-07-02 11:25:17 +00007998template <typename Derived>
7999StmtResult
8000TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8001 DeclarationNameInfo DirName;
8002 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
8003 D->getLocStart());
8004 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8005 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8006 return Res;
8007}
8008
Alexey Bataev49f6e782015-12-01 04:18:41 +00008009template <typename Derived>
8010StmtResult
8011TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8012 DeclarationNameInfo DirName;
8013 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
8014 D->getLocStart());
8015 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8016 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8017 return Res;
8018}
8019
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008020template <typename Derived>
8021StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8022 OMPTaskLoopSimdDirective *D) {
8023 DeclarationNameInfo DirName;
8024 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
8025 nullptr, D->getLocStart());
8026 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8027 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8028 return Res;
8029}
8030
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008031template <typename Derived>
8032StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8033 OMPDistributeDirective *D) {
8034 DeclarationNameInfo DirName;
8035 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
8036 D->getLocStart());
8037 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8038 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8039 return Res;
8040}
8041
Carlo Bertolli9925f152016-06-27 14:55:37 +00008042template <typename Derived>
8043StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8044 OMPDistributeParallelForDirective *D) {
8045 DeclarationNameInfo DirName;
8046 getDerived().getSema().StartOpenMPDSABlock(
8047 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
8048 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8049 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8050 return Res;
8051}
8052
Kelvin Li4a39add2016-07-05 05:00:15 +00008053template <typename Derived>
8054StmtResult
8055TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8056 OMPDistributeParallelForSimdDirective *D) {
8057 DeclarationNameInfo DirName;
8058 getDerived().getSema().StartOpenMPDSABlock(
8059 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8060 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8061 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8062 return Res;
8063}
8064
Kelvin Li787f3fc2016-07-06 04:45:38 +00008065template <typename Derived>
8066StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8067 OMPDistributeSimdDirective *D) {
8068 DeclarationNameInfo DirName;
8069 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
8070 nullptr, D->getLocStart());
8071 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8072 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8073 return Res;
8074}
8075
Kelvin Lia579b912016-07-14 02:54:56 +00008076template <typename Derived>
8077StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8078 OMPTargetParallelForSimdDirective *D) {
8079 DeclarationNameInfo DirName;
8080 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8081 DirName, nullptr,
8082 D->getLocStart());
8083 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8084 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8085 return Res;
8086}
8087
Kelvin Li986330c2016-07-20 22:57:10 +00008088template <typename Derived>
8089StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8090 OMPTargetSimdDirective *D) {
8091 DeclarationNameInfo DirName;
8092 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8093 D->getLocStart());
8094 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8095 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8096 return Res;
8097}
8098
Kelvin Li02532872016-08-05 14:37:37 +00008099template <typename Derived>
8100StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8101 OMPTeamsDistributeDirective *D) {
8102 DeclarationNameInfo DirName;
8103 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8104 nullptr, D->getLocStart());
8105 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8106 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8107 return Res;
8108}
8109
Kelvin Li4e325f72016-10-25 12:50:55 +00008110template <typename Derived>
8111StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8112 OMPTeamsDistributeSimdDirective *D) {
8113 DeclarationNameInfo DirName;
8114 getDerived().getSema().StartOpenMPDSABlock(
8115 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8116 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8117 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8118 return Res;
8119}
8120
Kelvin Li579e41c2016-11-30 23:51:03 +00008121template <typename Derived>
8122StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8123 OMPTeamsDistributeParallelForSimdDirective *D) {
8124 DeclarationNameInfo DirName;
8125 getDerived().getSema().StartOpenMPDSABlock(
8126 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8127 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8128 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8129 return Res;
8130}
8131
Kelvin Li7ade93f2016-12-09 03:24:30 +00008132template <typename Derived>
8133StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8134 OMPTeamsDistributeParallelForDirective *D) {
8135 DeclarationNameInfo DirName;
8136 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8137 DirName, nullptr, D->getLocStart());
8138 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8139 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8140 return Res;
8141}
8142
Kelvin Libf594a52016-12-17 05:48:59 +00008143template <typename Derived>
8144StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8145 OMPTargetTeamsDirective *D) {
8146 DeclarationNameInfo DirName;
8147 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8148 nullptr, D->getLocStart());
8149 auto Res = getDerived().TransformOMPExecutableDirective(D);
8150 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8151 return Res;
8152}
Kelvin Li579e41c2016-11-30 23:51:03 +00008153
Kelvin Li83c451e2016-12-25 04:52:54 +00008154template <typename Derived>
8155StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8156 OMPTargetTeamsDistributeDirective *D) {
8157 DeclarationNameInfo DirName;
8158 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8159 DirName, nullptr, D->getLocStart());
8160 auto Res = getDerived().TransformOMPExecutableDirective(D);
8161 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8162 return Res;
8163}
8164
Kelvin Li80e8f562016-12-29 22:16:30 +00008165template <typename Derived>
8166StmtResult
8167TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8168 OMPTargetTeamsDistributeParallelForDirective *D) {
8169 DeclarationNameInfo DirName;
8170 getDerived().getSema().StartOpenMPDSABlock(
8171 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8172 D->getLocStart());
8173 auto Res = getDerived().TransformOMPExecutableDirective(D);
8174 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8175 return Res;
8176}
8177
Kelvin Li1851df52017-01-03 05:23:48 +00008178template <typename Derived>
8179StmtResult TreeTransform<Derived>::
8180 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8181 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8182 DeclarationNameInfo DirName;
8183 getDerived().getSema().StartOpenMPDSABlock(
8184 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8185 D->getLocStart());
8186 auto Res = getDerived().TransformOMPExecutableDirective(D);
8187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8188 return Res;
8189}
8190
Kelvin Lida681182017-01-10 18:08:18 +00008191template <typename Derived>
8192StmtResult
8193TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8194 OMPTargetTeamsDistributeSimdDirective *D) {
8195 DeclarationNameInfo DirName;
8196 getDerived().getSema().StartOpenMPDSABlock(
8197 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8198 auto Res = getDerived().TransformOMPExecutableDirective(D);
8199 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8200 return Res;
8201}
8202
Kelvin Li1851df52017-01-03 05:23:48 +00008203
Alexander Musman64d33f12014-06-04 07:53:32 +00008204//===----------------------------------------------------------------------===//
8205// OpenMP clause transformation
8206//===----------------------------------------------------------------------===//
8207template <typename Derived>
8208OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008209 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8210 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008211 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008212 return getDerived().RebuildOMPIfClause(
8213 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8214 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008215}
8216
Alexander Musman64d33f12014-06-04 07:53:32 +00008217template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008218OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8219 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8220 if (Cond.isInvalid())
8221 return nullptr;
8222 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8223 C->getLParenLoc(), C->getLocEnd());
8224}
8225
8226template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008227OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008228TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8229 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8230 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008231 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008232 return getDerived().RebuildOMPNumThreadsClause(
8233 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00008234}
8235
Alexey Bataev62c87d22014-03-21 04:51:18 +00008236template <typename Derived>
8237OMPClause *
8238TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8239 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8240 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008241 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008242 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008243 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008244}
8245
Alexander Musman8bd31e62014-05-27 15:12:19 +00008246template <typename Derived>
8247OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008248TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8249 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8250 if (E.isInvalid())
8251 return nullptr;
8252 return getDerived().RebuildOMPSimdlenClause(
8253 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8254}
8255
8256template <typename Derived>
8257OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008258TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8259 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8260 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008261 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008262 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008263 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008264}
8265
Alexander Musman64d33f12014-06-04 07:53:32 +00008266template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008267OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008268TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008269 return getDerived().RebuildOMPDefaultClause(
8270 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8271 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008272}
8273
Alexander Musman64d33f12014-06-04 07:53:32 +00008274template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008275OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008276TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008277 return getDerived().RebuildOMPProcBindClause(
8278 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8279 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008280}
8281
Alexander Musman64d33f12014-06-04 07:53:32 +00008282template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008283OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008284TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8285 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8286 if (E.isInvalid())
8287 return nullptr;
8288 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008289 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008290 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008291 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008292 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8293}
8294
8295template <typename Derived>
8296OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008297TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008298 ExprResult E;
8299 if (auto *Num = C->getNumForLoops()) {
8300 E = getDerived().TransformExpr(Num);
8301 if (E.isInvalid())
8302 return nullptr;
8303 }
8304 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8305 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008306}
8307
8308template <typename Derived>
8309OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008310TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8311 // No need to rebuild this clause, no template-dependent parameters.
8312 return C;
8313}
8314
8315template <typename Derived>
8316OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008317TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8318 // No need to rebuild this clause, no template-dependent parameters.
8319 return C;
8320}
8321
8322template <typename Derived>
8323OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008324TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8325 // No need to rebuild this clause, no template-dependent parameters.
8326 return C;
8327}
8328
8329template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008330OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8331 // No need to rebuild this clause, no template-dependent parameters.
8332 return C;
8333}
8334
8335template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008336OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8337 // No need to rebuild this clause, no template-dependent parameters.
8338 return C;
8339}
8340
8341template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008342OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008343TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8344 // No need to rebuild this clause, no template-dependent parameters.
8345 return C;
8346}
8347
8348template <typename Derived>
8349OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008350TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8351 // No need to rebuild this clause, no template-dependent parameters.
8352 return C;
8353}
8354
8355template <typename Derived>
8356OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008357TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8358 // No need to rebuild this clause, no template-dependent parameters.
8359 return C;
8360}
8361
8362template <typename Derived>
8363OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008364TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8365 // No need to rebuild this clause, no template-dependent parameters.
8366 return C;
8367}
8368
8369template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008370OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8371 // No need to rebuild this clause, no template-dependent parameters.
8372 return C;
8373}
8374
8375template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008376OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008377TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8378 // No need to rebuild this clause, no template-dependent parameters.
8379 return C;
8380}
8381
8382template <typename Derived>
8383OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008384TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008385 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008386 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008387 for (auto *VE : C->varlists()) {
8388 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008389 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008390 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008391 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008392 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008393 return getDerived().RebuildOMPPrivateClause(
8394 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008395}
8396
Alexander Musman64d33f12014-06-04 07:53:32 +00008397template <typename Derived>
8398OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8399 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008400 llvm::SmallVector<Expr *, 16> Vars;
8401 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008402 for (auto *VE : C->varlists()) {
8403 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008404 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008405 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008406 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008407 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008408 return getDerived().RebuildOMPFirstprivateClause(
8409 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008410}
8411
Alexander Musman64d33f12014-06-04 07:53:32 +00008412template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008413OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008414TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8415 llvm::SmallVector<Expr *, 16> Vars;
8416 Vars.reserve(C->varlist_size());
8417 for (auto *VE : C->varlists()) {
8418 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8419 if (EVar.isInvalid())
8420 return nullptr;
8421 Vars.push_back(EVar.get());
8422 }
8423 return getDerived().RebuildOMPLastprivateClause(
8424 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8425}
8426
8427template <typename Derived>
8428OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008429TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8430 llvm::SmallVector<Expr *, 16> Vars;
8431 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008432 for (auto *VE : C->varlists()) {
8433 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008434 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008435 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008436 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008437 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008438 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8439 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008440}
8441
Alexander Musman64d33f12014-06-04 07:53:32 +00008442template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008443OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008444TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8445 llvm::SmallVector<Expr *, 16> Vars;
8446 Vars.reserve(C->varlist_size());
8447 for (auto *VE : C->varlists()) {
8448 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8449 if (EVar.isInvalid())
8450 return nullptr;
8451 Vars.push_back(EVar.get());
8452 }
8453 CXXScopeSpec ReductionIdScopeSpec;
8454 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8455
8456 DeclarationNameInfo NameInfo = C->getNameInfo();
8457 if (NameInfo.getName()) {
8458 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8459 if (!NameInfo.getName())
8460 return nullptr;
8461 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008462 // Build a list of all UDR decls with the same names ranged by the Scopes.
8463 // The Scope boundary is a duplication of the previous decl.
8464 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8465 for (auto *E : C->reduction_ops()) {
8466 // Transform all the decls.
8467 if (E) {
8468 auto *ULE = cast<UnresolvedLookupExpr>(E);
8469 UnresolvedSet<8> Decls;
8470 for (auto *D : ULE->decls()) {
8471 NamedDecl *InstD =
8472 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8473 Decls.addDecl(InstD, InstD->getAccess());
8474 }
8475 UnresolvedReductions.push_back(
8476 UnresolvedLookupExpr::Create(
8477 SemaRef.Context, /*NamingClass=*/nullptr,
8478 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8479 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8480 Decls.begin(), Decls.end()));
8481 } else
8482 UnresolvedReductions.push_back(nullptr);
8483 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008484 return getDerived().RebuildOMPReductionClause(
8485 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008486 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008487}
8488
8489template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008490OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8491 OMPTaskReductionClause *C) {
8492 llvm::SmallVector<Expr *, 16> Vars;
8493 Vars.reserve(C->varlist_size());
8494 for (auto *VE : C->varlists()) {
8495 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8496 if (EVar.isInvalid())
8497 return nullptr;
8498 Vars.push_back(EVar.get());
8499 }
8500 CXXScopeSpec ReductionIdScopeSpec;
8501 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8502
8503 DeclarationNameInfo NameInfo = C->getNameInfo();
8504 if (NameInfo.getName()) {
8505 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8506 if (!NameInfo.getName())
8507 return nullptr;
8508 }
8509 // Build a list of all UDR decls with the same names ranged by the Scopes.
8510 // The Scope boundary is a duplication of the previous decl.
8511 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8512 for (auto *E : C->reduction_ops()) {
8513 // Transform all the decls.
8514 if (E) {
8515 auto *ULE = cast<UnresolvedLookupExpr>(E);
8516 UnresolvedSet<8> Decls;
8517 for (auto *D : ULE->decls()) {
8518 NamedDecl *InstD =
8519 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8520 Decls.addDecl(InstD, InstD->getAccess());
8521 }
8522 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8523 SemaRef.Context, /*NamingClass=*/nullptr,
8524 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8525 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8526 } else
8527 UnresolvedReductions.push_back(nullptr);
8528 }
8529 return getDerived().RebuildOMPTaskReductionClause(
8530 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8531 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8532}
8533
8534template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008535OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008536TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8537 llvm::SmallVector<Expr *, 16> Vars;
8538 Vars.reserve(C->varlist_size());
8539 for (auto *VE : C->varlists()) {
8540 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8541 if (EVar.isInvalid())
8542 return nullptr;
8543 Vars.push_back(EVar.get());
8544 }
8545 CXXScopeSpec ReductionIdScopeSpec;
8546 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8547
8548 DeclarationNameInfo NameInfo = C->getNameInfo();
8549 if (NameInfo.getName()) {
8550 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8551 if (!NameInfo.getName())
8552 return nullptr;
8553 }
8554 // Build a list of all UDR decls with the same names ranged by the Scopes.
8555 // The Scope boundary is a duplication of the previous decl.
8556 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8557 for (auto *E : C->reduction_ops()) {
8558 // Transform all the decls.
8559 if (E) {
8560 auto *ULE = cast<UnresolvedLookupExpr>(E);
8561 UnresolvedSet<8> Decls;
8562 for (auto *D : ULE->decls()) {
8563 NamedDecl *InstD =
8564 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8565 Decls.addDecl(InstD, InstD->getAccess());
8566 }
8567 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8568 SemaRef.Context, /*NamingClass=*/nullptr,
8569 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8570 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8571 } else
8572 UnresolvedReductions.push_back(nullptr);
8573 }
8574 return getDerived().RebuildOMPInReductionClause(
8575 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8576 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8577}
8578
8579template <typename Derived>
8580OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008581TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8582 llvm::SmallVector<Expr *, 16> Vars;
8583 Vars.reserve(C->varlist_size());
8584 for (auto *VE : C->varlists()) {
8585 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8586 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008587 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008588 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008589 }
8590 ExprResult Step = getDerived().TransformExpr(C->getStep());
8591 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008592 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008593 return getDerived().RebuildOMPLinearClause(
8594 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8595 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008596}
8597
Alexander Musman64d33f12014-06-04 07:53:32 +00008598template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008599OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008600TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8601 llvm::SmallVector<Expr *, 16> Vars;
8602 Vars.reserve(C->varlist_size());
8603 for (auto *VE : C->varlists()) {
8604 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8605 if (EVar.isInvalid())
8606 return nullptr;
8607 Vars.push_back(EVar.get());
8608 }
8609 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8610 if (Alignment.isInvalid())
8611 return nullptr;
8612 return getDerived().RebuildOMPAlignedClause(
8613 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8614 C->getColonLoc(), C->getLocEnd());
8615}
8616
Alexander Musman64d33f12014-06-04 07:53:32 +00008617template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008618OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008619TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8620 llvm::SmallVector<Expr *, 16> Vars;
8621 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008622 for (auto *VE : C->varlists()) {
8623 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008624 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008625 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008626 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008627 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008628 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8629 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008630}
8631
Alexey Bataevbae9a792014-06-27 10:37:06 +00008632template <typename Derived>
8633OMPClause *
8634TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8635 llvm::SmallVector<Expr *, 16> Vars;
8636 Vars.reserve(C->varlist_size());
8637 for (auto *VE : C->varlists()) {
8638 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8639 if (EVar.isInvalid())
8640 return nullptr;
8641 Vars.push_back(EVar.get());
8642 }
8643 return getDerived().RebuildOMPCopyprivateClause(
8644 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8645}
8646
Alexey Bataev6125da92014-07-21 11:26:11 +00008647template <typename Derived>
8648OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8649 llvm::SmallVector<Expr *, 16> Vars;
8650 Vars.reserve(C->varlist_size());
8651 for (auto *VE : C->varlists()) {
8652 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8653 if (EVar.isInvalid())
8654 return nullptr;
8655 Vars.push_back(EVar.get());
8656 }
8657 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8658 C->getLParenLoc(), C->getLocEnd());
8659}
8660
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008661template <typename Derived>
8662OMPClause *
8663TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8664 llvm::SmallVector<Expr *, 16> Vars;
8665 Vars.reserve(C->varlist_size());
8666 for (auto *VE : C->varlists()) {
8667 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8668 if (EVar.isInvalid())
8669 return nullptr;
8670 Vars.push_back(EVar.get());
8671 }
8672 return getDerived().RebuildOMPDependClause(
8673 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8674 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8675}
8676
Michael Wonge710d542015-08-07 16:16:36 +00008677template <typename Derived>
8678OMPClause *
8679TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8680 ExprResult E = getDerived().TransformExpr(C->getDevice());
8681 if (E.isInvalid())
8682 return nullptr;
8683 return getDerived().RebuildOMPDeviceClause(
8684 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8685}
8686
Kelvin Li0bff7af2015-11-23 05:32:03 +00008687template <typename Derived>
8688OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8689 llvm::SmallVector<Expr *, 16> Vars;
8690 Vars.reserve(C->varlist_size());
8691 for (auto *VE : C->varlists()) {
8692 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8693 if (EVar.isInvalid())
8694 return nullptr;
8695 Vars.push_back(EVar.get());
8696 }
8697 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008698 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8699 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8700 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008701}
8702
Kelvin Li099bb8c2015-11-24 20:50:12 +00008703template <typename Derived>
8704OMPClause *
8705TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8706 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8707 if (E.isInvalid())
8708 return nullptr;
8709 return getDerived().RebuildOMPNumTeamsClause(
8710 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8711}
8712
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008713template <typename Derived>
8714OMPClause *
8715TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8716 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8717 if (E.isInvalid())
8718 return nullptr;
8719 return getDerived().RebuildOMPThreadLimitClause(
8720 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8721}
8722
Alexey Bataeva0569352015-12-01 10:17:31 +00008723template <typename Derived>
8724OMPClause *
8725TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8726 ExprResult E = getDerived().TransformExpr(C->getPriority());
8727 if (E.isInvalid())
8728 return nullptr;
8729 return getDerived().RebuildOMPPriorityClause(
8730 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8731}
8732
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008733template <typename Derived>
8734OMPClause *
8735TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8736 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8737 if (E.isInvalid())
8738 return nullptr;
8739 return getDerived().RebuildOMPGrainsizeClause(
8740 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8741}
8742
Alexey Bataev382967a2015-12-08 12:06:20 +00008743template <typename Derived>
8744OMPClause *
8745TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8746 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8747 if (E.isInvalid())
8748 return nullptr;
8749 return getDerived().RebuildOMPNumTasksClause(
8750 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8751}
8752
Alexey Bataev28c75412015-12-15 08:19:24 +00008753template <typename Derived>
8754OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8755 ExprResult E = getDerived().TransformExpr(C->getHint());
8756 if (E.isInvalid())
8757 return nullptr;
8758 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8759 C->getLParenLoc(), C->getLocEnd());
8760}
8761
Carlo Bertollib4adf552016-01-15 18:50:31 +00008762template <typename Derived>
8763OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8764 OMPDistScheduleClause *C) {
8765 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8766 if (E.isInvalid())
8767 return nullptr;
8768 return getDerived().RebuildOMPDistScheduleClause(
8769 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8770 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8771}
8772
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008773template <typename Derived>
8774OMPClause *
8775TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8776 return C;
8777}
8778
Samuel Antao661c0902016-05-26 17:39:58 +00008779template <typename Derived>
8780OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8781 llvm::SmallVector<Expr *, 16> Vars;
8782 Vars.reserve(C->varlist_size());
8783 for (auto *VE : C->varlists()) {
8784 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8785 if (EVar.isInvalid())
8786 return 0;
8787 Vars.push_back(EVar.get());
8788 }
8789 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8790 C->getLParenLoc(), C->getLocEnd());
8791}
8792
Samuel Antaoec172c62016-05-26 17:49:04 +00008793template <typename Derived>
8794OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8795 llvm::SmallVector<Expr *, 16> Vars;
8796 Vars.reserve(C->varlist_size());
8797 for (auto *VE : C->varlists()) {
8798 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8799 if (EVar.isInvalid())
8800 return 0;
8801 Vars.push_back(EVar.get());
8802 }
8803 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8804 C->getLParenLoc(), C->getLocEnd());
8805}
8806
Carlo Bertolli2404b172016-07-13 15:37:16 +00008807template <typename Derived>
8808OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8809 OMPUseDevicePtrClause *C) {
8810 llvm::SmallVector<Expr *, 16> Vars;
8811 Vars.reserve(C->varlist_size());
8812 for (auto *VE : C->varlists()) {
8813 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8814 if (EVar.isInvalid())
8815 return nullptr;
8816 Vars.push_back(EVar.get());
8817 }
8818 return getDerived().RebuildOMPUseDevicePtrClause(
8819 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8820}
8821
Carlo Bertolli70594e92016-07-13 17:16:49 +00008822template <typename Derived>
8823OMPClause *
8824TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8825 llvm::SmallVector<Expr *, 16> Vars;
8826 Vars.reserve(C->varlist_size());
8827 for (auto *VE : C->varlists()) {
8828 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8829 if (EVar.isInvalid())
8830 return nullptr;
8831 Vars.push_back(EVar.get());
8832 }
8833 return getDerived().RebuildOMPIsDevicePtrClause(
8834 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8835}
8836
Douglas Gregorebe10102009-08-20 07:17:43 +00008837//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008838// Expression transformation
8839//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008842TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008843 if (!E->isTypeDependent())
8844 return E;
8845
8846 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8847 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008848}
Mike Stump11289f42009-09-09 15:08:12 +00008849
8850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008852TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008853 NestedNameSpecifierLoc QualifierLoc;
8854 if (E->getQualifierLoc()) {
8855 QualifierLoc
8856 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8857 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008858 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008859 }
John McCallce546572009-12-08 09:08:17 +00008860
8861 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008862 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8863 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008864 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008866
John McCall815039a2010-08-17 21:27:17 +00008867 DeclarationNameInfo NameInfo = E->getNameInfo();
8868 if (NameInfo.getName()) {
8869 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8870 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008871 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008872 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008873
8874 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008875 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008876 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008877 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008878 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008879
8880 // Mark it referenced in the new context regardless.
8881 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008882 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008883
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008884 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008885 }
John McCallce546572009-12-08 09:08:17 +00008886
Craig Topperc3ec1492014-05-26 06:22:03 +00008887 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008888 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008889 TemplateArgs = &TransArgs;
8890 TransArgs.setLAngleLoc(E->getLAngleLoc());
8891 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008892 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8893 E->getNumTemplateArgs(),
8894 TransArgs))
8895 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008896 }
8897
Chad Rosier1dcde962012-08-08 18:46:20 +00008898 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008899 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008900}
Mike Stump11289f42009-09-09 15:08:12 +00008901
Douglas Gregora16548e2009-08-11 05:31:07 +00008902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008903ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008904TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008905 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008906}
Mike Stump11289f42009-09-09 15:08:12 +00008907
Douglas Gregora16548e2009-08-11 05:31:07 +00008908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008909ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008910TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008911 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008912}
Mike Stump11289f42009-09-09 15:08:12 +00008913
Douglas Gregora16548e2009-08-11 05:31:07 +00008914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008916TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008917 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008918}
Mike Stump11289f42009-09-09 15:08:12 +00008919
Douglas Gregora16548e2009-08-11 05:31:07 +00008920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008922TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008923 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008924}
Mike Stump11289f42009-09-09 15:08:12 +00008925
Douglas Gregora16548e2009-08-11 05:31:07 +00008926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008927ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008928TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008929 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008930}
8931
8932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008933ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008934TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008935 if (FunctionDecl *FD = E->getDirectCallee())
8936 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008937 return SemaRef.MaybeBindToTemporary(E);
8938}
8939
8940template<typename Derived>
8941ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008942TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8943 ExprResult ControllingExpr =
8944 getDerived().TransformExpr(E->getControllingExpr());
8945 if (ControllingExpr.isInvalid())
8946 return ExprError();
8947
Chris Lattner01cf8db2011-07-20 06:58:45 +00008948 SmallVector<Expr *, 4> AssocExprs;
8949 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008950 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8951 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8952 if (TS) {
8953 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8954 if (!AssocType)
8955 return ExprError();
8956 AssocTypes.push_back(AssocType);
8957 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008958 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008959 }
8960
8961 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8962 if (AssocExpr.isInvalid())
8963 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008964 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008965 }
8966
8967 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8968 E->getDefaultLoc(),
8969 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008970 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008971 AssocTypes,
8972 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008973}
8974
8975template<typename Derived>
8976ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008977TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008978 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008979 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008981
Douglas Gregora16548e2009-08-11 05:31:07 +00008982 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008983 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008984
John McCallb268a282010-08-23 23:25:46 +00008985 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008986 E->getRParen());
8987}
8988
Richard Smithdb2630f2012-10-21 03:28:35 +00008989/// \brief The operand of a unary address-of operator has special rules: it's
8990/// allowed to refer to a non-static member of a class even if there's no 'this'
8991/// object available.
8992template<typename Derived>
8993ExprResult
8994TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8995 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008996 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008997 else
8998 return getDerived().TransformExpr(E);
8999}
9000
Mike Stump11289f42009-09-09 15:08:12 +00009001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009003TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009004 ExprResult SubExpr;
9005 if (E->getOpcode() == UO_AddrOf)
9006 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9007 else
9008 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009009 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009010 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009011
Douglas Gregora16548e2009-08-11 05:31:07 +00009012 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009013 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009014
Douglas Gregora16548e2009-08-11 05:31:07 +00009015 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9016 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009017 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009018}
Mike Stump11289f42009-09-09 15:08:12 +00009019
Douglas Gregora16548e2009-08-11 05:31:07 +00009020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009021ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009022TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9023 // Transform the type.
9024 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9025 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009027
Douglas Gregor882211c2010-04-28 22:16:22 +00009028 // Transform all of the components into components similar to what the
9029 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009030 // FIXME: It would be slightly more efficient in the non-dependent case to
9031 // just map FieldDecls, rather than requiring the rebuilder to look for
9032 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009033 // template code that we don't care.
9034 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009035 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009036 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009037 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009038 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009039 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009040 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009041 Comp.LocStart = ON.getSourceRange().getBegin();
9042 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009043 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009044 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009045 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009046 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009047 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009048 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009049
Douglas Gregor882211c2010-04-28 22:16:22 +00009050 ExprChanged = ExprChanged || Index.get() != FromIndex;
9051 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009052 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009053 break;
9054 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009055
James Y Knight7281c352015-12-29 22:31:18 +00009056 case OffsetOfNode::Field:
9057 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009058 Comp.isBrackets = false;
9059 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009060 if (!Comp.U.IdentInfo)
9061 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009062
Douglas Gregor882211c2010-04-28 22:16:22 +00009063 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009064
James Y Knight7281c352015-12-29 22:31:18 +00009065 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009066 // Will be recomputed during the rebuild.
9067 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009068 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009069
Douglas Gregor882211c2010-04-28 22:16:22 +00009070 Components.push_back(Comp);
9071 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009072
Douglas Gregor882211c2010-04-28 22:16:22 +00009073 // If nothing changed, retain the existing expression.
9074 if (!getDerived().AlwaysRebuild() &&
9075 Type == E->getTypeSourceInfo() &&
9076 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009077 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009078
Douglas Gregor882211c2010-04-28 22:16:22 +00009079 // Build a new offsetof expression.
9080 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009081 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009082}
9083
9084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009085ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009086TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009087 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009088 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009089 return E;
John McCall8d69a212010-11-15 23:31:06 +00009090}
9091
9092template<typename Derived>
9093ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009094TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9095 return E;
9096}
9097
9098template<typename Derived>
9099ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009100TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009101 // Rebuild the syntactic form. The original syntactic form has
9102 // opaque-value expressions in it, so strip those away and rebuild
9103 // the result. This is a really awful way of doing this, but the
9104 // better solution (rebuilding the semantic expressions and
9105 // rebinding OVEs as necessary) doesn't work; we'd need
9106 // TreeTransform to not strip away implicit conversions.
9107 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9108 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009109 if (result.isInvalid()) return ExprError();
9110
9111 // If that gives us a pseudo-object result back, the pseudo-object
9112 // expression must have been an lvalue-to-rvalue conversion which we
9113 // should reapply.
9114 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009115 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009116
9117 return result;
9118}
9119
9120template<typename Derived>
9121ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009122TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9123 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009125 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009126
John McCallbcd03502009-12-07 02:54:59 +00009127 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009128 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009130
John McCall4c98fd82009-11-04 07:28:41 +00009131 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009132 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009133
Peter Collingbournee190dee2011-03-11 19:24:49 +00009134 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9135 E->getKind(),
9136 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009137 }
Mike Stump11289f42009-09-09 15:08:12 +00009138
Eli Friedmane4f22df2012-02-29 04:03:55 +00009139 // C++0x [expr.sizeof]p1:
9140 // The operand is either an expression, which is an unevaluated operand
9141 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009142 EnterExpressionEvaluationContext Unevaluated(
9143 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9144 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009145
Reid Kleckner32506ed2014-06-12 23:03:48 +00009146 // Try to recover if we have something like sizeof(T::X) where X is a type.
9147 // Notably, there must be *exactly* one set of parens if X is a type.
9148 TypeSourceInfo *RecoveryTSI = nullptr;
9149 ExprResult SubExpr;
9150 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9151 if (auto *DRE =
9152 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9153 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9154 PE, DRE, false, &RecoveryTSI);
9155 else
9156 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9157
9158 if (RecoveryTSI) {
9159 return getDerived().RebuildUnaryExprOrTypeTrait(
9160 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9161 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009162 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009163
Eli Friedmane4f22df2012-02-29 04:03:55 +00009164 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009165 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009166
Peter Collingbournee190dee2011-03-11 19:24:49 +00009167 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9168 E->getOperatorLoc(),
9169 E->getKind(),
9170 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009171}
Mike Stump11289f42009-09-09 15:08:12 +00009172
Douglas Gregora16548e2009-08-11 05:31:07 +00009173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009174ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009175TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009176 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009177 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009179
John McCalldadc5752010-08-24 06:29:42 +00009180 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009181 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009182 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009183
9184
Douglas Gregora16548e2009-08-11 05:31:07 +00009185 if (!getDerived().AlwaysRebuild() &&
9186 LHS.get() == E->getLHS() &&
9187 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009188 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009189
John McCallb268a282010-08-23 23:25:46 +00009190 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009191 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009192 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009193 E->getRBracketLoc());
9194}
Mike Stump11289f42009-09-09 15:08:12 +00009195
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009196template <typename Derived>
9197ExprResult
9198TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9199 ExprResult Base = getDerived().TransformExpr(E->getBase());
9200 if (Base.isInvalid())
9201 return ExprError();
9202
9203 ExprResult LowerBound;
9204 if (E->getLowerBound()) {
9205 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9206 if (LowerBound.isInvalid())
9207 return ExprError();
9208 }
9209
9210 ExprResult Length;
9211 if (E->getLength()) {
9212 Length = getDerived().TransformExpr(E->getLength());
9213 if (Length.isInvalid())
9214 return ExprError();
9215 }
9216
9217 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9218 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9219 return E;
9220
9221 return getDerived().RebuildOMPArraySectionExpr(
9222 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9223 Length.get(), E->getRBracketLoc());
9224}
9225
Mike Stump11289f42009-09-09 15:08:12 +00009226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009228TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009229 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009230 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009231 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009232 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009233
9234 // Transform arguments.
9235 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009236 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009237 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009238 &ArgChanged))
9239 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009240
Douglas Gregora16548e2009-08-11 05:31:07 +00009241 if (!getDerived().AlwaysRebuild() &&
9242 Callee.get() == E->getCallee() &&
9243 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009244 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009245
Douglas Gregora16548e2009-08-11 05:31:07 +00009246 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009247 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009248 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009249 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009250 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009251 E->getRParenLoc());
9252}
Mike Stump11289f42009-09-09 15:08:12 +00009253
9254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009256TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009257 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009258 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009260
Douglas Gregorea972d32011-02-28 21:54:11 +00009261 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009262 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009263 QualifierLoc
9264 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009265
Douglas Gregorea972d32011-02-28 21:54:11 +00009266 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009267 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009268 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009269 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009270
Eli Friedman2cfcef62009-12-04 06:40:45 +00009271 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009272 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9273 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009274 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009275 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009276
John McCall16df1e52010-03-30 21:47:33 +00009277 NamedDecl *FoundDecl = E->getFoundDecl();
9278 if (FoundDecl == E->getMemberDecl()) {
9279 FoundDecl = Member;
9280 } else {
9281 FoundDecl = cast_or_null<NamedDecl>(
9282 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9283 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009284 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009285 }
9286
Douglas Gregora16548e2009-08-11 05:31:07 +00009287 if (!getDerived().AlwaysRebuild() &&
9288 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009289 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009290 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009291 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009292 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009293
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009294 // Mark it referenced in the new context regardless.
9295 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009296 SemaRef.MarkMemberReferenced(E);
9297
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009298 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009299 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009300
John McCall6b51f282009-11-23 01:53:49 +00009301 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009302 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009303 TransArgs.setLAngleLoc(E->getLAngleLoc());
9304 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009305 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9306 E->getNumTemplateArgs(),
9307 TransArgs))
9308 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009309 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009310
Douglas Gregora16548e2009-08-11 05:31:07 +00009311 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009312 SourceLocation FakeOperatorLoc =
9313 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009314
John McCall38836f02010-01-15 08:34:02 +00009315 // FIXME: to do this check properly, we will need to preserve the
9316 // first-qualifier-in-scope here, just in case we had a dependent
9317 // base (and therefore couldn't do the check) and a
9318 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009319 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009320 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9321 if (MemberNameInfo.getName()) {
9322 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9323 if (!MemberNameInfo.getName())
9324 return ExprError();
9325 }
John McCall38836f02010-01-15 08:34:02 +00009326
John McCallb268a282010-08-23 23:25:46 +00009327 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009328 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009329 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009330 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009331 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009332 Member,
John McCall16df1e52010-03-30 21:47:33 +00009333 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009334 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009335 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009336 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009337}
Mike Stump11289f42009-09-09 15:08:12 +00009338
Douglas Gregora16548e2009-08-11 05:31:07 +00009339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009341TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009342 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009343 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009345
John McCalldadc5752010-08-24 06:29:42 +00009346 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009347 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009349
Douglas Gregora16548e2009-08-11 05:31:07 +00009350 if (!getDerived().AlwaysRebuild() &&
9351 LHS.get() == E->getLHS() &&
9352 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009353 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009354
Lang Hames5de91cc2012-10-02 04:45:10 +00009355 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009356 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009357
Douglas Gregora16548e2009-08-11 05:31:07 +00009358 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009359 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009360}
9361
Mike Stump11289f42009-09-09 15:08:12 +00009362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009363ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009364TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009365 CompoundAssignOperator *E) {
9366 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009367}
Mike Stump11289f42009-09-09 15:08:12 +00009368
Douglas Gregora16548e2009-08-11 05:31:07 +00009369template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009370ExprResult TreeTransform<Derived>::
9371TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9372 // Just rebuild the common and RHS expressions and see whether we
9373 // get any changes.
9374
9375 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9376 if (commonExpr.isInvalid())
9377 return ExprError();
9378
9379 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9380 if (rhs.isInvalid())
9381 return ExprError();
9382
9383 if (!getDerived().AlwaysRebuild() &&
9384 commonExpr.get() == e->getCommon() &&
9385 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009386 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009387
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009388 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009389 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009390 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009391 e->getColonLoc(),
9392 rhs.get());
9393}
9394
9395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009397TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009398 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009399 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009400 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009401
John McCalldadc5752010-08-24 06:29:42 +00009402 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009403 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009405
John McCalldadc5752010-08-24 06:29:42 +00009406 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009407 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009408 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009409
Douglas Gregora16548e2009-08-11 05:31:07 +00009410 if (!getDerived().AlwaysRebuild() &&
9411 Cond.get() == E->getCond() &&
9412 LHS.get() == E->getLHS() &&
9413 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009414 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009415
John McCallb268a282010-08-23 23:25:46 +00009416 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009417 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009418 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009419 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009420 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009421}
Mike Stump11289f42009-09-09 15:08:12 +00009422
9423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009425TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009426 // Implicit casts are eliminated during transformation, since they
9427 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009428 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009429}
Mike Stump11289f42009-09-09 15:08:12 +00009430
Douglas Gregora16548e2009-08-11 05:31:07 +00009431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009433TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009434 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9435 if (!Type)
9436 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009437
John McCalldadc5752010-08-24 06:29:42 +00009438 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009439 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009440 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009441 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009442
Douglas Gregora16548e2009-08-11 05:31:07 +00009443 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009444 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009445 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009446 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009447
John McCall97513962010-01-15 18:39:57 +00009448 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009449 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009450 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009451 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009452}
Mike Stump11289f42009-09-09 15:08:12 +00009453
Douglas Gregora16548e2009-08-11 05:31:07 +00009454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009455ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009456TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009457 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9458 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9459 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009460 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009461
John McCalldadc5752010-08-24 06:29:42 +00009462 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009463 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009465
Douglas Gregora16548e2009-08-11 05:31:07 +00009466 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009467 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009468 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009469 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009470
John McCall5d7aa7f2010-01-19 22:33:45 +00009471 // Note: the expression type doesn't necessarily match the
9472 // type-as-written, but that's okay, because it should always be
9473 // derivable from the initializer.
9474
John McCalle15bbff2010-01-18 19:35:47 +00009475 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00009476 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00009477 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009478}
Mike Stump11289f42009-09-09 15:08:12 +00009479
Douglas Gregora16548e2009-08-11 05:31:07 +00009480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009481ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009482TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009483 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009484 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009485 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009486
Douglas Gregora16548e2009-08-11 05:31:07 +00009487 if (!getDerived().AlwaysRebuild() &&
9488 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009489 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009490
Douglas Gregora16548e2009-08-11 05:31:07 +00009491 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009492 SourceLocation FakeOperatorLoc =
9493 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00009494 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009495 E->getAccessorLoc(),
9496 E->getAccessor());
9497}
Mike Stump11289f42009-09-09 15:08:12 +00009498
Douglas Gregora16548e2009-08-11 05:31:07 +00009499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009500ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009501TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009502 if (InitListExpr *Syntactic = E->getSyntacticForm())
9503 E = Syntactic;
9504
Douglas Gregora16548e2009-08-11 05:31:07 +00009505 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009506
Benjamin Kramerf0623432012-08-23 22:51:59 +00009507 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009508 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009509 Inits, &InitChanged))
9510 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009511
Richard Smith520449d2015-02-05 06:15:50 +00009512 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9513 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9514 // in some cases. We can't reuse it in general, because the syntactic and
9515 // semantic forms are linked, and we can't know that semantic form will
9516 // match even if the syntactic form does.
9517 }
Mike Stump11289f42009-09-09 15:08:12 +00009518
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009519 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00009520 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00009521}
Mike Stump11289f42009-09-09 15:08:12 +00009522
Douglas Gregora16548e2009-08-11 05:31:07 +00009523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009525TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009526 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009527
Douglas Gregorebe10102009-08-20 07:17:43 +00009528 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009529 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009530 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009532
Douglas Gregorebe10102009-08-20 07:17:43 +00009533 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009534 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009535 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009536 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9537 if (D.isFieldDesignator()) {
9538 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9539 D.getDotLoc(),
9540 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009541 if (D.getField()) {
9542 FieldDecl *Field = cast_or_null<FieldDecl>(
9543 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9544 if (Field != D.getField())
9545 // Rebuild the expression when the transformed FieldDecl is
9546 // different to the already assigned FieldDecl.
9547 ExprChanged = true;
9548 } else {
9549 // Ensure that the designator expression is rebuilt when there isn't
9550 // a resolved FieldDecl in the designator as we don't want to assign
9551 // a FieldDecl to a pattern designator that will be instantiated again.
9552 ExprChanged = true;
9553 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009554 continue;
9555 }
Mike Stump11289f42009-09-09 15:08:12 +00009556
David Majnemerf7e36092016-06-23 00:15:04 +00009557 if (D.isArrayDesignator()) {
9558 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009559 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009561
David Majnemerf7e36092016-06-23 00:15:04 +00009562 Desig.AddDesignator(
9563 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009564
David Majnemerf7e36092016-06-23 00:15:04 +00009565 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009566 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009567 continue;
9568 }
Mike Stump11289f42009-09-09 15:08:12 +00009569
David Majnemerf7e36092016-06-23 00:15:04 +00009570 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009571 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009572 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009573 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009574 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009575
David Majnemerf7e36092016-06-23 00:15:04 +00009576 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009577 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009579
9580 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009581 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009582 D.getLBracketLoc(),
9583 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009584
David Majnemerf7e36092016-06-23 00:15:04 +00009585 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9586 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009587
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009588 ArrayExprs.push_back(Start.get());
9589 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009590 }
Mike Stump11289f42009-09-09 15:08:12 +00009591
Douglas Gregora16548e2009-08-11 05:31:07 +00009592 if (!getDerived().AlwaysRebuild() &&
9593 Init.get() == E->getInit() &&
9594 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009595 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009596
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009597 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009598 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009599 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009600}
Mike Stump11289f42009-09-09 15:08:12 +00009601
Yunzhong Gaocb779302015-06-10 00:27:52 +00009602// Seems that if TransformInitListExpr() only works on the syntactic form of an
9603// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9604template<typename Derived>
9605ExprResult
9606TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9607 DesignatedInitUpdateExpr *E) {
9608 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9609 "initializer");
9610 return ExprError();
9611}
9612
9613template<typename Derived>
9614ExprResult
9615TreeTransform<Derived>::TransformNoInitExpr(
9616 NoInitExpr *E) {
9617 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9618 return ExprError();
9619}
9620
Douglas Gregora16548e2009-08-11 05:31:07 +00009621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009622ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009623TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9624 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9625 return ExprError();
9626}
9627
9628template<typename Derived>
9629ExprResult
9630TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9631 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9632 return ExprError();
9633}
9634
9635template<typename Derived>
9636ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009637TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009638 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009639 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009640
Douglas Gregor3da3c062009-10-28 00:29:27 +00009641 // FIXME: Will we ever have proper type location here? Will we actually
9642 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009643 QualType T = getDerived().TransformType(E->getType());
9644 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009646
Douglas Gregora16548e2009-08-11 05:31:07 +00009647 if (!getDerived().AlwaysRebuild() &&
9648 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009649 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009650
Douglas Gregora16548e2009-08-11 05:31:07 +00009651 return getDerived().RebuildImplicitValueInitExpr(T);
9652}
Mike Stump11289f42009-09-09 15:08:12 +00009653
Douglas Gregora16548e2009-08-11 05:31:07 +00009654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009655ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009656TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009657 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9658 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009659 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009660
John McCalldadc5752010-08-24 06:29:42 +00009661 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009662 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009663 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009664
Douglas Gregora16548e2009-08-11 05:31:07 +00009665 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009666 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009667 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009668 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009669
John McCallb268a282010-08-23 23:25:46 +00009670 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009671 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009672}
9673
9674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009676TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009677 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009678 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009679 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9680 &ArgumentChanged))
9681 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009682
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009684 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009685 E->getRParenLoc());
9686}
Mike Stump11289f42009-09-09 15:08:12 +00009687
Douglas Gregora16548e2009-08-11 05:31:07 +00009688/// \brief Transform an address-of-label expression.
9689///
9690/// By default, the transformation of an address-of-label expression always
9691/// rebuilds the expression, so that the label identifier can be resolved to
9692/// the corresponding label statement by semantic analysis.
9693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009694ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009695TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009696 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9697 E->getLabel());
9698 if (!LD)
9699 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009700
Douglas Gregora16548e2009-08-11 05:31:07 +00009701 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009702 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009703}
Mike Stump11289f42009-09-09 15:08:12 +00009704
9705template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009706ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009707TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009708 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009709 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009710 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009711 if (SubStmt.isInvalid()) {
9712 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009713 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009714 }
Mike Stump11289f42009-09-09 15:08:12 +00009715
Douglas Gregora16548e2009-08-11 05:31:07 +00009716 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009717 SubStmt.get() == E->getSubStmt()) {
9718 // Calling this an 'error' is unintuitive, but it does the right thing.
9719 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009720 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009721 }
Mike Stump11289f42009-09-09 15:08:12 +00009722
9723 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009724 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009725 E->getRParenLoc());
9726}
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregora16548e2009-08-11 05:31:07 +00009728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009730TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009731 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009732 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009734
John McCalldadc5752010-08-24 06:29:42 +00009735 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009736 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009738
John McCalldadc5752010-08-24 06:29:42 +00009739 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009740 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009742
Douglas Gregora16548e2009-08-11 05:31:07 +00009743 if (!getDerived().AlwaysRebuild() &&
9744 Cond.get() == E->getCond() &&
9745 LHS.get() == E->getLHS() &&
9746 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009747 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009748
Douglas Gregora16548e2009-08-11 05:31:07 +00009749 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009750 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009751 E->getRParenLoc());
9752}
Mike Stump11289f42009-09-09 15:08:12 +00009753
Douglas Gregora16548e2009-08-11 05:31:07 +00009754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009755ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009756TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009757 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009758}
9759
9760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009761ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009762TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009763 switch (E->getOperator()) {
9764 case OO_New:
9765 case OO_Delete:
9766 case OO_Array_New:
9767 case OO_Array_Delete:
9768 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009769
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009770 case OO_Call: {
9771 // This is a call to an object's operator().
9772 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9773
9774 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009775 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009776 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009777 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009778
9779 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009780 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9781 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009782
9783 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009784 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009785 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009786 Args))
9787 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009788
John McCallb268a282010-08-23 23:25:46 +00009789 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009790 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009791 E->getLocEnd());
9792 }
9793
9794#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9795 case OO_##Name:
9796#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9797#include "clang/Basic/OperatorKinds.def"
9798 case OO_Subscript:
9799 // Handled below.
9800 break;
9801
9802 case OO_Conditional:
9803 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009804
9805 case OO_None:
9806 case NUM_OVERLOADED_OPERATORS:
9807 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009808 }
9809
John McCalldadc5752010-08-24 06:29:42 +00009810 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009811 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009813
Richard Smithdb2630f2012-10-21 03:28:35 +00009814 ExprResult First;
9815 if (E->getOperator() == OO_Amp)
9816 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9817 else
9818 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009819 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009820 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009821
John McCalldadc5752010-08-24 06:29:42 +00009822 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009823 if (E->getNumArgs() == 2) {
9824 Second = getDerived().TransformExpr(E->getArg(1));
9825 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009826 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009827 }
Mike Stump11289f42009-09-09 15:08:12 +00009828
Douglas Gregora16548e2009-08-11 05:31:07 +00009829 if (!getDerived().AlwaysRebuild() &&
9830 Callee.get() == E->getCallee() &&
9831 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009832 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009833 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009834
Lang Hames5de91cc2012-10-02 04:45:10 +00009835 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009836 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009837
Douglas Gregora16548e2009-08-11 05:31:07 +00009838 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9839 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009840 Callee.get(),
9841 First.get(),
9842 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009843}
Mike Stump11289f42009-09-09 15:08:12 +00009844
Douglas Gregora16548e2009-08-11 05:31:07 +00009845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009847TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9848 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009849}
Mike Stump11289f42009-09-09 15:08:12 +00009850
Douglas Gregora16548e2009-08-11 05:31:07 +00009851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009852ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009853TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9854 // Transform the callee.
9855 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9856 if (Callee.isInvalid())
9857 return ExprError();
9858
9859 // Transform exec config.
9860 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9861 if (EC.isInvalid())
9862 return ExprError();
9863
9864 // Transform arguments.
9865 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009866 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009867 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009868 &ArgChanged))
9869 return ExprError();
9870
9871 if (!getDerived().AlwaysRebuild() &&
9872 Callee.get() == E->getCallee() &&
9873 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009874 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009875
9876 // FIXME: Wrong source location information for the '('.
9877 SourceLocation FakeLParenLoc
9878 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9879 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009880 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009881 E->getRParenLoc(), EC.get());
9882}
9883
9884template<typename Derived>
9885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009886TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009887 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9888 if (!Type)
9889 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009890
John McCalldadc5752010-08-24 06:29:42 +00009891 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009892 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009893 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009895
Douglas Gregora16548e2009-08-11 05:31:07 +00009896 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009897 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009898 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009899 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009900 return getDerived().RebuildCXXNamedCastExpr(
9901 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9902 Type, E->getAngleBrackets().getEnd(),
9903 // FIXME. this should be '(' location
9904 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009905}
Mike Stump11289f42009-09-09 15:08:12 +00009906
Douglas Gregora16548e2009-08-11 05:31:07 +00009907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009909TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9910 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009911}
Mike Stump11289f42009-09-09 15:08:12 +00009912
9913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009915TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9916 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009917}
9918
Douglas Gregora16548e2009-08-11 05:31:07 +00009919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009920ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009921TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009922 CXXReinterpretCastExpr *E) {
9923 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009924}
Mike Stump11289f42009-09-09 15:08:12 +00009925
Douglas Gregora16548e2009-08-11 05:31:07 +00009926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009927ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009928TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9929 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009930}
Mike Stump11289f42009-09-09 15:08:12 +00009931
Douglas Gregora16548e2009-08-11 05:31:07 +00009932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009933ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009934TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009935 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009936 TypeSourceInfo *Type =
9937 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009938 if (!Type)
9939 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009940
John McCalldadc5752010-08-24 06:29:42 +00009941 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009942 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009943 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009944 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009945
Douglas Gregora16548e2009-08-11 05:31:07 +00009946 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009947 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009948 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009949 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009950
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009951 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009952 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009953 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009954 E->getRParenLoc());
9955}
Mike Stump11289f42009-09-09 15:08:12 +00009956
Douglas Gregora16548e2009-08-11 05:31:07 +00009957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009959TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009960 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009961 TypeSourceInfo *TInfo
9962 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9963 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009965
Douglas Gregora16548e2009-08-11 05:31:07 +00009966 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009967 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009968 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009969
Douglas Gregor9da64192010-04-26 22:37:10 +00009970 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9971 E->getLocStart(),
9972 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009973 E->getLocEnd());
9974 }
Mike Stump11289f42009-09-09 15:08:12 +00009975
Eli Friedman456f0182012-01-20 01:26:23 +00009976 // We don't know whether the subexpression is potentially evaluated until
9977 // after we perform semantic analysis. We speculatively assume it is
9978 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009979 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +00009980 EnterExpressionEvaluationContext Unevaluated(
9981 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9982 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009983
John McCalldadc5752010-08-24 06:29:42 +00009984 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009985 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009987
Douglas Gregora16548e2009-08-11 05:31:07 +00009988 if (!getDerived().AlwaysRebuild() &&
9989 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009990 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009991
Douglas Gregor9da64192010-04-26 22:37:10 +00009992 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9993 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009994 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009995 E->getLocEnd());
9996}
9997
9998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009999ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010000TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10001 if (E->isTypeOperand()) {
10002 TypeSourceInfo *TInfo
10003 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10004 if (!TInfo)
10005 return ExprError();
10006
10007 if (!getDerived().AlwaysRebuild() &&
10008 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010009 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010010
Douglas Gregor69735112011-03-06 17:40:41 +000010011 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +000010012 E->getLocStart(),
10013 TInfo,
10014 E->getLocEnd());
10015 }
10016
Faisal Valid143a0c2017-04-01 21:30:49 +000010017 EnterExpressionEvaluationContext Unevaluated(
10018 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010019
10020 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10021 if (SubExpr.isInvalid())
10022 return ExprError();
10023
10024 if (!getDerived().AlwaysRebuild() &&
10025 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010026 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010027
10028 return getDerived().RebuildCXXUuidofExpr(E->getType(),
10029 E->getLocStart(),
10030 SubExpr.get(),
10031 E->getLocEnd());
10032}
10033
10034template<typename Derived>
10035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010036TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010037 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010038}
Mike Stump11289f42009-09-09 15:08:12 +000010039
Douglas Gregora16548e2009-08-11 05:31:07 +000010040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010041ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010042TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010043 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010044 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010045}
Mike Stump11289f42009-09-09 15:08:12 +000010046
Douglas Gregora16548e2009-08-11 05:31:07 +000010047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010048ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010049TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010050 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010051
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010052 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10053 // Make sure that we capture 'this'.
10054 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010055 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010056 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010057
Douglas Gregorb15af892010-01-07 23:12:05 +000010058 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010059}
Mike Stump11289f42009-09-09 15:08:12 +000010060
Douglas Gregora16548e2009-08-11 05:31:07 +000010061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010063TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010064 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010065 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010067
Douglas Gregora16548e2009-08-11 05:31:07 +000010068 if (!getDerived().AlwaysRebuild() &&
10069 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010070 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010071
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010072 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10073 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010074}
Mike Stump11289f42009-09-09 15:08:12 +000010075
Douglas Gregora16548e2009-08-11 05:31:07 +000010076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010078TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +000010079 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010080 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
10081 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010082 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010084
Chandler Carruth794da4c2010-02-08 06:42:49 +000010085 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010086 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010087 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010088
Douglas Gregor033f6752009-12-23 23:03:06 +000010089 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010090}
Mike Stump11289f42009-09-09 15:08:12 +000010091
Douglas Gregora16548e2009-08-11 05:31:07 +000010092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010093ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010094TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
10095 FieldDecl *Field
10096 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
10097 E->getField()));
10098 if (!Field)
10099 return ExprError();
10100
10101 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010102 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010103
10104 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10105}
10106
10107template<typename Derived>
10108ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010109TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10110 CXXScalarValueInitExpr *E) {
10111 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10112 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010113 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010114
Douglas Gregora16548e2009-08-11 05:31:07 +000010115 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010116 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010117 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010118
Chad Rosier1dcde962012-08-08 18:46:20 +000010119 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010120 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010121 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010122}
Mike Stump11289f42009-09-09 15:08:12 +000010123
Douglas Gregora16548e2009-08-11 05:31:07 +000010124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010126TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010127 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010128 TypeSourceInfo *AllocTypeInfo =
10129 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010130 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010132
Douglas Gregora16548e2009-08-11 05:31:07 +000010133 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010134 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010135 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010137
Douglas Gregora16548e2009-08-11 05:31:07 +000010138 // Transform the placement arguments (if any).
10139 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010140 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010141 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010142 E->getNumPlacementArgs(), true,
10143 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010144 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010145
Sebastian Redl6047f072012-02-16 12:22:20 +000010146 // Transform the initializer (if any).
10147 Expr *OldInit = E->getInitializer();
10148 ExprResult NewInit;
10149 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010150 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010151 if (NewInit.isInvalid())
10152 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010153
Sebastian Redl6047f072012-02-16 12:22:20 +000010154 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010155 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010156 if (E->getOperatorNew()) {
10157 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010158 getDerived().TransformDecl(E->getLocStart(),
10159 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010160 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010161 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010162 }
10163
Craig Topperc3ec1492014-05-26 06:22:03 +000010164 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010165 if (E->getOperatorDelete()) {
10166 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010167 getDerived().TransformDecl(E->getLocStart(),
10168 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010169 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010170 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010171 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010172
Douglas Gregora16548e2009-08-11 05:31:07 +000010173 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010174 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010175 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010176 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010177 OperatorNew == E->getOperatorNew() &&
10178 OperatorDelete == E->getOperatorDelete() &&
10179 !ArgumentChanged) {
10180 // Mark any declarations we need as referenced.
10181 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010182 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010183 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010184 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010185 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010186
Sebastian Redl6047f072012-02-16 12:22:20 +000010187 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010188 QualType ElementType
10189 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10190 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10191 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10192 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +000010193 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010194 }
10195 }
10196 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010197
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010198 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010199 }
Mike Stump11289f42009-09-09 15:08:12 +000010200
Douglas Gregor0744ef62010-09-07 21:49:58 +000010201 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010202 if (!ArraySize.get()) {
10203 // If no array size was specified, but the new expression was
10204 // instantiated with an array type (e.g., "new T" where T is
10205 // instantiated with "int[4]"), extract the outer bound from the
10206 // array type as our array size. We do this with constant and
10207 // dependently-sized array types.
10208 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10209 if (!ArrayT) {
10210 // Do nothing
10211 } else if (const ConstantArrayType *ConsArrayT
10212 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010213 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10214 SemaRef.Context.getSizeType(),
10215 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010216 AllocType = ConsArrayT->getElementType();
10217 } else if (const DependentSizedArrayType *DepArrayT
10218 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10219 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010220 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010221 AllocType = DepArrayT->getElementType();
10222 }
10223 }
10224 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010225
Douglas Gregora16548e2009-08-11 05:31:07 +000010226 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10227 E->isGlobalNew(),
10228 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010229 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010230 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +000010231 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010232 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +000010233 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +000010234 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +000010235 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010236 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010237}
Mike Stump11289f42009-09-09 15:08:12 +000010238
Douglas Gregora16548e2009-08-11 05:31:07 +000010239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010241TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010242 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010243 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010245
Douglas Gregord2d9da02010-02-26 00:38:10 +000010246 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010247 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010248 if (E->getOperatorDelete()) {
10249 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010250 getDerived().TransformDecl(E->getLocStart(),
10251 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010252 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010253 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010254 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010255
Douglas Gregora16548e2009-08-11 05:31:07 +000010256 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010257 Operand.get() == E->getArgument() &&
10258 OperatorDelete == E->getOperatorDelete()) {
10259 // Mark any declarations we need as referenced.
10260 // FIXME: instantiation-specific.
10261 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010262 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010263
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010264 if (!E->getArgument()->isTypeDependent()) {
10265 QualType Destroyed = SemaRef.Context.getBaseElementType(
10266 E->getDestroyedType());
10267 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10268 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010269 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010270 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010271 }
10272 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010273
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010274 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010275 }
Mike Stump11289f42009-09-09 15:08:12 +000010276
Douglas Gregora16548e2009-08-11 05:31:07 +000010277 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10278 E->isGlobalDelete(),
10279 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +000010280 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010281}
Mike Stump11289f42009-09-09 15:08:12 +000010282
Douglas Gregora16548e2009-08-11 05:31:07 +000010283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010284ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010285TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010286 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010287 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010288 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010289 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010290
John McCallba7bf592010-08-24 05:47:05 +000010291 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010292 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010293 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010294 E->getOperatorLoc(),
10295 E->isArrow()? tok::arrow : tok::period,
10296 ObjectTypePtr,
10297 MayBePseudoDestructor);
10298 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010299 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010300
John McCallba7bf592010-08-24 05:47:05 +000010301 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010302 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10303 if (QualifierLoc) {
10304 QualifierLoc
10305 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10306 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010307 return ExprError();
10308 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010309 CXXScopeSpec SS;
10310 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010311
Douglas Gregor678f90d2010-02-25 01:56:36 +000010312 PseudoDestructorTypeStorage Destroyed;
10313 if (E->getDestroyedTypeInfo()) {
10314 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010315 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010316 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010317 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010318 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010319 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010320 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010321 // We aren't likely to be able to resolve the identifier down to a type
10322 // now anyway, so just retain the identifier.
10323 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10324 E->getDestroyedTypeLoc());
10325 } else {
10326 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010327 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010328 *E->getDestroyedTypeIdentifier(),
10329 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010330 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010331 SS, ObjectTypePtr,
10332 false);
10333 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010334 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010335
Douglas Gregor678f90d2010-02-25 01:56:36 +000010336 Destroyed
10337 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10338 E->getDestroyedTypeLoc());
10339 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010340
Craig Topperc3ec1492014-05-26 06:22:03 +000010341 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010342 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010343 CXXScopeSpec EmptySS;
10344 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010345 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010346 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010347 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010348 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010349
John McCallb268a282010-08-23 23:25:46 +000010350 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010351 E->getOperatorLoc(),
10352 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010353 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010354 ScopeTypeInfo,
10355 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010356 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010357 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010358}
Mike Stump11289f42009-09-09 15:08:12 +000010359
Richard Smith151c4562016-12-20 21:35:28 +000010360template <typename Derived>
10361bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10362 bool RequiresADL,
10363 LookupResult &R) {
10364 // Transform all the decls.
10365 bool AllEmptyPacks = true;
10366 for (auto *OldD : Old->decls()) {
10367 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10368 if (!InstD) {
10369 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10370 // This can happen because of dependent hiding.
10371 if (isa<UsingShadowDecl>(OldD))
10372 continue;
10373 else {
10374 R.clear();
10375 return true;
10376 }
10377 }
10378
10379 // Expand using pack declarations.
10380 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10381 ArrayRef<NamedDecl*> Decls = SingleDecl;
10382 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10383 Decls = UPD->expansions();
10384
10385 // Expand using declarations.
10386 for (auto *D : Decls) {
10387 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10388 for (auto *SD : UD->shadows())
10389 R.addDecl(SD);
10390 } else {
10391 R.addDecl(D);
10392 }
10393 }
10394
10395 AllEmptyPacks &= Decls.empty();
10396 };
10397
10398 // C++ [temp.res]/8.4.2:
10399 // The program is ill-formed, no diagnostic required, if [...] lookup for
10400 // a name in the template definition found a using-declaration, but the
10401 // lookup in the corresponding scope in the instantiation odoes not find
10402 // any declarations because the using-declaration was a pack expansion and
10403 // the corresponding pack is empty
10404 if (AllEmptyPacks && !RequiresADL) {
10405 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10406 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10407 return true;
10408 }
10409
10410 // Resolve a kind, but don't do any further analysis. If it's
10411 // ambiguous, the callee needs to deal with it.
10412 R.resolveKind();
10413 return false;
10414}
10415
Douglas Gregorad8a3362009-09-04 17:36:40 +000010416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010417ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010418TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010419 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010420 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10421 Sema::LookupOrdinaryName);
10422
Richard Smith151c4562016-12-20 21:35:28 +000010423 // Transform the declaration set.
10424 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10425 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010426
10427 // Rebuild the nested-name qualifier, if present.
10428 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010429 if (Old->getQualifierLoc()) {
10430 NestedNameSpecifierLoc QualifierLoc
10431 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10432 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010433 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010434
Douglas Gregor0da1d432011-02-28 20:01:57 +000010435 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010436 }
10437
Douglas Gregor9262f472010-04-27 18:19:34 +000010438 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010439 CXXRecordDecl *NamingClass
10440 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10441 Old->getNameLoc(),
10442 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010443 if (!NamingClass) {
10444 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010445 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010446 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010447
Douglas Gregorda7be082010-04-27 16:10:10 +000010448 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010449 }
10450
Abramo Bagnara7945c982012-01-27 09:46:47 +000010451 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10452
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010453 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010454 // it's a normal declaration name or member reference.
10455 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10456 NamedDecl *D = R.getAsSingle<NamedDecl>();
10457 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10458 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10459 // give a good diagnostic.
10460 if (D && D->isCXXInstanceMember()) {
10461 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10462 /*TemplateArgs=*/nullptr,
10463 /*Scope=*/nullptr);
10464 }
10465
John McCalle66edc12009-11-24 19:00:30 +000010466 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010467 }
John McCalle66edc12009-11-24 19:00:30 +000010468
10469 // If we have template arguments, rebuild them, then rebuild the
10470 // templateid expression.
10471 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010472 if (Old->hasExplicitTemplateArgs() &&
10473 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010474 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010475 TransArgs)) {
10476 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010477 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010478 }
John McCalle66edc12009-11-24 19:00:30 +000010479
Abramo Bagnara7945c982012-01-27 09:46:47 +000010480 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010481 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010482}
Mike Stump11289f42009-09-09 15:08:12 +000010483
Douglas Gregora16548e2009-08-11 05:31:07 +000010484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010485ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010486TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10487 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010488 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010489 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10490 TypeSourceInfo *From = E->getArg(I);
10491 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010492 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010493 TypeLocBuilder TLB;
10494 TLB.reserve(FromTL.getFullDataSize());
10495 QualType To = getDerived().TransformType(TLB, FromTL);
10496 if (To.isNull())
10497 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010498
Douglas Gregor29c42f22012-02-24 07:38:34 +000010499 if (To == From->getType())
10500 Args.push_back(From);
10501 else {
10502 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10503 ArgChanged = true;
10504 }
10505 continue;
10506 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010507
Douglas Gregor29c42f22012-02-24 07:38:34 +000010508 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010509
Douglas Gregor29c42f22012-02-24 07:38:34 +000010510 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010511 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010512 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10513 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10514 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010515
Douglas Gregor29c42f22012-02-24 07:38:34 +000010516 // Determine whether the set of unexpanded parameter packs can and should
10517 // be expanded.
10518 bool Expand = true;
10519 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010520 Optional<unsigned> OrigNumExpansions =
10521 ExpansionTL.getTypePtr()->getNumExpansions();
10522 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010523 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10524 PatternTL.getSourceRange(),
10525 Unexpanded,
10526 Expand, RetainExpansion,
10527 NumExpansions))
10528 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010529
Douglas Gregor29c42f22012-02-24 07:38:34 +000010530 if (!Expand) {
10531 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010532 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010533 // expansion.
10534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010535
Douglas Gregor29c42f22012-02-24 07:38:34 +000010536 TypeLocBuilder TLB;
10537 TLB.reserve(From->getTypeLoc().getFullDataSize());
10538
10539 QualType To = getDerived().TransformType(TLB, PatternTL);
10540 if (To.isNull())
10541 return ExprError();
10542
Chad Rosier1dcde962012-08-08 18:46:20 +000010543 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010544 PatternTL.getSourceRange(),
10545 ExpansionTL.getEllipsisLoc(),
10546 NumExpansions);
10547 if (To.isNull())
10548 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010549
Douglas Gregor29c42f22012-02-24 07:38:34 +000010550 PackExpansionTypeLoc ToExpansionTL
10551 = TLB.push<PackExpansionTypeLoc>(To);
10552 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10553 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10554 continue;
10555 }
10556
10557 // Expand the pack expansion by substituting for each argument in the
10558 // pack(s).
10559 for (unsigned I = 0; I != *NumExpansions; ++I) {
10560 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10561 TypeLocBuilder TLB;
10562 TLB.reserve(PatternTL.getFullDataSize());
10563 QualType To = getDerived().TransformType(TLB, PatternTL);
10564 if (To.isNull())
10565 return ExprError();
10566
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010567 if (To->containsUnexpandedParameterPack()) {
10568 To = getDerived().RebuildPackExpansionType(To,
10569 PatternTL.getSourceRange(),
10570 ExpansionTL.getEllipsisLoc(),
10571 NumExpansions);
10572 if (To.isNull())
10573 return ExprError();
10574
10575 PackExpansionTypeLoc ToExpansionTL
10576 = TLB.push<PackExpansionTypeLoc>(To);
10577 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10578 }
10579
Douglas Gregor29c42f22012-02-24 07:38:34 +000010580 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10581 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010582
Douglas Gregor29c42f22012-02-24 07:38:34 +000010583 if (!RetainExpansion)
10584 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010585
Douglas Gregor29c42f22012-02-24 07:38:34 +000010586 // If we're supposed to retain a pack expansion, do so by temporarily
10587 // forgetting the partially-substituted parameter pack.
10588 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10589
10590 TypeLocBuilder TLB;
10591 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010592
Douglas Gregor29c42f22012-02-24 07:38:34 +000010593 QualType To = getDerived().TransformType(TLB, PatternTL);
10594 if (To.isNull())
10595 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010596
10597 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010598 PatternTL.getSourceRange(),
10599 ExpansionTL.getEllipsisLoc(),
10600 NumExpansions);
10601 if (To.isNull())
10602 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010603
Douglas Gregor29c42f22012-02-24 07:38:34 +000010604 PackExpansionTypeLoc ToExpansionTL
10605 = TLB.push<PackExpansionTypeLoc>(To);
10606 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10607 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10608 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010609
Douglas Gregor29c42f22012-02-24 07:38:34 +000010610 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010611 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010612
10613 return getDerived().RebuildTypeTrait(E->getTrait(),
10614 E->getLocStart(),
10615 Args,
10616 E->getLocEnd());
10617}
10618
10619template<typename Derived>
10620ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010621TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10622 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10623 if (!T)
10624 return ExprError();
10625
10626 if (!getDerived().AlwaysRebuild() &&
10627 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010628 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010629
10630 ExprResult SubExpr;
10631 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010632 EnterExpressionEvaluationContext Unevaluated(
10633 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010634 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10635 if (SubExpr.isInvalid())
10636 return ExprError();
10637
10638 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010639 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010640 }
10641
10642 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10643 E->getLocStart(),
10644 T,
10645 SubExpr.get(),
10646 E->getLocEnd());
10647}
10648
10649template<typename Derived>
10650ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010651TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10652 ExprResult SubExpr;
10653 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010654 EnterExpressionEvaluationContext Unevaluated(
10655 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010656 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10657 if (SubExpr.isInvalid())
10658 return ExprError();
10659
10660 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010661 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010662 }
10663
10664 return getDerived().RebuildExpressionTrait(
10665 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10666}
10667
Reid Kleckner32506ed2014-06-12 23:03:48 +000010668template <typename Derived>
10669ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10670 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10671 TypeSourceInfo **RecoveryTSI) {
10672 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10673 DRE, AddrTaken, RecoveryTSI);
10674
10675 // Propagate both errors and recovered types, which return ExprEmpty.
10676 if (!NewDRE.isUsable())
10677 return NewDRE;
10678
10679 // We got an expr, wrap it up in parens.
10680 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10681 return PE;
10682 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10683 PE->getRParen());
10684}
10685
10686template <typename Derived>
10687ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10688 DependentScopeDeclRefExpr *E) {
10689 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10690 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010691}
10692
10693template<typename Derived>
10694ExprResult
10695TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10696 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010697 bool IsAddressOfOperand,
10698 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010699 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010700 NestedNameSpecifierLoc QualifierLoc
10701 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10702 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010703 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010704 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010705
John McCall31f82722010-11-12 08:19:04 +000010706 // TODO: If this is a conversion-function-id, verify that the
10707 // destination type name (if present) resolves the same way after
10708 // instantiation as it did in the local scope.
10709
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010710 DeclarationNameInfo NameInfo
10711 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10712 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010714
John McCalle66edc12009-11-24 19:00:30 +000010715 if (!E->hasExplicitTemplateArgs()) {
10716 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010717 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010718 // Note: it is sufficient to compare the Name component of NameInfo:
10719 // if name has not changed, DNLoc has not changed either.
10720 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010721 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010722
Reid Kleckner32506ed2014-06-12 23:03:48 +000010723 return getDerived().RebuildDependentScopeDeclRefExpr(
10724 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10725 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010726 }
John McCall6b51f282009-11-23 01:53:49 +000010727
10728 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010729 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10730 E->getNumTemplateArgs(),
10731 TransArgs))
10732 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010733
Reid Kleckner32506ed2014-06-12 23:03:48 +000010734 return getDerived().RebuildDependentScopeDeclRefExpr(
10735 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10736 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010737}
10738
10739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010741TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010742 // CXXConstructExprs other than for list-initialization and
10743 // CXXTemporaryObjectExpr are always implicit, so when we have
10744 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010745 if ((E->getNumArgs() == 1 ||
10746 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010747 (!getDerived().DropCallArgument(E->getArg(0))) &&
10748 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010749 return getDerived().TransformExpr(E->getArg(0));
10750
Douglas Gregora16548e2009-08-11 05:31:07 +000010751 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10752
10753 QualType T = getDerived().TransformType(E->getType());
10754 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010755 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010756
10757 CXXConstructorDecl *Constructor
10758 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010759 getDerived().TransformDecl(E->getLocStart(),
10760 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010761 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010762 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010763
Douglas Gregora16548e2009-08-11 05:31:07 +000010764 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010765 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010766 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010767 &ArgumentChanged))
10768 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010769
Douglas Gregora16548e2009-08-11 05:31:07 +000010770 if (!getDerived().AlwaysRebuild() &&
10771 T == E->getType() &&
10772 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010773 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010774 // Mark the constructor as referenced.
10775 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010776 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010777 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010778 }
Mike Stump11289f42009-09-09 15:08:12 +000010779
Douglas Gregordb121ba2009-12-14 16:27:04 +000010780 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010781 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010782 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010783 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010784 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010785 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010786 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010787 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010788 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010789}
Mike Stump11289f42009-09-09 15:08:12 +000010790
Richard Smith5179eb72016-06-28 19:03:57 +000010791template<typename Derived>
10792ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10793 CXXInheritedCtorInitExpr *E) {
10794 QualType T = getDerived().TransformType(E->getType());
10795 if (T.isNull())
10796 return ExprError();
10797
10798 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10799 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10800 if (!Constructor)
10801 return ExprError();
10802
10803 if (!getDerived().AlwaysRebuild() &&
10804 T == E->getType() &&
10805 Constructor == E->getConstructor()) {
10806 // Mark the constructor as referenced.
10807 // FIXME: Instantiation-specific
10808 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10809 return E;
10810 }
10811
10812 return getDerived().RebuildCXXInheritedCtorInitExpr(
10813 T, E->getLocation(), Constructor,
10814 E->constructsVBase(), E->inheritedFromVBase());
10815}
10816
Douglas Gregora16548e2009-08-11 05:31:07 +000010817/// \brief Transform a C++ temporary-binding expression.
10818///
Douglas Gregor363b1512009-12-24 18:51:59 +000010819/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10820/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010823TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010824 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010825}
Mike Stump11289f42009-09-09 15:08:12 +000010826
John McCall5d413782010-12-06 08:20:24 +000010827/// \brief Transform a C++ expression that contains cleanups that should
10828/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010829///
John McCall5d413782010-12-06 08:20:24 +000010830/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010831/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010833ExprResult
John McCall5d413782010-12-06 08:20:24 +000010834TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010835 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010836}
Mike Stump11289f42009-09-09 15:08:12 +000010837
Douglas Gregora16548e2009-08-11 05:31:07 +000010838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010839ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010840TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010841 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010842 TypeSourceInfo *T =
10843 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010844 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010846
Douglas Gregora16548e2009-08-11 05:31:07 +000010847 CXXConstructorDecl *Constructor
10848 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010849 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010850 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010851 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010853
Douglas Gregora16548e2009-08-11 05:31:07 +000010854 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010855 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010856 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010857 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010858 &ArgumentChanged))
10859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010860
Douglas Gregora16548e2009-08-11 05:31:07 +000010861 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010862 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010863 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010864 !ArgumentChanged) {
10865 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010866 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010867 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010868 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010869
Richard Smithd59b8322012-12-19 01:39:02 +000010870 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010871 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10872 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010873 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010874 E->getLocEnd());
10875}
Mike Stump11289f42009-09-09 15:08:12 +000010876
Douglas Gregora16548e2009-08-11 05:31:07 +000010877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010878ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010879TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010880 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010881 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010882 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010883 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10884 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010885 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010886 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010887 CEnd = E->capture_end();
10888 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010889 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010890 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010891 EnterExpressionEvaluationContext EEEC(
10892 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010893 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10894 C->getCapturedVar()->getInit(),
10895 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010896
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010897 if (NewExprInitResult.isInvalid())
10898 return ExprError();
10899 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010900
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010901 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010902 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010903 getSema().buildLambdaInitCaptureInitialization(
10904 C->getLocation(), OldVD->getType()->isReferenceType(),
10905 OldVD->getIdentifier(),
10906 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010907 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010908 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10909 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010910 }
10911
Faisal Vali2cba1332013-10-23 06:44:28 +000010912 // Transform the template parameters, and add them to the current
10913 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010914 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010915 E->getTemplateParameterList());
10916
Richard Smith01014ce2014-11-20 23:53:14 +000010917 // Transform the type of the original lambda's call operator.
10918 // The transformation MUST be done in the CurrentInstantiationScope since
10919 // it introduces a mapping of the original to the newly created
10920 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010921 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010922 {
10923 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10924 FunctionProtoTypeLoc OldCallOpFPTL =
10925 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010926
10927 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010928 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010929 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010930 QualType NewCallOpType = TransformFunctionProtoType(
10931 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010932 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10933 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10934 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010935 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010936 if (NewCallOpType.isNull())
10937 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010938 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10939 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010940 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010941
Richard Smithc38498f2015-04-27 21:27:54 +000010942 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10943 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10944 LSI->GLTemplateParameterList = TPL;
10945
Eli Friedmand564afb2012-09-19 01:18:11 +000010946 // Create the local class that will describe the lambda.
10947 CXXRecordDecl *Class
10948 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010949 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010950 /*KnownDependent=*/false,
10951 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010952 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10953
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010954 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010955 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10956 Class, E->getIntroducerRange(), NewCallOpTSI,
10957 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010958 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10959 E->getCallOperator()->isConstexpr());
10960
Faisal Vali2cba1332013-10-23 06:44:28 +000010961 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010962
Akira Hatanaka402818462016-12-16 21:16:57 +000010963 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10964 I != NumParams; ++I) {
10965 auto *P = NewCallOperator->getParamDecl(I);
10966 if (P->hasUninstantiatedDefaultArg()) {
10967 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000010968 getSema(),
10969 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000010970 ExprResult R = getDerived().TransformExpr(
10971 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10972 P->setDefaultArg(R.get());
10973 }
10974 }
10975
Faisal Vali2cba1332013-10-23 06:44:28 +000010976 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010977 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010978
Douglas Gregorb4328232012-02-14 00:00:48 +000010979 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010980 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010981 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010982
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010983 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010984 getSema().buildLambdaScope(LSI, NewCallOperator,
10985 E->getIntroducerRange(),
10986 E->getCaptureDefault(),
10987 E->getCaptureDefaultLoc(),
10988 E->hasExplicitParameters(),
10989 E->hasExplicitResultType(),
10990 E->isMutable());
10991
10992 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010993
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010994 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010995 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010996 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010997 CEnd = E->capture_end();
10998 C != CEnd; ++C) {
10999 // When we hit the first implicit capture, tell Sema that we've finished
11000 // the list of explicit captures.
11001 if (!FinishedExplicitCaptures && C->isImplicit()) {
11002 getSema().finishLambdaExplicitCaptures(LSI);
11003 FinishedExplicitCaptures = true;
11004 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011005
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011006 // Capturing 'this' is trivial.
11007 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011008 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11009 /*BuildAndDiagnose*/ true, nullptr,
11010 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011011 continue;
11012 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011013 // Captured expression will be recaptured during captured variables
11014 // rebuilding.
11015 if (C->capturesVLAType())
11016 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011017
Richard Smithba71c082013-05-16 06:20:58 +000011018 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011019 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011020 InitCaptureInfoTy InitExprTypePair =
11021 InitCaptureExprsAndTypes[C - E->capture_begin()];
11022 ExprResult Init = InitExprTypePair.first;
11023 QualType InitQualType = InitExprTypePair.second;
11024 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000011025 Invalid = true;
11026 continue;
11027 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011028 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011029 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000011030 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11031 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000011032 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000011033 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011034 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000011035 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011036 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011037 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000011038 continue;
11039 }
11040
11041 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11042
Douglas Gregor3e308b12012-02-14 19:27:52 +000011043 // Determine the capture kind for Sema.
11044 Sema::TryCaptureKind Kind
11045 = C->isImplicit()? Sema::TryCapture_Implicit
11046 : C->getCaptureKind() == LCK_ByCopy
11047 ? Sema::TryCapture_ExplicitByVal
11048 : Sema::TryCapture_ExplicitByRef;
11049 SourceLocation EllipsisLoc;
11050 if (C->isPackExpansion()) {
11051 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11052 bool ShouldExpand = false;
11053 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011054 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011055 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11056 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011057 Unexpanded,
11058 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011059 NumExpansions)) {
11060 Invalid = true;
11061 continue;
11062 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011063
Douglas Gregor3e308b12012-02-14 19:27:52 +000011064 if (ShouldExpand) {
11065 // The transform has determined that we should perform an expansion;
11066 // transform and capture each of the arguments.
11067 // expansion of the pattern. Do so.
11068 VarDecl *Pack = C->getCapturedVar();
11069 for (unsigned I = 0; I != *NumExpansions; ++I) {
11070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11071 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011072 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011073 Pack));
11074 if (!CapturedVar) {
11075 Invalid = true;
11076 continue;
11077 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011078
Douglas Gregor3e308b12012-02-14 19:27:52 +000011079 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011080 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11081 }
Richard Smith9467be42014-06-06 17:33:35 +000011082
11083 // FIXME: Retain a pack expansion if RetainExpansion is true.
11084
Douglas Gregor3e308b12012-02-14 19:27:52 +000011085 continue;
11086 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011087
Douglas Gregor3e308b12012-02-14 19:27:52 +000011088 EllipsisLoc = C->getEllipsisLoc();
11089 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011090
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011091 // Transform the captured variable.
11092 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011093 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011094 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011095 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011096 Invalid = true;
11097 continue;
11098 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011099
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011100 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011101 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11102 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011103 }
11104 if (!FinishedExplicitCaptures)
11105 getSema().finishLambdaExplicitCaptures(LSI);
11106
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011107 // Enter a new evaluation context to insulate the lambda from any
11108 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011109 getSema().PushExpressionEvaluationContext(
11110 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011111
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011112 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011113 StmtResult Body =
11114 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11115
11116 // ActOnLambda* will pop the function scope for us.
11117 FuncScopeCleanup.disable();
11118
Douglas Gregorb4328232012-02-14 00:00:48 +000011119 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011120 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000011121 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011122 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011123 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011124 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011125
Richard Smithc38498f2015-04-27 21:27:54 +000011126 // Copy the LSI before ActOnFinishFunctionBody removes it.
11127 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11128 // the call operator.
11129 auto LSICopy = *LSI;
11130 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11131 /*IsInstantiation*/ true);
11132 SavedContext.pop();
11133
11134 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11135 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011136}
11137
11138template<typename Derived>
11139ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011140TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011141 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011142 TypeSourceInfo *T =
11143 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011144 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011146
Douglas Gregora16548e2009-08-11 05:31:07 +000011147 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011148 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011149 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000011150 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011151 &ArgumentChanged))
11152 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011153
Douglas Gregora16548e2009-08-11 05:31:07 +000011154 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011155 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011156 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011157 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011158
Douglas Gregora16548e2009-08-11 05:31:07 +000011159 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000011160 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000011161 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011162 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000011163 E->getRParenLoc());
11164}
Mike Stump11289f42009-09-09 15:08:12 +000011165
Douglas Gregora16548e2009-08-11 05:31:07 +000011166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011167ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011168TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011169 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011170 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011171 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011172 Expr *OldBase;
11173 QualType BaseType;
11174 QualType ObjectType;
11175 if (!E->isImplicitAccess()) {
11176 OldBase = E->getBase();
11177 Base = getDerived().TransformExpr(OldBase);
11178 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011180
John McCall2d74de92009-12-01 22:10:20 +000011181 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011182 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011183 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011184 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011185 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011186 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011187 ObjectTy,
11188 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011189 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011190 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011191
John McCallba7bf592010-08-24 05:47:05 +000011192 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011193 BaseType = ((Expr*) Base.get())->getType();
11194 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011195 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011196 BaseType = getDerived().TransformType(E->getBaseType());
11197 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11198 }
Mike Stump11289f42009-09-09 15:08:12 +000011199
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011200 // Transform the first part of the nested-name-specifier that qualifies
11201 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011202 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011203 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011204 E->getFirstQualifierFoundInScope(),
11205 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011206
Douglas Gregore16af532011-02-28 18:50:33 +000011207 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011208 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011209 QualifierLoc
11210 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11211 ObjectType,
11212 FirstQualifierInScope);
11213 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011214 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011215 }
Mike Stump11289f42009-09-09 15:08:12 +000011216
Abramo Bagnara7945c982012-01-27 09:46:47 +000011217 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11218
John McCall31f82722010-11-12 08:19:04 +000011219 // TODO: If this is a conversion-function-id, verify that the
11220 // destination type name (if present) resolves the same way after
11221 // instantiation as it did in the local scope.
11222
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011223 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011224 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011225 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011227
John McCall2d74de92009-12-01 22:10:20 +000011228 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011229 // This is a reference to a member without an explicitly-specified
11230 // template argument list. Optimize for this common case.
11231 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011232 Base.get() == OldBase &&
11233 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011234 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011235 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011236 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011237 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011238
John McCallb268a282010-08-23 23:25:46 +000011239 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011240 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011241 E->isArrow(),
11242 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011243 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011244 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011245 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011246 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011247 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011248 }
11249
John McCall6b51f282009-11-23 01:53:49 +000011250 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011251 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11252 E->getNumTemplateArgs(),
11253 TransArgs))
11254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011255
John McCallb268a282010-08-23 23:25:46 +000011256 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011257 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011258 E->isArrow(),
11259 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011260 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011261 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011262 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011263 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011264 &TransArgs);
11265}
11266
11267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011269TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011270 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011271 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011272 QualType BaseType;
11273 if (!Old->isImplicitAccess()) {
11274 Base = getDerived().TransformExpr(Old->getBase());
11275 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011276 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011277 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011278 Old->isArrow());
11279 if (Base.isInvalid())
11280 return ExprError();
11281 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011282 } else {
11283 BaseType = getDerived().TransformType(Old->getBaseType());
11284 }
John McCall10eae182009-11-30 22:42:35 +000011285
Douglas Gregor0da1d432011-02-28 20:01:57 +000011286 NestedNameSpecifierLoc QualifierLoc;
11287 if (Old->getQualifierLoc()) {
11288 QualifierLoc
11289 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11290 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011291 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011292 }
11293
Abramo Bagnara7945c982012-01-27 09:46:47 +000011294 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11295
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011296 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011297 Sema::LookupOrdinaryName);
11298
Richard Smith151c4562016-12-20 21:35:28 +000011299 // Transform the declaration set.
11300 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11301 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011302
Douglas Gregor9262f472010-04-27 18:19:34 +000011303 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011304 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011305 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011306 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011307 Old->getMemberLoc(),
11308 Old->getNamingClass()));
11309 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011310 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011311
Douglas Gregorda7be082010-04-27 16:10:10 +000011312 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011313 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011314
John McCall10eae182009-11-30 22:42:35 +000011315 TemplateArgumentListInfo TransArgs;
11316 if (Old->hasExplicitTemplateArgs()) {
11317 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11318 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011319 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11320 Old->getNumTemplateArgs(),
11321 TransArgs))
11322 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011323 }
John McCall38836f02010-01-15 08:34:02 +000011324
11325 // FIXME: to do this check properly, we will need to preserve the
11326 // first-qualifier-in-scope here, just in case we had a dependent
11327 // base (and therefore couldn't do the check) and a
11328 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011329 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011330
John McCallb268a282010-08-23 23:25:46 +000011331 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011332 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011333 Old->getOperatorLoc(),
11334 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011335 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011336 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011337 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011338 R,
11339 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011340 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011341}
11342
11343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011344ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011345TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011346 EnterExpressionEvaluationContext Unevaluated(
11347 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011348 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11349 if (SubExpr.isInvalid())
11350 return ExprError();
11351
11352 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011353 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011354
11355 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11356}
11357
11358template<typename Derived>
11359ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011360TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011361 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11362 if (Pattern.isInvalid())
11363 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011364
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011365 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011366 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011367
Douglas Gregorb8840002011-01-14 21:20:45 +000011368 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11369 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011370}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011371
11372template<typename Derived>
11373ExprResult
11374TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11375 // If E is not value-dependent, then nothing will change when we transform it.
11376 // Note: This is an instantiation-centric view.
11377 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011378 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011379
Faisal Valid143a0c2017-04-01 21:30:49 +000011380 EnterExpressionEvaluationContext Unevaluated(
11381 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011382
Richard Smithd784e682015-09-23 21:41:42 +000011383 ArrayRef<TemplateArgument> PackArgs;
11384 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011385
Richard Smithd784e682015-09-23 21:41:42 +000011386 // Find the argument list to transform.
11387 if (E->isPartiallySubstituted()) {
11388 PackArgs = E->getPartialArguments();
11389 } else if (E->isValueDependent()) {
11390 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11391 bool ShouldExpand = false;
11392 bool RetainExpansion = false;
11393 Optional<unsigned> NumExpansions;
11394 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11395 Unexpanded,
11396 ShouldExpand, RetainExpansion,
11397 NumExpansions))
11398 return ExprError();
11399
11400 // If we need to expand the pack, build a template argument from it and
11401 // expand that.
11402 if (ShouldExpand) {
11403 auto *Pack = E->getPack();
11404 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11405 ArgStorage = getSema().Context.getPackExpansionType(
11406 getSema().Context.getTypeDeclType(TTPD), None);
11407 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11408 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11409 } else {
11410 auto *VD = cast<ValueDecl>(Pack);
11411 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11412 VK_RValue, E->getPackLoc());
11413 if (DRE.isInvalid())
11414 return ExprError();
11415 ArgStorage = new (getSema().Context) PackExpansionExpr(
11416 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11417 }
11418 PackArgs = ArgStorage;
11419 }
11420 }
11421
11422 // If we're not expanding the pack, just transform the decl.
11423 if (!PackArgs.size()) {
11424 auto *Pack = cast_or_null<NamedDecl>(
11425 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011426 if (!Pack)
11427 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011428 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11429 E->getPackLoc(),
11430 E->getRParenLoc(), None, None);
11431 }
11432
Richard Smithc5452ed2016-10-19 22:18:42 +000011433 // Try to compute the result without performing a partial substitution.
11434 Optional<unsigned> Result = 0;
11435 for (const TemplateArgument &Arg : PackArgs) {
11436 if (!Arg.isPackExpansion()) {
11437 Result = *Result + 1;
11438 continue;
11439 }
11440
11441 TemplateArgumentLoc ArgLoc;
11442 InventTemplateArgumentLoc(Arg, ArgLoc);
11443
11444 // Find the pattern of the pack expansion.
11445 SourceLocation Ellipsis;
11446 Optional<unsigned> OrigNumExpansions;
11447 TemplateArgumentLoc Pattern =
11448 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11449 OrigNumExpansions);
11450
11451 // Substitute under the pack expansion. Do not expand the pack (yet).
11452 TemplateArgumentLoc OutPattern;
11453 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11454 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11455 /*Uneval*/ true))
11456 return true;
11457
11458 // See if we can determine the number of arguments from the result.
11459 Optional<unsigned> NumExpansions =
11460 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11461 if (!NumExpansions) {
11462 // No: we must be in an alias template expansion, and we're going to need
11463 // to actually expand the packs.
11464 Result = None;
11465 break;
11466 }
11467
11468 Result = *Result + *NumExpansions;
11469 }
11470
11471 // Common case: we could determine the number of expansions without
11472 // substituting.
11473 if (Result)
11474 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11475 E->getPackLoc(),
11476 E->getRParenLoc(), *Result, None);
11477
Richard Smithd784e682015-09-23 21:41:42 +000011478 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11479 E->getPackLoc());
11480 {
11481 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11482 typedef TemplateArgumentLocInventIterator<
11483 Derived, const TemplateArgument*> PackLocIterator;
11484 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11485 PackLocIterator(*this, PackArgs.end()),
11486 TransformedPackArgs, /*Uneval*/true))
11487 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011488 }
11489
Richard Smithc5452ed2016-10-19 22:18:42 +000011490 // Check whether we managed to fully-expand the pack.
11491 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011492 SmallVector<TemplateArgument, 8> Args;
11493 bool PartialSubstitution = false;
11494 for (auto &Loc : TransformedPackArgs.arguments()) {
11495 Args.push_back(Loc.getArgument());
11496 if (Loc.getArgument().isPackExpansion())
11497 PartialSubstitution = true;
11498 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011499
Richard Smithd784e682015-09-23 21:41:42 +000011500 if (PartialSubstitution)
11501 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11502 E->getPackLoc(),
11503 E->getRParenLoc(), None, Args);
11504
11505 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011506 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011507 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011508}
11509
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011510template<typename Derived>
11511ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011512TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11513 SubstNonTypeTemplateParmPackExpr *E) {
11514 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011515 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011516}
11517
11518template<typename Derived>
11519ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011520TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11521 SubstNonTypeTemplateParmExpr *E) {
11522 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011523 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011524}
11525
11526template<typename Derived>
11527ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011528TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11529 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011530 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011531}
11532
11533template<typename Derived>
11534ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011535TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11536 MaterializeTemporaryExpr *E) {
11537 return getDerived().TransformExpr(E->GetTemporaryExpr());
11538}
Chad Rosier1dcde962012-08-08 18:46:20 +000011539
Douglas Gregorfe314812011-06-21 17:03:29 +000011540template<typename Derived>
11541ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011542TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11543 Expr *Pattern = E->getPattern();
11544
11545 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11546 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11547 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11548
11549 // Determine whether the set of unexpanded parameter packs can and should
11550 // be expanded.
11551 bool Expand = true;
11552 bool RetainExpansion = false;
11553 Optional<unsigned> NumExpansions;
11554 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11555 Pattern->getSourceRange(),
11556 Unexpanded,
11557 Expand, RetainExpansion,
11558 NumExpansions))
11559 return true;
11560
11561 if (!Expand) {
11562 // Do not expand any packs here, just transform and rebuild a fold
11563 // expression.
11564 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11565
11566 ExprResult LHS =
11567 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11568 if (LHS.isInvalid())
11569 return true;
11570
11571 ExprResult RHS =
11572 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11573 if (RHS.isInvalid())
11574 return true;
11575
11576 if (!getDerived().AlwaysRebuild() &&
11577 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11578 return E;
11579
11580 return getDerived().RebuildCXXFoldExpr(
11581 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11582 RHS.get(), E->getLocEnd());
11583 }
11584
11585 // The transform has determined that we should perform an elementwise
11586 // expansion of the pattern. Do so.
11587 ExprResult Result = getDerived().TransformExpr(E->getInit());
11588 if (Result.isInvalid())
11589 return true;
11590 bool LeftFold = E->isLeftFold();
11591
11592 // If we're retaining an expansion for a right fold, it is the innermost
11593 // component and takes the init (if any).
11594 if (!LeftFold && RetainExpansion) {
11595 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11596
11597 ExprResult Out = getDerived().TransformExpr(Pattern);
11598 if (Out.isInvalid())
11599 return true;
11600
11601 Result = getDerived().RebuildCXXFoldExpr(
11602 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11603 Result.get(), E->getLocEnd());
11604 if (Result.isInvalid())
11605 return true;
11606 }
11607
11608 for (unsigned I = 0; I != *NumExpansions; ++I) {
11609 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11610 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11611 ExprResult Out = getDerived().TransformExpr(Pattern);
11612 if (Out.isInvalid())
11613 return true;
11614
11615 if (Out.get()->containsUnexpandedParameterPack()) {
11616 // We still have a pack; retain a pack expansion for this slice.
11617 Result = getDerived().RebuildCXXFoldExpr(
11618 E->getLocStart(),
11619 LeftFold ? Result.get() : Out.get(),
11620 E->getOperator(), E->getEllipsisLoc(),
11621 LeftFold ? Out.get() : Result.get(),
11622 E->getLocEnd());
11623 } else if (Result.isUsable()) {
11624 // We've got down to a single element; build a binary operator.
11625 Result = getDerived().RebuildBinaryOperator(
11626 E->getEllipsisLoc(), E->getOperator(),
11627 LeftFold ? Result.get() : Out.get(),
11628 LeftFold ? Out.get() : Result.get());
11629 } else
11630 Result = Out;
11631
11632 if (Result.isInvalid())
11633 return true;
11634 }
11635
11636 // If we're retaining an expansion for a left fold, it is the outermost
11637 // component and takes the complete expansion so far as its init (if any).
11638 if (LeftFold && RetainExpansion) {
11639 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11640
11641 ExprResult Out = getDerived().TransformExpr(Pattern);
11642 if (Out.isInvalid())
11643 return true;
11644
11645 Result = getDerived().RebuildCXXFoldExpr(
11646 E->getLocStart(), Result.get(),
11647 E->getOperator(), E->getEllipsisLoc(),
11648 Out.get(), E->getLocEnd());
11649 if (Result.isInvalid())
11650 return true;
11651 }
11652
11653 // If we had no init and an empty pack, and we're not retaining an expansion,
11654 // then produce a fallback value or error.
11655 if (Result.isUnset())
11656 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11657 E->getOperator());
11658
11659 return Result;
11660}
11661
11662template<typename Derived>
11663ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011664TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11665 CXXStdInitializerListExpr *E) {
11666 return getDerived().TransformExpr(E->getSubExpr());
11667}
11668
11669template<typename Derived>
11670ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011671TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011672 return SemaRef.MaybeBindToTemporary(E);
11673}
11674
11675template<typename Derived>
11676ExprResult
11677TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011678 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011679}
11680
11681template<typename Derived>
11682ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011683TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11684 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11685 if (SubExpr.isInvalid())
11686 return ExprError();
11687
11688 if (!getDerived().AlwaysRebuild() &&
11689 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011690 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011691
11692 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011693}
11694
11695template<typename Derived>
11696ExprResult
11697TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11698 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011699 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011700 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011701 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011702 /*IsCall=*/false, Elements, &ArgChanged))
11703 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011704
Ted Kremeneke65b0862012-03-06 20:05:56 +000011705 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11706 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011707
Ted Kremeneke65b0862012-03-06 20:05:56 +000011708 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11709 Elements.data(),
11710 Elements.size());
11711}
11712
11713template<typename Derived>
11714ExprResult
11715TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011716 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011717 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011718 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011719 bool ArgChanged = false;
11720 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11721 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011722
Ted Kremeneke65b0862012-03-06 20:05:56 +000011723 if (OrigElement.isPackExpansion()) {
11724 // This key/value element is a pack expansion.
11725 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11726 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11727 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11728 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11729
11730 // Determine whether the set of unexpanded parameter packs can
11731 // and should be expanded.
11732 bool Expand = true;
11733 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011734 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11735 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011736 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11737 OrigElement.Value->getLocEnd());
11738 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11739 PatternRange,
11740 Unexpanded,
11741 Expand, RetainExpansion,
11742 NumExpansions))
11743 return ExprError();
11744
11745 if (!Expand) {
11746 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011747 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011748 // expansion.
11749 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11750 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11751 if (Key.isInvalid())
11752 return ExprError();
11753
11754 if (Key.get() != OrigElement.Key)
11755 ArgChanged = true;
11756
11757 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11758 if (Value.isInvalid())
11759 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011760
Ted Kremeneke65b0862012-03-06 20:05:56 +000011761 if (Value.get() != OrigElement.Value)
11762 ArgChanged = true;
11763
Chad Rosier1dcde962012-08-08 18:46:20 +000011764 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011765 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11766 };
11767 Elements.push_back(Expansion);
11768 continue;
11769 }
11770
11771 // Record right away that the argument was changed. This needs
11772 // to happen even if the array expands to nothing.
11773 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011774
Ted Kremeneke65b0862012-03-06 20:05:56 +000011775 // The transform has determined that we should perform an elementwise
11776 // expansion of the pattern. Do so.
11777 for (unsigned I = 0; I != *NumExpansions; ++I) {
11778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11779 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11780 if (Key.isInvalid())
11781 return ExprError();
11782
11783 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11784 if (Value.isInvalid())
11785 return ExprError();
11786
Chad Rosier1dcde962012-08-08 18:46:20 +000011787 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011788 Key.get(), Value.get(), SourceLocation(), NumExpansions
11789 };
11790
11791 // If any unexpanded parameter packs remain, we still have a
11792 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011793 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011794 if (Key.get()->containsUnexpandedParameterPack() ||
11795 Value.get()->containsUnexpandedParameterPack())
11796 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011797
Ted Kremeneke65b0862012-03-06 20:05:56 +000011798 Elements.push_back(Element);
11799 }
11800
Richard Smith9467be42014-06-06 17:33:35 +000011801 // FIXME: Retain a pack expansion if RetainExpansion is true.
11802
Ted Kremeneke65b0862012-03-06 20:05:56 +000011803 // We've finished with this pack expansion.
11804 continue;
11805 }
11806
11807 // Transform and check key.
11808 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11809 if (Key.isInvalid())
11810 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011811
Ted Kremeneke65b0862012-03-06 20:05:56 +000011812 if (Key.get() != OrigElement.Key)
11813 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011814
Ted Kremeneke65b0862012-03-06 20:05:56 +000011815 // Transform and check value.
11816 ExprResult Value
11817 = getDerived().TransformExpr(OrigElement.Value);
11818 if (Value.isInvalid())
11819 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011820
Ted Kremeneke65b0862012-03-06 20:05:56 +000011821 if (Value.get() != OrigElement.Value)
11822 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011823
11824 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011825 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011826 };
11827 Elements.push_back(Element);
11828 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011829
Ted Kremeneke65b0862012-03-06 20:05:56 +000011830 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11831 return SemaRef.MaybeBindToTemporary(E);
11832
11833 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011834 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011835}
11836
Mike Stump11289f42009-09-09 15:08:12 +000011837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011838ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011839TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011840 TypeSourceInfo *EncodedTypeInfo
11841 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11842 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011844
Douglas Gregora16548e2009-08-11 05:31:07 +000011845 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011846 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011847 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011848
11849 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011850 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011851 E->getRParenLoc());
11852}
Mike Stump11289f42009-09-09 15:08:12 +000011853
Douglas Gregora16548e2009-08-11 05:31:07 +000011854template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011855ExprResult TreeTransform<Derived>::
11856TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011857 // This is a kind of implicit conversion, and it needs to get dropped
11858 // and recomputed for the same general reasons that ImplicitCastExprs
11859 // do, as well a more specific one: this expression is only valid when
11860 // it appears *immediately* as an argument expression.
11861 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011862}
11863
11864template<typename Derived>
11865ExprResult TreeTransform<Derived>::
11866TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011867 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011868 = getDerived().TransformType(E->getTypeInfoAsWritten());
11869 if (!TSInfo)
11870 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011871
John McCall31168b02011-06-15 23:02:42 +000011872 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011873 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011874 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011875
John McCall31168b02011-06-15 23:02:42 +000011876 if (!getDerived().AlwaysRebuild() &&
11877 TSInfo == E->getTypeInfoAsWritten() &&
11878 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011879 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011880
John McCall31168b02011-06-15 23:02:42 +000011881 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011882 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011883 Result.get());
11884}
11885
Erik Pilkington29099de2016-07-16 00:35:23 +000011886template <typename Derived>
11887ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11888 ObjCAvailabilityCheckExpr *E) {
11889 return E;
11890}
11891
John McCall31168b02011-06-15 23:02:42 +000011892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011893ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011894TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011895 // Transform arguments.
11896 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011897 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011898 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011899 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011900 &ArgChanged))
11901 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011902
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011903 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11904 // Class message: transform the receiver type.
11905 TypeSourceInfo *ReceiverTypeInfo
11906 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11907 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011908 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011909
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011910 // If nothing changed, just retain the existing message send.
11911 if (!getDerived().AlwaysRebuild() &&
11912 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011913 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011914
11915 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011916 SmallVector<SourceLocation, 16> SelLocs;
11917 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011918 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11919 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011920 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011921 E->getMethodDecl(),
11922 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011923 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011924 E->getRightLoc());
11925 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011926 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11927 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011928 if (!E->getMethodDecl())
11929 return ExprError();
11930
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011931 // Build a new class message send to 'super'.
11932 SmallVector<SourceLocation, 16> SelLocs;
11933 E->getSelectorLocs(SelLocs);
11934 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11935 E->getSelector(),
11936 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011937 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011938 E->getMethodDecl(),
11939 E->getLeftLoc(),
11940 Args,
11941 E->getRightLoc());
11942 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011943
11944 // Instance message: transform the receiver
11945 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11946 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011947 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011948 = getDerived().TransformExpr(E->getInstanceReceiver());
11949 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011950 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011951
11952 // If nothing changed, just retain the existing message send.
11953 if (!getDerived().AlwaysRebuild() &&
11954 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011955 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011956
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011957 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011958 SmallVector<SourceLocation, 16> SelLocs;
11959 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011960 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011961 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011962 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011963 E->getMethodDecl(),
11964 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011965 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011966 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011967}
11968
Mike Stump11289f42009-09-09 15:08:12 +000011969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011971TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011972 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011973}
11974
Mike Stump11289f42009-09-09 15:08:12 +000011975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011976ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011977TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011978 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011979}
11980
Mike Stump11289f42009-09-09 15:08:12 +000011981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011982ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011983TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011984 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011985 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011986 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011987 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011988
11989 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011990
Douglas Gregord51d90d2010-04-26 20:11:03 +000011991 // If nothing changed, just retain the existing expression.
11992 if (!getDerived().AlwaysRebuild() &&
11993 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011994 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011995
John McCallb268a282010-08-23 23:25:46 +000011996 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011997 E->getLocation(),
11998 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011999}
12000
Mike Stump11289f42009-09-09 15:08:12 +000012001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012003TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012004 // 'super' and types never change. Property never changes. Just
12005 // retain the existing expression.
12006 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012007 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012008
Douglas Gregor9faee212010-04-26 20:47:02 +000012009 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012010 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012011 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012012 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012013
Douglas Gregor9faee212010-04-26 20:47:02 +000012014 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012015
Douglas Gregor9faee212010-04-26 20:47:02 +000012016 // If nothing changed, just retain the existing expression.
12017 if (!getDerived().AlwaysRebuild() &&
12018 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012019 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012020
John McCallb7bd14f2010-12-02 01:19:52 +000012021 if (E->isExplicitProperty())
12022 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12023 E->getExplicitProperty(),
12024 E->getLocation());
12025
12026 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012027 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012028 E->getImplicitPropertyGetter(),
12029 E->getImplicitPropertySetter(),
12030 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012031}
12032
Mike Stump11289f42009-09-09 15:08:12 +000012033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012034ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012035TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12036 // Transform the base expression.
12037 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12038 if (Base.isInvalid())
12039 return ExprError();
12040
12041 // Transform the key expression.
12042 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12043 if (Key.isInvalid())
12044 return ExprError();
12045
12046 // If nothing changed, just retain the existing expression.
12047 if (!getDerived().AlwaysRebuild() &&
12048 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012049 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012050
Chad Rosier1dcde962012-08-08 18:46:20 +000012051 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012052 Base.get(), Key.get(),
12053 E->getAtIndexMethodDecl(),
12054 E->setAtIndexMethodDecl());
12055}
12056
12057template<typename Derived>
12058ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012059TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012060 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012061 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012062 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012063 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012064
Douglas Gregord51d90d2010-04-26 20:11:03 +000012065 // If nothing changed, just retain the existing expression.
12066 if (!getDerived().AlwaysRebuild() &&
12067 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012068 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012069
John McCallb268a282010-08-23 23:25:46 +000012070 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012071 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012072 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012073}
12074
Mike Stump11289f42009-09-09 15:08:12 +000012075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012076ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012077TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012078 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012079 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012080 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012081 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012082 SubExprs, &ArgumentChanged))
12083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012084
Douglas Gregora16548e2009-08-11 05:31:07 +000012085 if (!getDerived().AlwaysRebuild() &&
12086 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012087 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012088
Douglas Gregora16548e2009-08-11 05:31:07 +000012089 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012090 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012091 E->getRParenLoc());
12092}
12093
Mike Stump11289f42009-09-09 15:08:12 +000012094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012095ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012096TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12097 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12098 if (SrcExpr.isInvalid())
12099 return ExprError();
12100
12101 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12102 if (!Type)
12103 return ExprError();
12104
12105 if (!getDerived().AlwaysRebuild() &&
12106 Type == E->getTypeSourceInfo() &&
12107 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012108 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012109
12110 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12111 SrcExpr.get(), Type,
12112 E->getRParenLoc());
12113}
12114
12115template<typename Derived>
12116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012117TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012118 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012119
Craig Topperc3ec1492014-05-26 06:22:03 +000012120 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012121 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12122
12123 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012124 blockScope->TheDecl->setBlockMissingReturnType(
12125 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012126
Chris Lattner01cf8db2011-07-20 06:58:45 +000012127 SmallVector<ParmVarDecl*, 4> params;
12128 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012129
John McCallc8e321d2016-03-01 02:09:25 +000012130 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12131
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012132 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012133 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012134 if (getDerived().TransformFunctionTypeParams(
12135 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12136 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12137 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012138 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012139 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012140 }
John McCall490112f2011-02-04 18:33:18 +000012141
Eli Friedman34b49062012-01-26 03:00:14 +000012142 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012143 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012144
John McCallc8e321d2016-03-01 02:09:25 +000012145 auto epi = exprFunctionType->getExtProtoInfo();
12146 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12147
Jordan Rose5c382722013-03-08 21:51:21 +000012148 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012149 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012150 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012151
12152 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012153 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012154 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012155
12156 if (!oldBlock->blockMissingReturnType()) {
12157 blockScope->HasImplicitReturnType = false;
12158 blockScope->ReturnType = exprResultType;
12159 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012160
John McCall3882ace2011-01-05 12:14:39 +000012161 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012162 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012163 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012164 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012165 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012166 }
John McCall3882ace2011-01-05 12:14:39 +000012167
John McCall490112f2011-02-04 18:33:18 +000012168#ifndef NDEBUG
12169 // In builds with assertions, make sure that we captured everything we
12170 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012171 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012172 for (const auto &I : oldBlock->captures()) {
12173 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012174
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012175 // Ignore parameter packs.
12176 if (isa<ParmVarDecl>(oldCapture) &&
12177 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12178 continue;
John McCall490112f2011-02-04 18:33:18 +000012179
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012180 VarDecl *newCapture =
12181 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12182 oldCapture));
12183 assert(blockScope->CaptureMap.count(newCapture));
12184 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012185 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012186 }
12187#endif
12188
12189 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012190 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012191}
12192
Mike Stump11289f42009-09-09 15:08:12 +000012193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012194ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012195TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012196 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012197}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012198
12199template<typename Derived>
12200ExprResult
12201TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012202 QualType RetTy = getDerived().TransformType(E->getType());
12203 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012204 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012205 SubExprs.reserve(E->getNumSubExprs());
12206 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12207 SubExprs, &ArgumentChanged))
12208 return ExprError();
12209
12210 if (!getDerived().AlwaysRebuild() &&
12211 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012212 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012213
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012214 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012215 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012216}
Chad Rosier1dcde962012-08-08 18:46:20 +000012217
Douglas Gregora16548e2009-08-11 05:31:07 +000012218//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012219// Type reconstruction
12220//===----------------------------------------------------------------------===//
12221
Mike Stump11289f42009-09-09 15:08:12 +000012222template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012223QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12224 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012225 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012226 getDerived().getBaseEntity());
12227}
12228
Mike Stump11289f42009-09-09 15:08:12 +000012229template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012230QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12231 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012232 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012233 getDerived().getBaseEntity());
12234}
12235
Mike Stump11289f42009-09-09 15:08:12 +000012236template<typename Derived>
12237QualType
John McCall70dd5f62009-10-30 00:06:24 +000012238TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12239 bool WrittenAsLValue,
12240 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012241 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012242 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012243}
12244
12245template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012246QualType
John McCall70dd5f62009-10-30 00:06:24 +000012247TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12248 QualType ClassType,
12249 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012250 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12251 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012252}
12253
12254template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012255QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12256 const ObjCTypeParamDecl *Decl,
12257 SourceLocation ProtocolLAngleLoc,
12258 ArrayRef<ObjCProtocolDecl *> Protocols,
12259 ArrayRef<SourceLocation> ProtocolLocs,
12260 SourceLocation ProtocolRAngleLoc) {
12261 return SemaRef.BuildObjCTypeParamType(Decl,
12262 ProtocolLAngleLoc, Protocols,
12263 ProtocolLocs, ProtocolRAngleLoc,
12264 /*FailOnError=*/true);
12265}
12266
12267template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012268QualType TreeTransform<Derived>::RebuildObjCObjectType(
12269 QualType BaseType,
12270 SourceLocation Loc,
12271 SourceLocation TypeArgsLAngleLoc,
12272 ArrayRef<TypeSourceInfo *> TypeArgs,
12273 SourceLocation TypeArgsRAngleLoc,
12274 SourceLocation ProtocolLAngleLoc,
12275 ArrayRef<ObjCProtocolDecl *> Protocols,
12276 ArrayRef<SourceLocation> ProtocolLocs,
12277 SourceLocation ProtocolRAngleLoc) {
12278 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12279 TypeArgs, TypeArgsRAngleLoc,
12280 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12281 ProtocolRAngleLoc,
12282 /*FailOnError=*/true);
12283}
12284
12285template<typename Derived>
12286QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12287 QualType PointeeType,
12288 SourceLocation Star) {
12289 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12290}
12291
12292template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012293QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012294TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12295 ArrayType::ArraySizeModifier SizeMod,
12296 const llvm::APInt *Size,
12297 Expr *SizeExpr,
12298 unsigned IndexTypeQuals,
12299 SourceRange BracketsRange) {
12300 if (SizeExpr || !Size)
12301 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12302 IndexTypeQuals, BracketsRange,
12303 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012304
12305 QualType Types[] = {
12306 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12307 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12308 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012309 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012310 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012311 QualType SizeType;
12312 for (unsigned I = 0; I != NumTypes; ++I)
12313 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12314 SizeType = Types[I];
12315 break;
12316 }
Mike Stump11289f42009-09-09 15:08:12 +000012317
Eli Friedman9562f392012-01-25 23:20:27 +000012318 // Note that we can return a VariableArrayType here in the case where
12319 // the element type was a dependent VariableArrayType.
12320 IntegerLiteral *ArraySize
12321 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12322 /*FIXME*/BracketsRange.getBegin());
12323 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012324 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012325 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012326}
Mike Stump11289f42009-09-09 15:08:12 +000012327
Douglas Gregord6ff3322009-08-04 16:50:30 +000012328template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012329QualType
12330TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012331 ArrayType::ArraySizeModifier SizeMod,
12332 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012333 unsigned IndexTypeQuals,
12334 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012335 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012336 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012337}
12338
12339template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012340QualType
Mike Stump11289f42009-09-09 15:08:12 +000012341TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012342 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012343 unsigned IndexTypeQuals,
12344 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012345 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012346 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012347}
Mike Stump11289f42009-09-09 15:08:12 +000012348
Douglas Gregord6ff3322009-08-04 16:50:30 +000012349template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012350QualType
12351TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012352 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012353 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012354 unsigned IndexTypeQuals,
12355 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012356 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012357 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012358 IndexTypeQuals, BracketsRange);
12359}
12360
12361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012362QualType
12363TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012364 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012365 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012366 unsigned IndexTypeQuals,
12367 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012368 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012369 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012370 IndexTypeQuals, BracketsRange);
12371}
12372
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012373template <typename Derived>
12374QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12375 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12376 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12377 AttributeLoc);
12378}
12379
12380template <typename Derived>
12381QualType
12382TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12383 unsigned NumElements,
12384 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012385 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012386 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012387}
Mike Stump11289f42009-09-09 15:08:12 +000012388
Douglas Gregord6ff3322009-08-04 16:50:30 +000012389template<typename Derived>
12390QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12391 unsigned NumElements,
12392 SourceLocation AttributeLoc) {
12393 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12394 NumElements, true);
12395 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012396 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12397 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012398 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012399}
Mike Stump11289f42009-09-09 15:08:12 +000012400
Douglas Gregord6ff3322009-08-04 16:50:30 +000012401template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012402QualType
12403TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012404 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012405 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012406 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012407}
Mike Stump11289f42009-09-09 15:08:12 +000012408
Douglas Gregord6ff3322009-08-04 16:50:30 +000012409template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012410QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12411 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012412 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012413 const FunctionProtoType::ExtProtoInfo &EPI) {
12414 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012415 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012416 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012417 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012418}
Mike Stump11289f42009-09-09 15:08:12 +000012419
Douglas Gregord6ff3322009-08-04 16:50:30 +000012420template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012421QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12422 return SemaRef.Context.getFunctionNoProtoType(T);
12423}
12424
12425template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012426QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12427 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012428 assert(D && "no decl found");
12429 if (D->isInvalidDecl()) return QualType();
12430
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012431 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012432 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012433 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12434 // A valid resolved using typename pack expansion decl can have multiple
12435 // UsingDecls, but they must each have exactly one type, and it must be
12436 // the same type in every case. But we must have at least one expansion!
12437 if (UPD->expansions().empty()) {
12438 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12439 << UPD->isCXXClassMember() << UPD;
12440 return QualType();
12441 }
12442
12443 // We might still have some unresolved types. Try to pick a resolved type
12444 // if we can. The final instantiation will check that the remaining
12445 // unresolved types instantiate to the type we pick.
12446 QualType FallbackT;
12447 QualType T;
12448 for (auto *E : UPD->expansions()) {
12449 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12450 if (ThisT.isNull())
12451 continue;
12452 else if (ThisT->getAs<UnresolvedUsingType>())
12453 FallbackT = ThisT;
12454 else if (T.isNull())
12455 T = ThisT;
12456 else
12457 assert(getSema().Context.hasSameType(ThisT, T) &&
12458 "mismatched resolved types in using pack expansion");
12459 }
12460 return T.isNull() ? FallbackT : T;
12461 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012462 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012463 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12464
12465 // A valid resolved using typename decl points to exactly one type decl.
12466 assert(++Using->shadow_begin() == Using->shadow_end());
12467 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012468 } else {
12469 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12470 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12471 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12472 }
12473
12474 return SemaRef.Context.getTypeDeclType(Ty);
12475}
12476
12477template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012478QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12479 SourceLocation Loc) {
12480 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012481}
12482
12483template<typename Derived>
12484QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12485 return SemaRef.Context.getTypeOfType(Underlying);
12486}
12487
12488template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012489QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12490 SourceLocation Loc) {
12491 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012492}
12493
12494template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012495QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12496 UnaryTransformType::UTTKind UKind,
12497 SourceLocation Loc) {
12498 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12499}
12500
12501template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012502QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012503 TemplateName Template,
12504 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012505 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012506 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012507}
Mike Stump11289f42009-09-09 15:08:12 +000012508
Douglas Gregor1135c352009-08-06 05:28:30 +000012509template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012510QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12511 SourceLocation KWLoc) {
12512 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12513}
12514
12515template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012516QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012517 SourceLocation KWLoc,
12518 bool isReadPipe) {
12519 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12520 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012521}
12522
12523template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012524TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012525TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012526 bool TemplateKW,
12527 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012528 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012529 Template);
12530}
12531
12532template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012533TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012534TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12535 const IdentifierInfo &Name,
12536 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012537 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012538 NamedDecl *FirstQualifierInScope,
12539 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012540 UnqualifiedId TemplateName;
12541 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012542 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000012543 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000012544 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012545 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012546 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012547 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012548 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012549 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012550}
Mike Stump11289f42009-09-09 15:08:12 +000012551
Douglas Gregora16548e2009-08-11 05:31:07 +000012552template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012553TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012554TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012555 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012556 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012557 QualType ObjectType,
12558 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012559 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012560 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012561 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012562 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000012563 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000012564 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012565 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012566 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012567 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012568 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012569 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012570 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012571}
Chad Rosier1dcde962012-08-08 18:46:20 +000012572
Douglas Gregor71395fa2009-11-04 00:56:37 +000012573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012574ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012575TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12576 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012577 Expr *OrigCallee,
12578 Expr *First,
12579 Expr *Second) {
12580 Expr *Callee = OrigCallee->IgnoreParenCasts();
12581 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012582
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012583 if (First->getObjectKind() == OK_ObjCProperty) {
12584 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12585 if (BinaryOperator::isAssignmentOp(Opc))
12586 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12587 First, Second);
12588 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12589 if (Result.isInvalid())
12590 return ExprError();
12591 First = Result.get();
12592 }
12593
12594 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12595 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12596 if (Result.isInvalid())
12597 return ExprError();
12598 Second = Result.get();
12599 }
12600
Douglas Gregora16548e2009-08-11 05:31:07 +000012601 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012602 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012603 if (!First->getType()->isOverloadableType() &&
12604 !Second->getType()->isOverloadableType())
12605 return getSema().CreateBuiltinArraySubscriptExpr(First,
12606 Callee->getLocStart(),
12607 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012608 } else if (Op == OO_Arrow) {
12609 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012610 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12611 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012612 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012613 // The argument is not of overloadable type, so try to create a
12614 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012615 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012616 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012617
John McCallb268a282010-08-23 23:25:46 +000012618 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012619 }
12620 } else {
John McCallb268a282010-08-23 23:25:46 +000012621 if (!First->getType()->isOverloadableType() &&
12622 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012623 // Neither of the arguments is an overloadable type, so try to
12624 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012625 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012626 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012627 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012628 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012630
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012631 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012632 }
12633 }
Mike Stump11289f42009-09-09 15:08:12 +000012634
12635 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012636 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012637 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000012638 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000012639
John McCallb268a282010-08-23 23:25:46 +000012640 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000012641 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000012642 // If the overload could not be resolved in the template definition
12643 // (because we had a dependent argument), ADL is performed as part of
12644 // template instantiation.
12645 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000012646 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012647 // If we've resolved this to a particular non-member function, just call
12648 // that function. If we resolved it to a member function,
12649 // CreateOverloaded* will find that function for us.
12650 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12651 if (!isa<CXXMethodDecl>(ND))
12652 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000012653 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000012654 }
Mike Stump11289f42009-09-09 15:08:12 +000012655
Douglas Gregora16548e2009-08-11 05:31:07 +000012656 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012657 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012658 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012659
Douglas Gregora16548e2009-08-11 05:31:07 +000012660 // Create the overloaded operator invocation for unary operators.
12661 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012662 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012663 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000012664 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12665 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012666 }
Mike Stump11289f42009-09-09 15:08:12 +000012667
Douglas Gregore9d62932011-07-15 16:25:15 +000012668 if (Op == OO_Subscript) {
12669 SourceLocation LBrace;
12670 SourceLocation RBrace;
12671
12672 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012673 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012674 LBrace = SourceLocation::getFromRawEncoding(
12675 NameLoc.CXXOperatorName.BeginOpNameLoc);
12676 RBrace = SourceLocation::getFromRawEncoding(
12677 NameLoc.CXXOperatorName.EndOpNameLoc);
12678 } else {
12679 LBrace = Callee->getLocStart();
12680 RBrace = OpLoc;
12681 }
12682
12683 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12684 First, Second);
12685 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012686
Douglas Gregora16548e2009-08-11 05:31:07 +000012687 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012688 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000012689 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12690 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012691 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012693
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012694 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012695}
Mike Stump11289f42009-09-09 15:08:12 +000012696
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012697template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012698ExprResult
John McCallb268a282010-08-23 23:25:46 +000012699TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012700 SourceLocation OperatorLoc,
12701 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012702 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012703 TypeSourceInfo *ScopeType,
12704 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012705 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012706 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012707 QualType BaseType = Base->getType();
12708 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012709 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012710 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012711 !BaseType->getAs<PointerType>()->getPointeeType()
12712 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012713 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012714 return SemaRef.BuildPseudoDestructorExpr(
12715 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12716 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012717 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012718
Douglas Gregor678f90d2010-02-25 01:56:36 +000012719 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012720 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12721 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12722 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12723 NameInfo.setNamedTypeInfo(DestroyedType);
12724
Richard Smith8e4a3862012-05-15 06:15:11 +000012725 // The scope type is now known to be a valid nested name specifier
12726 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012727 if (ScopeType) {
12728 if (!ScopeType->getType()->getAs<TagType>()) {
12729 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12730 diag::err_expected_class_or_namespace)
12731 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12732 return ExprError();
12733 }
12734 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12735 CCLoc);
12736 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012737
Abramo Bagnara7945c982012-01-27 09:46:47 +000012738 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012739 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012740 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012741 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012742 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012743 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012744 /*TemplateArgs*/ nullptr,
12745 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012746}
12747
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012748template<typename Derived>
12749StmtResult
12750TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012751 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012752 CapturedDecl *CD = S->getCapturedDecl();
12753 unsigned NumParams = CD->getNumParams();
12754 unsigned ContextParamPos = CD->getContextParamPosition();
12755 SmallVector<Sema::CapturedParamNameType, 4> Params;
12756 for (unsigned I = 0; I < NumParams; ++I) {
12757 if (I != ContextParamPos) {
12758 Params.push_back(
12759 std::make_pair(
12760 CD->getParam(I)->getName(),
12761 getDerived().TransformType(CD->getParam(I)->getType())));
12762 } else {
12763 Params.push_back(std::make_pair(StringRef(), QualType()));
12764 }
12765 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012766 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012767 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012768 StmtResult Body;
12769 {
12770 Sema::CompoundScopeRAII CompoundScope(getSema());
12771 Body = getDerived().TransformStmt(S->getCapturedStmt());
12772 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012773
12774 if (Body.isInvalid()) {
12775 getSema().ActOnCapturedRegionError();
12776 return StmtError();
12777 }
12778
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012779 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012780}
12781
Douglas Gregord6ff3322009-08-04 16:50:30 +000012782} // end namespace clang
12783
Hans Wennborg59dbe862015-09-29 20:56:43 +000012784#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H