blob: 2bee5e7ec82f7462331d03cab3637bc86e6631b2 [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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000044/// A semantic tree transformation that allows one to transform one
Douglas Gregord6ff3322009-08-04 16:50:30 +000045/// 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
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +000060/// overriding function should not be virtual.
Douglas Gregord6ff3322009-08-04 16:50:30 +000061///
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 {
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000097 /// Private RAII object that helps us forget and then re-remember
Douglas Gregora8bac7f2011-01-10 07:32:04 +000098 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000117 /// The set of local declarations that have been transformed, for
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000118 /// 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:
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000123 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000126 /// Retrieves a reference to the derived class.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000127 Derived &getDerived() { return static_cast<Derived&>(*this); }
128
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000129 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000137 /// Retrieves a reference to the semantic analysis object used for
Douglas Gregord6ff3322009-08-04 16:50:30 +0000138 /// this tree transform.
139 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000141 /// Whether the transformation should always rebuild AST nodes, even
Douglas Gregord6ff3322009-08-04 16:50:30 +0000142 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000152 /// Returns the location of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000153 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000160 /// Returns the name of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000161 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000167 /// Sets the "base" location and entity when that
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000174 /// RAII object that temporarily sets the base location and entity
Douglas Gregora16548e2009-08-11 05:31:07 +0000175 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000196 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000207 /// Determine whether the given call argument should be dropped, e.g.,
Douglas Gregord196a582009-12-14 19:27:10 +0000208 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000217 /// Determine whether we should expand a pack expansion with the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000218 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000264 /// "Forget" about the partially-substituted pack template argument,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000265 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000273 /// "Remember" the partially-substituted pack template argument
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000274 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000280 /// Note to the derived class when a function parameter pack is
Douglas Gregorf3010112011-01-07 16:43:16 +0000281 /// being expanded.
282 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000283
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000284 /// Transforms the given type into another type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000285 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000295 /// Transforms the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000296 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000305 /// Transform the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000306 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000311 /// Transform a type that is permitted to produce a
Richard Smithee579842017-01-30 20:39:26 +0000312 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000322 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000333 /// Transform the given statement.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000334 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000343 /// Transform the given attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000344 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000353/// Transform the specified attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000354///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000364 /// Transform the given expression.
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000365 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000374 /// Transform the given initializer.
Richard Smithd59b8322012-12-19 01:39:02 +0000375 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000383 /// Transform the given list of expressions.
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000410 /// Transform the given declaration, which is referenced from a type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000425 /// Transform the specified condition.
Richard Smith03a4aa32016-06-23 19:02:52 +0000426 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000433 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000440 /// Note that a local declaration has been transformed by this
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000441 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000451 /// Transform the definition of the given declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000452 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000459 /// Transform the given declaration, which was the first part of a
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000460 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000476 /// Transform the given nested-name-specifier with source-location
Douglas Gregor14454802011-02-25 02:25:35 +0000477 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000487 /// Transform the given declaration name.
Douglas Gregorf816bd72009-09-03 22:13:48 +0000488 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000496 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000523 /// Transform the given template argument.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000524 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000535 /// Transform the given set of template arguments.
Douglas Gregor62e06f22010-12-20 17:31:10 +0000536 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000561 /// Transform the given set of template arguments.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000562 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000581 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
John McCall0ad16662009-10-29 08:12:44 +0000582 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
583 TemplateArgumentLoc &ArgLoc);
584
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000585 /// Fakes up a TypeSourceInfo for a type.
John McCallbcd03502009-12-07 02:54:59 +0000586 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000625 /// Transforms the parameters of a function type into the
John McCall58f10c32010-03-11 09:03:00 +0000626 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000639 /// Transforms a single function-type parameter. Return null
John McCall58f10c32010-03-11 09:03:00 +0000640 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000687 /// Build a new qualified type given its unqualified type and type
Richard Smithee579842017-01-30 20:39:26 +0000688 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000697 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000698 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000703 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000704 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000709 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000721 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000735 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000736 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000749 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000750 ///
751 /// By default, directly builds the pointer type, with no additional semantic
752 /// analysis.
753 QualType RebuildObjCObjectPointerType(QualType PointeeType,
754 SourceLocation Star);
755
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000756 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000770 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000771 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000781 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000782 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000791 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000802 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000813 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000814 /// 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
Erich Keanef702b022018-07-13 19:46:04 +0000821 /// Build a new potentially dependently-sized extended vector type
822 /// given the element type and 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 RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
827 SourceLocation AttributeLoc,
828 VectorType::VectorKind);
829
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000830 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831 /// number of elements.
832 ///
833 /// By default, performs semantic analysis when building the vector type.
834 /// Subclasses may override this routine to provide different behavior.
835 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
836 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000837
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000838 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000839 /// given the element type and number of elements.
840 ///
841 /// By default, performs semantic analysis when building the vector type.
842 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000843 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000844 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000845 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000846
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000847 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000848 /// type variable with the correct address space (retrieved from
849 /// AddrSpaceExpr) applied to it. The former will be returned in cases
850 /// where the address space remains dependent.
851 ///
852 /// By default, performs semantic analysis when building the type with address
853 /// space applied. Subclasses may override this routine to provide different
854 /// behavior.
855 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
856 Expr *AddrSpaceExpr,
857 SourceLocation AttributeLoc);
858
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000859 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000860 ///
861 /// By default, performs semantic analysis when building the function type.
862 /// Subclasses may override this routine to provide different behavior.
863 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000864 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000865 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000866
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000867 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000868 QualType RebuildFunctionNoProtoType(QualType ResultType);
869
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000870 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000871 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000872 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000873
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000874 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000875 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 return SemaRef.Context.getTypeDeclType(Typedef);
877 }
878
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000879 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000880 QualType RebuildRecordType(RecordDecl *Record) {
881 return SemaRef.Context.getTypeDeclType(Record);
882 }
883
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000884 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 QualType RebuildEnumType(EnumDecl *Enum) {
886 return SemaRef.Context.getTypeDeclType(Enum);
887 }
John McCallfcc33b02009-09-05 00:15:47 +0000888
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000889 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000890 ///
891 /// By default, performs semantic analysis when building the typeof type.
892 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000893 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000894
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000895 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000896 ///
897 /// By default, builds a new TypeOfType with the given underlying type.
898 QualType RebuildTypeOfType(QualType Underlying);
899
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000900 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000901 QualType RebuildUnaryTransformType(QualType BaseType,
902 UnaryTransformType::UTTKind UKind,
903 SourceLocation Loc);
904
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000905 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000906 ///
907 /// By default, performs semantic analysis when building the decltype type.
908 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000909 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000910
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000911 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000912 ///
913 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000914 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000915 // Note, IsDependent is always false here: we implicitly convert an 'auto'
916 // which has been deduced to a dependent type into an undeduced 'auto', so
917 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000918 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000919 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000920 }
921
Richard Smith600b5262017-01-26 20:40:47 +0000922 /// By default, builds a new DeducedTemplateSpecializationType with the given
923 /// deduced type.
924 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
925 QualType Deduced) {
926 return SemaRef.Context.getDeducedTemplateSpecializationType(
927 Template, Deduced, /*IsDependent*/ false);
928 }
929
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000930 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000931 ///
932 /// By default, performs semantic analysis when building the template
933 /// specialization type. Subclasses may override this routine to provide
934 /// different behavior.
935 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000936 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000937 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000938
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000939 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000940 ///
941 /// By default, builds a new ParenType type from the inner type.
942 /// Subclasses may override this routine to provide different behavior.
943 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000944 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000945 }
946
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000947 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000948 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000949 /// By default, builds a new ElaboratedType type from the keyword,
950 /// the nested-name-specifier and the named type.
951 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000952 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
953 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000954 NestedNameSpecifierLoc QualifierLoc,
955 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000956 return SemaRef.Context.getElaboratedType(Keyword,
957 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000958 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000959 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000960
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000961 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000962 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 /// By default, builds a new DependentNameType type from the
964 /// nested-name-specifier and the given type. Subclasses may override
965 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000966 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000967 ElaboratedTypeKeyword Keyword,
968 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000969 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000970 const IdentifierInfo *Name,
971 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000972 TemplateArgumentListInfo &Args,
973 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000974 // Rebuild the template name.
975 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000976 CXXScopeSpec SS;
977 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +0000978 TemplateName InstName = getDerived().RebuildTemplateName(
979 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
980 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregora7a795b2011-03-01 20:11:18 +0000982 if (InstName.isNull())
983 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000984
Douglas Gregora7a795b2011-03-01 20:11:18 +0000985 // If it's still dependent, make a dependent specialization.
986 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000987 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
988 QualifierLoc.getNestedNameSpecifier(),
989 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000990 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000991
Douglas Gregora7a795b2011-03-01 20:11:18 +0000992 // Otherwise, make an elaborated type wrapping a non-dependent
993 // specialization.
994 QualType T =
995 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
996 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000997
Craig Topperc3ec1492014-05-26 06:22:03 +0000998 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000999 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +00001000
1001 return SemaRef.Context.getElaboratedType(Keyword,
1002 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001003 T);
1004 }
1005
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001006 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001007 ///
1008 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001009 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001010 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001011 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001012 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001013 NestedNameSpecifierLoc QualifierLoc,
1014 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001015 SourceLocation IdLoc,
1016 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001017 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001018 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001020 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001021 // If the name is still dependent, just build a new dependent name type.
1022 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001023 return SemaRef.Context.getDependentNameType(Keyword,
1024 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001025 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001026 }
1027
Richard Smithee579842017-01-30 20:39:26 +00001028 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1029 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1030 *Id, IdLoc);
1031 // If a dependent name resolves to a deduced template specialization type,
1032 // check that we're in one of the syntactic contexts permitting it.
1033 if (!DeducedTSTContext) {
1034 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1035 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1036 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1037 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1038 Deduced->getTemplateName())
1039 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1040 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1041 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1042 return QualType();
1043 }
1044 }
1045 return T;
1046 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001047
1048 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1049
Abramo Bagnarad7548482010-05-19 21:37:53 +00001050 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001051 // into a non-dependent elaborated-type-specifier. Find the tag we're
1052 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001053 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001054 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1055 if (!DC)
1056 return QualType();
1057
John McCallbf8c5192010-05-27 06:40:31 +00001058 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1059 return QualType();
1060
Craig Topperc3ec1492014-05-26 06:22:03 +00001061 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001062 SemaRef.LookupQualifiedName(Result, DC);
1063 switch (Result.getResultKind()) {
1064 case LookupResult::NotFound:
1065 case LookupResult::NotFoundInCurrentInstantiation:
1066 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001067
Douglas Gregore677daf2010-03-31 22:19:08 +00001068 case LookupResult::Found:
1069 Tag = Result.getAsSingle<TagDecl>();
1070 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001071
Douglas Gregore677daf2010-03-31 22:19:08 +00001072 case LookupResult::FoundOverloaded:
1073 case LookupResult::FoundUnresolvedValue:
1074 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001075
Douglas Gregore677daf2010-03-31 22:19:08 +00001076 case LookupResult::Ambiguous:
1077 // Let the LookupResult structure handle ambiguities.
1078 return QualType();
1079 }
1080
1081 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001082 // Check where the name exists but isn't a tag type and use that to emit
1083 // better diagnostics.
1084 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1085 SemaRef.LookupQualifiedName(Result, DC);
1086 switch (Result.getResultKind()) {
1087 case LookupResult::Found:
1088 case LookupResult::FoundOverloaded:
1089 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001090 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001091 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1092 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1093 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001094 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1095 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001096 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001097 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001098 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001099 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001100 break;
1101 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001102 return QualType();
1103 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001104
Richard Trieucaa33d32011-06-10 03:11:26 +00001105 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001106 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001107 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001108 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1109 return QualType();
1110 }
1111
1112 // Build the elaborated-type-specifier type.
1113 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001114 return SemaRef.Context.getElaboratedType(Keyword,
1115 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001116 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001117 }
Mike Stump11289f42009-09-09 15:08:12 +00001118
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001119 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001120 ///
1121 /// By default, builds a new PackExpansionType type from the given pattern.
1122 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001123 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001124 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001125 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001126 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001127 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1128 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001129 }
1130
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001131 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001132 ///
1133 /// By default, performs semantic analysis when building the atomic type.
1134 /// Subclasses may override this routine to provide different behavior.
1135 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1136
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001137 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001138 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1139 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001140
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001141 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001142 /// indicating whether the "template" keyword was provided, and the template
1143 /// that the template name refers to.
1144 ///
1145 /// By default, builds the new template name directly. Subclasses may override
1146 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001147 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001148 bool TemplateKW,
1149 TemplateDecl *Template);
1150
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001151 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001152 /// name that is referred to as a template.
1153 ///
1154 /// By default, performs semantic analysis to determine whether the name can
1155 /// be resolved to a specific template, then builds the appropriate kind of
1156 /// template name. Subclasses may override this routine to provide different
1157 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001158 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001159 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001160 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001161 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001162 NamedDecl *FirstQualifierInScope,
1163 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001164
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001165 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001166 /// overloaded operator name that is referred to as a template.
1167 ///
1168 /// By default, performs semantic analysis to determine whether the name can
1169 /// be resolved to a specific template, then builds the appropriate kind of
1170 /// template name. Subclasses may override this routine to provide different
1171 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001172 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001173 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001174 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001175 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001176 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001177
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001178 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001179 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001180 ///
1181 /// By default, performs semantic analysis to determine whether the name can
1182 /// be resolved to a specific template, then builds the appropriate kind of
1183 /// template name. Subclasses may override this routine to provide different
1184 /// behavior.
1185 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1186 const TemplateArgument &ArgPack) {
1187 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1188 }
1189
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001190 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001194 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 MultiStmtArg Statements,
1196 SourceLocation RBraceLoc,
1197 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001198 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 IsStmtExpr);
1200 }
1201
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001202 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001206 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001207 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001209 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001211 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 ColonLoc);
1213 }
Mike Stump11289f42009-09-09 15:08:12 +00001214
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001215 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001216 ///
1217 /// By default, performs semantic analysis to build the new statement.
1218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001219 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001220 getSema().ActOnCaseStmtBody(S, Body);
1221 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 }
Mike Stump11289f42009-09-09 15:08:12 +00001223
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001224 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001228 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001229 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001230 Stmt *SubStmt) {
1231 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001232 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 }
Mike Stump11289f42009-09-09 15:08:12 +00001234
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001235 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001239 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1240 SourceLocation ColonLoc, Stmt *SubStmt) {
1241 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001242 }
Mike Stump11289f42009-09-09 15:08:12 +00001243
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001244 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001245 ///
1246 /// By default, performs semantic analysis to build the new statement.
1247 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001248 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1249 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001250 Stmt *SubStmt) {
1251 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1252 }
1253
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001254 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001258 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001259 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001260 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001261 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001262 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001263 }
Mike Stump11289f42009-09-09 15:08:12 +00001264
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001265 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001269 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001270 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001271 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001272 }
Mike Stump11289f42009-09-09 15:08:12 +00001273
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001274 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001278 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001279 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001280 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001281 }
1282
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001283 /// Build a new while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001284 ///
1285 /// By default, performs semantic analysis to build the new statement.
1286 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001287 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1288 Sema::ConditionResult Cond, Stmt *Body) {
1289 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001290 }
Mike Stump11289f42009-09-09 15:08:12 +00001291
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001292 /// Build a new do-while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001293 ///
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001296 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001297 SourceLocation WhileLoc, SourceLocation LParenLoc,
1298 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001299 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1300 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001301 }
1302
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001303 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001307 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001308 Stmt *Init, Sema::ConditionResult Cond,
1309 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1310 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001311 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001312 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001313 }
Mike Stump11289f42009-09-09 15:08:12 +00001314
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001315 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001319 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1320 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001321 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001322 }
1323
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001324 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001328 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001329 SourceLocation StarLoc,
1330 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001331 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001332 }
Mike Stump11289f42009-09-09 15:08:12 +00001333
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001334 /// Build a new return statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001335 ///
1336 /// By default, performs semantic analysis to build the new statement.
1337 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001338 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001339 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001342 /// Build a new declaration statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001346 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001347 SourceLocation StartLoc, SourceLocation EndLoc) {
1348 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001349 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001350 }
Mike Stump11289f42009-09-09 15:08:12 +00001351
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001352 /// Build a new inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001353 ///
1354 /// By default, performs semantic analysis to build the new statement.
1355 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001356 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1357 bool IsVolatile, unsigned NumOutputs,
1358 unsigned NumInputs, IdentifierInfo **Names,
1359 MultiExprArg Constraints, MultiExprArg Exprs,
1360 Expr *AsmString, MultiExprArg Clobbers,
1361 SourceLocation RParenLoc) {
1362 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1363 NumInputs, Names, Constraints, Exprs,
1364 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001365 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001366
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001367 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001368 ///
1369 /// By default, performs semantic analysis to build the new statement.
1370 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001371 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001372 ArrayRef<Token> AsmToks,
1373 StringRef AsmString,
1374 unsigned NumOutputs, unsigned NumInputs,
1375 ArrayRef<StringRef> Constraints,
1376 ArrayRef<StringRef> Clobbers,
1377 ArrayRef<Expr*> Exprs,
1378 SourceLocation EndLoc) {
1379 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1380 NumOutputs, NumInputs,
1381 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001382 }
1383
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001384 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001385 ///
1386 /// By default, performs semantic analysis to build the new statement.
1387 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001388 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1389 bool IsImplicit) {
1390 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001391 }
1392
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001393 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001394 ///
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001397 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1398 bool IsImplicit) {
1399 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1400 }
1401
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001402 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001403 ///
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1407 Expr *Result,
1408 UnresolvedLookupExpr *Lookup) {
1409 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001410 }
1411
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001412 /// Build a new co_yield expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001413 ///
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
1416 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1417 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1418 }
1419
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001420 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1421 return getSema().BuildCoroutineBodyStmt(Args);
1422 }
1423
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001424 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001425 ///
1426 /// By default, performs semantic analysis to build the new statement.
1427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001428 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001429 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001430 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001431 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001432 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001433 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001434 }
1435
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001436 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001437 ///
1438 /// By default, performs semantic analysis to build the new declaration.
1439 /// Subclasses may override this routine to provide different behavior.
1440 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1441 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001442 return getSema().BuildObjCExceptionDecl(TInfo, T,
1443 ExceptionDecl->getInnerLocStart(),
1444 ExceptionDecl->getLocation(),
1445 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001447
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001448 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001449 ///
1450 /// By default, performs semantic analysis to build the new statement.
1451 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001452 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001453 SourceLocation RParenLoc,
1454 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001455 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001456 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001457 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001458 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001459
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001460 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001461 ///
1462 /// By default, performs semantic analysis to build the new statement.
1463 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001464 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001465 Stmt *Body) {
1466 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001467 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001468
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001469 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001470 ///
1471 /// By default, performs semantic analysis to build the new statement.
1472 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001473 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001474 Expr *Operand) {
1475 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001477
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001478 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001479 ///
1480 /// By default, performs semantic analysis to build the new statement.
1481 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001482 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001483 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001484 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001485 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001486 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001487 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001488 return getSema().ActOnOpenMPExecutableDirective(
1489 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001490 }
1491
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001492 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001493 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001494 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001495 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001496 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1497 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001498 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001499 SourceLocation NameModifierLoc,
1500 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001501 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001502 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1503 LParenLoc, NameModifierLoc, ColonLoc,
1504 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001505 }
1506
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001507 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001508 ///
1509 /// By default, performs semantic analysis to build the new OpenMP clause.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1512 SourceLocation LParenLoc,
1513 SourceLocation EndLoc) {
1514 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1515 EndLoc);
1516 }
1517
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001518 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001519 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001520 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1523 SourceLocation StartLoc,
1524 SourceLocation LParenLoc,
1525 SourceLocation EndLoc) {
1526 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1527 LParenLoc, EndLoc);
1528 }
1529
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001530 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001531 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001532 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1535 SourceLocation LParenLoc,
1536 SourceLocation EndLoc) {
1537 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1538 }
1539
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001540 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001541 ///
1542 /// By default, performs semantic analysis to build the new OpenMP clause.
1543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1545 SourceLocation LParenLoc,
1546 SourceLocation EndLoc) {
1547 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1548 }
1549
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001550 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001551 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001552 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001553 /// Subclasses may override this routine to provide different behavior.
1554 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1555 SourceLocation LParenLoc,
1556 SourceLocation EndLoc) {
1557 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1558 EndLoc);
1559 }
1560
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001561 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001562 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001563 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001564 /// Subclasses may override this routine to provide different behavior.
1565 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1566 SourceLocation KindKwLoc,
1567 SourceLocation StartLoc,
1568 SourceLocation LParenLoc,
1569 SourceLocation EndLoc) {
1570 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1571 StartLoc, LParenLoc, EndLoc);
1572 }
1573
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001574 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001575 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001576 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001577 /// Subclasses may override this routine to provide different behavior.
1578 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1579 SourceLocation KindKwLoc,
1580 SourceLocation StartLoc,
1581 SourceLocation LParenLoc,
1582 SourceLocation EndLoc) {
1583 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1584 StartLoc, LParenLoc, EndLoc);
1585 }
1586
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001587 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001588 ///
1589 /// By default, performs semantic analysis to build the new OpenMP clause.
1590 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001591 OMPClause *RebuildOMPScheduleClause(
1592 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1593 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1594 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1595 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001596 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001597 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1598 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001599 }
1600
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001601 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001602 ///
1603 /// By default, performs semantic analysis to build the new OpenMP clause.
1604 /// Subclasses may override this routine to provide different behavior.
1605 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1606 SourceLocation EndLoc,
1607 SourceLocation LParenLoc, Expr *Num) {
1608 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1609 }
1610
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001611 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001612 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001613 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001614 /// Subclasses may override this routine to provide different behavior.
1615 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1616 SourceLocation StartLoc,
1617 SourceLocation LParenLoc,
1618 SourceLocation EndLoc) {
1619 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1620 EndLoc);
1621 }
1622
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001623 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001624 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001625 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001626 /// Subclasses may override this routine to provide different behavior.
1627 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1628 SourceLocation StartLoc,
1629 SourceLocation LParenLoc,
1630 SourceLocation EndLoc) {
1631 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1632 EndLoc);
1633 }
1634
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001635 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001636 ///
1637 /// By default, performs semantic analysis to build the new OpenMP clause.
1638 /// Subclasses may override this routine to provide different behavior.
1639 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1640 SourceLocation StartLoc,
1641 SourceLocation LParenLoc,
1642 SourceLocation EndLoc) {
1643 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1644 EndLoc);
1645 }
1646
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001647 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001648 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001649 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001650 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001651 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1652 SourceLocation StartLoc,
1653 SourceLocation LParenLoc,
1654 SourceLocation EndLoc) {
1655 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1656 EndLoc);
1657 }
1658
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001659 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001660 ///
1661 /// By default, performs semantic analysis to build the new statement.
1662 /// Subclasses may override this routine to provide different behavior.
1663 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1664 SourceLocation StartLoc,
1665 SourceLocation LParenLoc,
1666 SourceLocation ColonLoc,
1667 SourceLocation EndLoc,
1668 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001669 const DeclarationNameInfo &ReductionId,
1670 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001671 return getSema().ActOnOpenMPReductionClause(
1672 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001673 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001674 }
1675
Alexey Bataev169d96a2017-07-18 20:17:46 +00001676 /// Build a new OpenMP 'task_reduction' clause.
1677 ///
1678 /// By default, performs semantic analysis to build the new statement.
1679 /// Subclasses may override this routine to provide different behavior.
1680 OMPClause *RebuildOMPTaskReductionClause(
1681 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1682 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1683 CXXScopeSpec &ReductionIdScopeSpec,
1684 const DeclarationNameInfo &ReductionId,
1685 ArrayRef<Expr *> UnresolvedReductions) {
1686 return getSema().ActOnOpenMPTaskReductionClause(
1687 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1688 ReductionId, UnresolvedReductions);
1689 }
1690
Alexey Bataevfa312f32017-07-21 18:48:21 +00001691 /// Build a new OpenMP 'in_reduction' clause.
1692 ///
1693 /// By default, performs semantic analysis to build the new statement.
1694 /// Subclasses may override this routine to provide different behavior.
1695 OMPClause *
1696 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1697 SourceLocation LParenLoc, SourceLocation ColonLoc,
1698 SourceLocation EndLoc,
1699 CXXScopeSpec &ReductionIdScopeSpec,
1700 const DeclarationNameInfo &ReductionId,
1701 ArrayRef<Expr *> UnresolvedReductions) {
1702 return getSema().ActOnOpenMPInReductionClause(
1703 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1704 ReductionId, UnresolvedReductions);
1705 }
1706
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001707 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001708 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001709 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001710 /// Subclasses may override this routine to provide different behavior.
1711 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1712 SourceLocation StartLoc,
1713 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001714 OpenMPLinearClauseKind Modifier,
1715 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001716 SourceLocation ColonLoc,
1717 SourceLocation EndLoc) {
1718 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001719 Modifier, ModifierLoc, ColonLoc,
1720 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001721 }
1722
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001723 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001724 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001725 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001726 /// Subclasses may override this routine to provide different behavior.
1727 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1728 SourceLocation StartLoc,
1729 SourceLocation LParenLoc,
1730 SourceLocation ColonLoc,
1731 SourceLocation EndLoc) {
1732 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1733 LParenLoc, ColonLoc, EndLoc);
1734 }
1735
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001736 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001737 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001738 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001739 /// Subclasses may override this routine to provide different behavior.
1740 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1741 SourceLocation StartLoc,
1742 SourceLocation LParenLoc,
1743 SourceLocation EndLoc) {
1744 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1745 EndLoc);
1746 }
1747
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001748 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001749 ///
1750 /// By default, performs semantic analysis to build the new OpenMP clause.
1751 /// Subclasses may override this routine to provide different behavior.
1752 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1753 SourceLocation StartLoc,
1754 SourceLocation LParenLoc,
1755 SourceLocation EndLoc) {
1756 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1757 EndLoc);
1758 }
1759
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001760 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001761 ///
1762 /// By default, performs semantic analysis to build the new OpenMP clause.
1763 /// Subclasses may override this routine to provide different behavior.
1764 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1769 EndLoc);
1770 }
1771
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001772 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001773 ///
1774 /// By default, performs semantic analysis to build the new OpenMP clause.
1775 /// Subclasses may override this routine to provide different behavior.
1776 OMPClause *
1777 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1778 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1779 SourceLocation StartLoc, SourceLocation LParenLoc,
1780 SourceLocation EndLoc) {
1781 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1782 StartLoc, LParenLoc, EndLoc);
1783 }
1784
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001785 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001786 ///
1787 /// By default, performs semantic analysis to build the new statement.
1788 /// Subclasses may override this routine to provide different behavior.
1789 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1790 SourceLocation LParenLoc,
1791 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001792 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001793 EndLoc);
1794 }
1795
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001796 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001797 ///
1798 /// By default, performs semantic analysis to build the new OpenMP clause.
1799 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001800 OMPClause *
1801 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1802 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1803 SourceLocation MapLoc, SourceLocation ColonLoc,
1804 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1805 SourceLocation LParenLoc, SourceLocation EndLoc) {
1806 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1807 IsMapTypeImplicit, MapLoc, ColonLoc,
1808 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001809 }
1810
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001811 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001812 ///
1813 /// By default, performs semantic analysis to build the new statement.
1814 /// Subclasses may override this routine to provide different behavior.
1815 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1816 SourceLocation LParenLoc,
1817 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001818 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001819 EndLoc);
1820 }
1821
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001822 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001823 ///
1824 /// By default, performs semantic analysis to build the new statement.
1825 /// Subclasses may override this routine to provide different behavior.
1826 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1827 SourceLocation StartLoc,
1828 SourceLocation LParenLoc,
1829 SourceLocation EndLoc) {
1830 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1831 LParenLoc, EndLoc);
1832 }
1833
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001834 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001835 ///
1836 /// By default, performs semantic analysis to build the new statement.
1837 /// Subclasses may override this routine to provide different behavior.
1838 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1839 SourceLocation LParenLoc,
1840 SourceLocation EndLoc) {
1841 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1842 EndLoc);
1843 }
1844
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001845 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001846 ///
1847 /// By default, performs semantic analysis to build the new statement.
1848 /// Subclasses may override this routine to provide different behavior.
1849 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1850 SourceLocation LParenLoc,
1851 SourceLocation EndLoc) {
1852 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1853 EndLoc);
1854 }
1855
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001856 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001857 ///
1858 /// By default, performs semantic analysis to build the new statement.
1859 /// Subclasses may override this routine to provide different behavior.
1860 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1861 SourceLocation LParenLoc,
1862 SourceLocation EndLoc) {
1863 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1864 EndLoc);
1865 }
1866
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001867 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001868 ///
1869 /// By default, performs semantic analysis to build the new statement.
1870 /// Subclasses may override this routine to provide different behavior.
1871 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1872 SourceLocation LParenLoc,
1873 SourceLocation EndLoc) {
1874 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1875 }
1876
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001877 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001878 ///
1879 /// By default, performs semantic analysis to build the new OpenMP clause.
1880 /// Subclasses may override this routine to provide different behavior.
1881 OMPClause *
1882 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1883 Expr *ChunkSize, SourceLocation StartLoc,
1884 SourceLocation LParenLoc, SourceLocation KindLoc,
1885 SourceLocation CommaLoc, SourceLocation EndLoc) {
1886 return getSema().ActOnOpenMPDistScheduleClause(
1887 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1888 }
1889
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001890 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001891 ///
1892 /// By default, performs semantic analysis to build the new statement.
1893 /// Subclasses may override this routine to provide different behavior.
1894 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1895 SourceLocation StartLoc,
1896 SourceLocation LParenLoc,
1897 SourceLocation EndLoc) {
1898 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1899 }
1900
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001901 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001902 ///
1903 /// By default, performs semantic analysis to build the new statement.
1904 /// Subclasses may override this routine to provide different behavior.
1905 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1906 SourceLocation StartLoc,
1907 SourceLocation LParenLoc,
1908 SourceLocation EndLoc) {
1909 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1910 EndLoc);
1911 }
1912
Carlo Bertolli2404b172016-07-13 15:37:16 +00001913 /// Build a new OpenMP 'use_device_ptr' clause.
1914 ///
1915 /// By default, performs semantic analysis to build the new OpenMP clause.
1916 /// Subclasses may override this routine to provide different behavior.
1917 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1918 SourceLocation StartLoc,
1919 SourceLocation LParenLoc,
1920 SourceLocation EndLoc) {
1921 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1922 EndLoc);
1923 }
1924
Carlo Bertolli70594e92016-07-13 17:16:49 +00001925 /// Build a new OpenMP 'is_device_ptr' clause.
1926 ///
1927 /// By default, performs semantic analysis to build the new OpenMP clause.
1928 /// Subclasses may override this routine to provide different behavior.
1929 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1930 SourceLocation StartLoc,
1931 SourceLocation LParenLoc,
1932 SourceLocation EndLoc) {
1933 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1934 EndLoc);
1935 }
1936
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001937 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001938 ///
1939 /// By default, performs semantic analysis to build the new statement.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1942 Expr *object) {
1943 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1944 }
1945
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001946 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001947 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001948 /// By default, performs semantic analysis to build the new statement.
1949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001950 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001951 Expr *Object, Stmt *Body) {
1952 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001953 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001954
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001955 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001956 ///
1957 /// By default, performs semantic analysis to build the new statement.
1958 /// Subclasses may override this routine to provide different behavior.
1959 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1960 Stmt *Body) {
1961 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1962 }
John McCall53848232011-07-27 01:07:15 +00001963
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001964 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00001965 ///
1966 /// By default, performs semantic analysis to build the new statement.
1967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001968 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001969 Stmt *Element,
1970 Expr *Collection,
1971 SourceLocation RParenLoc,
1972 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001973 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001974 Element,
John McCallb268a282010-08-23 23:25:46 +00001975 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001976 RParenLoc);
1977 if (ForEachStmt.isInvalid())
1978 return StmtError();
1979
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001980 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001982
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001983 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00001984 ///
1985 /// By default, performs semantic analysis to build the new decaration.
1986 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001987 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001988 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001989 SourceLocation StartLoc,
1990 SourceLocation IdLoc,
1991 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001992 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001993 StartLoc, IdLoc, Id);
1994 if (Var)
1995 getSema().CurContext->addDecl(Var);
1996 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001997 }
1998
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001999 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002000 ///
2001 /// By default, performs semantic analysis to build the new statement.
2002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002003 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002004 VarDecl *ExceptionDecl,
2005 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002006 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2007 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002010 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002011 ///
2012 /// By default, performs semantic analysis to build the new statement.
2013 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002014 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2015 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002016 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002017 }
Mike Stump11289f42009-09-09 15:08:12 +00002018
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002019 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002020 ///
2021 /// By default, performs semantic analysis to build the new statement.
2022 /// Subclasses may override this routine to provide different behavior.
2023 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00002024 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00002025 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002026 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00002027 Expr *Cond, Expr *Inc,
2028 Stmt *LoopVar,
2029 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002030 // If we've just learned that the range is actually an Objective-C
2031 // collection, treat this as an Objective-C fast enumeration loop.
2032 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2033 if (RangeStmt->isSingleDecl()) {
2034 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002035 if (RangeVar->isInvalidDecl())
2036 return StmtError();
2037
Douglas Gregorf7106af2013-04-08 18:40:13 +00002038 Expr *RangeExpr = RangeVar->getInit();
2039 if (!RangeExpr->isTypeDependent() &&
2040 RangeExpr->getType()->isObjCObjectPointerType())
2041 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2042 RParenLoc);
2043 }
2044 }
2045 }
2046
Richard Smithcfd53b42015-10-22 06:13:50 +00002047 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002048 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00002049 Cond, Inc, LoopVar, RParenLoc,
2050 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002051 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002052
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002053 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002054 ///
2055 /// By default, performs semantic analysis to build the new statement.
2056 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002057 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002058 bool IsIfExists,
2059 NestedNameSpecifierLoc QualifierLoc,
2060 DeclarationNameInfo NameInfo,
2061 Stmt *Nested) {
2062 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2063 QualifierLoc, NameInfo, Nested);
2064 }
2065
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002066 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002067 ///
2068 /// By default, performs semantic analysis to finish the new statement.
2069 /// Subclasses may override this routine to provide different behavior.
2070 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2071 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2072 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002073
David Majnemerfad8f482013-10-15 09:33:02 +00002074 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002075 Stmt *TryBlock, Stmt *Handler) {
2076 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002077 }
2078
David Majnemerfad8f482013-10-15 09:33:02 +00002079 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002080 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002081 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002082 }
2083
David Majnemerfad8f482013-10-15 09:33:02 +00002084 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002085 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002086 }
2087
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002088 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
2092 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2093 PredefinedExpr::IdentType IT) {
2094 return getSema().BuildPredefinedExpr(Loc, IT);
2095 }
2096
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002097 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 ///
2099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002101 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002102 LookupResult &R,
2103 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002104 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2105 }
2106
2107
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002108 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002112 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002113 ValueDecl *VD,
2114 const DeclarationNameInfo &NameInfo,
2115 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002116 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002117 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002118
2119 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002120
2121 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 }
Mike Stump11289f42009-09-09 15:08:12 +00002123
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002124 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002130 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 }
2132
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002133 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002134 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002138 SourceLocation OperatorLoc,
2139 bool isArrow,
2140 CXXScopeSpec &SS,
2141 TypeSourceInfo *ScopeType,
2142 SourceLocation CCLoc,
2143 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002144 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002145
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002146 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002147 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// 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 RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002151 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002152 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002153 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 }
Mike Stump11289f42009-09-09 15:08:12 +00002155
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002156 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002160 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002161 TypeSourceInfo *Type,
2162 ArrayRef<Sema::OffsetOfComponent> Components,
2163 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002164 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002165 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002166 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002167
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002168 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002169 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002170 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002173 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2174 SourceLocation OpLoc,
2175 UnaryExprOrTypeTrait ExprKind,
2176 SourceRange R) {
2177 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 }
2179
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002180 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002181 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002182 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// By default, performs semantic analysis to build the new expression.
2184 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002185 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2186 UnaryExprOrTypeTrait ExprKind,
2187 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002189 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002192
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002193 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002196 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002200 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002202 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002204 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002205 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 RBracketLoc);
2207 }
2208
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002209 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002210 ///
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
2213 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2214 Expr *LowerBound,
2215 SourceLocation ColonLoc, Expr *Length,
2216 SourceLocation RBracketLoc) {
2217 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2218 ColonLoc, Length, RBracketLoc);
2219 }
2220
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002221 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002225 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002227 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002228 Expr *ExecConfig = nullptr) {
2229 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002230 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 }
2232
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002233 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002234 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002237 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002238 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002239 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002240 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002241 const DeclarationNameInfo &MemberNameInfo,
2242 ValueDecl *Member,
2243 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002244 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002245 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002246 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2247 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002248 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002249 // We have a reference to an unnamed field. This is always the
2250 // base of an anonymous struct/union member access, i.e. the
2251 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002252 assert(Member->getType()->isRecordType() &&
2253 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002254
Richard Smithcab9a7d2011-10-26 19:06:56 +00002255 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002256 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002257 QualifierLoc.getNestedNameSpecifier(),
2258 FoundDecl, Member);
2259 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002260 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002261 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002262
2263 CXXScopeSpec EmptySS;
2264 return getSema().BuildFieldReferenceExpr(
2265 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2266 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002267 }
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002269 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002270 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002271
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002272 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002273 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002274
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002275 if (isArrow && !BaseType->isPointerType())
2276 return ExprError();
2277
John McCall16df1e52010-03-30 21:47:33 +00002278 // FIXME: this involves duplicating earlier analysis in a lot of
2279 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002280 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002281 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002282 R.resolveKind();
2283
John McCallb268a282010-08-23 23:25:46 +00002284 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002285 SS, TemplateKWLoc,
2286 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002287 R, ExplicitTemplateArgs,
2288 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002291 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002292 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002296 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002297 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002298 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 }
2300
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002301 /// Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002302 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 /// By default, performs semantic analysis to build the new expression.
2304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002305 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002306 SourceLocation QuestionLoc,
2307 Expr *LHS,
2308 SourceLocation ColonLoc,
2309 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002310 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2311 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 }
2313
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002314 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 /// By default, performs semantic analysis to build the new expression.
2317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002318 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002319 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002321 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002322 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002323 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 }
Mike Stump11289f42009-09-09 15:08:12 +00002325
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002326 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002327 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002330 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002331 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002332 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002333 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002334 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002335 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 }
Mike Stump11289f42009-09-09 15:08:12 +00002337
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002338 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002339 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 /// By default, performs semantic analysis to build the new expression.
2341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002342 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 SourceLocation OpLoc,
2344 SourceLocation AccessorLoc,
2345 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002346
John McCall10eae182009-11-30 22:42:35 +00002347 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002348 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002349 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002350 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002351 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002352 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002353 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002354 /* TemplateArgs */ nullptr,
2355 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 }
Mike Stump11289f42009-09-09 15:08:12 +00002357
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002358 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002359 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002362 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002363 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002364 SourceLocation RBraceLoc) {
2365 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 }
Mike Stump11289f42009-09-09 15:08:12 +00002367
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002368 /// Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002369 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 /// By default, performs semantic analysis to build the new expression.
2371 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002372 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 MultiExprArg ArrayExprs,
2374 SourceLocation EqualOrColonLoc,
2375 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002376 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002379 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002382
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002383 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 }
Mike Stump11289f42009-09-09 15:08:12 +00002385
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002386 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002387 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 /// By default, builds the implicit value initialization without performing
2389 /// any semantic analysis. Subclasses may override this routine to provide
2390 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002391 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002392 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 }
Mike Stump11289f42009-09-09 15:08:12 +00002394
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002395 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002396 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002399 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002400 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002401 SourceLocation RParenLoc) {
2402 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002403 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002404 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 }
2406
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002407 /// Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002408 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002411 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002412 MultiExprArg SubExprs,
2413 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002414 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 }
Mike Stump11289f42009-09-09 15:08:12 +00002416
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002417 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002418 ///
2419 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002420 /// rather than attempting to map the label statement itself.
2421 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002422 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002423 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002424 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 }
Mike Stump11289f42009-09-09 15:08:12 +00002426
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002427 /// Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002428 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 /// By default, performs semantic analysis to build the new expression.
2430 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002431 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002432 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002434 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 }
Mike Stump11289f42009-09-09 15:08:12 +00002436
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002437 /// Build a new __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 ///
2439 /// By default, performs semantic analysis to build the new expression.
2440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002441 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002442 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002443 SourceLocation RParenLoc) {
2444 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002445 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 RParenLoc);
2447 }
Mike Stump11289f42009-09-09 15:08:12 +00002448
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002449 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002450 ///
2451 /// By default, performs semantic analysis to build the new expression.
2452 /// Subclasses may override this routine to provide different behavior.
2453 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2454 SourceLocation DefaultLoc,
2455 SourceLocation RParenLoc,
2456 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002457 ArrayRef<TypeSourceInfo *> Types,
2458 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002459 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002460 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002461 }
2462
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002463 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 ///
2465 /// By default, performs semantic analysis to build the new expression.
2466 /// The semantic analysis provides the behavior of template instantiation,
2467 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002468 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002469 /// argument-dependent lookup, etc. Subclasses may override this routine to
2470 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002471 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002472 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002473 Expr *Callee,
2474 Expr *First,
2475 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002476
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002477 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 /// reinterpret_cast.
2479 ///
2480 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002481 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002482 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002483 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002484 Stmt::StmtClass Class,
2485 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002486 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002487 SourceLocation RAngleLoc,
2488 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002489 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 SourceLocation RParenLoc) {
2491 switch (Class) {
2492 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002493 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002494 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002495 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002496
2497 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002498 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002499 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002500 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002501
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002503 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002504 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002505 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002507
Douglas Gregora16548e2009-08-11 05:31:07 +00002508 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002509 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002510 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002511 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002512
Douglas Gregora16548e2009-08-11 05:31:07 +00002513 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002514 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002515 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002516 }
Mike Stump11289f42009-09-09 15:08:12 +00002517
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002518 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002519 ///
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002522 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002523 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002524 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002525 SourceLocation RAngleLoc,
2526 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002527 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002528 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002529 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002530 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002531 SourceRange(LAngleLoc, RAngleLoc),
2532 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 }
2534
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002535 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002536 ///
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002539 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002540 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002541 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002542 SourceLocation RAngleLoc,
2543 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002544 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002545 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002546 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002547 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002548 SourceRange(LAngleLoc, RAngleLoc),
2549 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 }
2551
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002552 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 ///
2554 /// By default, performs semantic analysis to build the new expression.
2555 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002556 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002558 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002559 SourceLocation RAngleLoc,
2560 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002561 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002562 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002563 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002564 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002565 SourceRange(LAngleLoc, RAngleLoc),
2566 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002567 }
2568
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002569 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 ///
2571 /// By default, performs semantic analysis to build the new expression.
2572 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002573 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002574 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002575 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002576 SourceLocation RAngleLoc,
2577 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002578 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002580 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002581 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002582 SourceRange(LAngleLoc, RAngleLoc),
2583 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002584 }
Mike Stump11289f42009-09-09 15:08:12 +00002585
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002586 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 ///
2588 /// By default, performs semantic analysis to build the new expression.
2589 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002590 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2591 SourceLocation LParenLoc,
2592 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002593 SourceLocation RParenLoc,
2594 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002595 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002596 MultiExprArg(&Sub, 1), RParenLoc,
2597 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 }
Mike Stump11289f42009-09-09 15:08:12 +00002599
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002600 /// Build a new C++ typeid(type) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002613 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002625 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002626 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002637 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002638 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002649 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002650 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002661 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002670 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002671 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002680 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002681 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002690 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002691 ///
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) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002697 return getSema().BuildCXXTypeConstructExpr(
2698 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002699 }
Mike Stump11289f42009-09-09 15:08:12 +00002700
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002701 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002702 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002728 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002729 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002740 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002741 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002751 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002752 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002763 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002764 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002774 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002797 /// Build a new template-id expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002798 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002810 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002811 ///
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002840 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002841 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002850 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002851 ///
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,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002855 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002856 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002857 SourceLocation RParenOrBraceLoc,
2858 bool ListInitialization) {
2859 return getSema().BuildCXXTypeConstructExpr(
2860 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002861 }
2862
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002863 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002864 ///
2865 /// By default, performs semantic analysis to build the new expression.
2866 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002867 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2868 SourceLocation LParenLoc,
2869 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002870 SourceLocation RParenLoc,
2871 bool ListInitialization) {
2872 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2873 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002874 }
Mike Stump11289f42009-09-09 15:08:12 +00002875
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002876 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002877 ///
2878 /// By default, performs semantic analysis to build the new expression.
2879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002880 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002881 QualType BaseType,
2882 bool IsArrow,
2883 SourceLocation OperatorLoc,
2884 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002885 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002886 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002887 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002888 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002889 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002890 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002891
John McCallb268a282010-08-23 23:25:46 +00002892 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002893 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002894 SS, TemplateKWLoc,
2895 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002896 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002897 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002898 }
2899
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002900 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002901 ///
2902 /// By default, performs semantic analysis to build the new expression.
2903 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002904 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2905 SourceLocation OperatorLoc,
2906 bool IsArrow,
2907 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002908 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002909 NamedDecl *FirstQualifierInScope,
2910 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002911 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002912 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002913 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002914
John McCallb268a282010-08-23 23:25:46 +00002915 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002916 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002917 SS, TemplateKWLoc,
2918 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002919 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002920 }
Mike Stump11289f42009-09-09 15:08:12 +00002921
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002922 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002923 ///
2924 /// By default, performs semantic analysis to build the new expression.
2925 /// Subclasses may override this routine to provide different behavior.
2926 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2927 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2928 }
2929
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002930 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002931 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2932 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002933 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002934 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002935 Optional<unsigned> Length,
2936 ArrayRef<TemplateArgument> PartialArgs) {
2937 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2938 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002939 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002940
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002941 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00002942 ///
2943 /// By default, performs semantic analysis to build the new expression.
2944 /// Subclasses may override this routine to provide different behavior.
2945 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2946 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002949 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00002950 ///
2951 /// By default, performs semantic analysis to build the new expression.
2952 /// Subclasses may override this routine to provide different behavior.
2953 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2954 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002955 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002956 MultiExprArg(Elements, NumElements));
2957 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002958
2959 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002960 Expr *Base, Expr *Key,
2961 ObjCMethodDecl *getterMethod,
2962 ObjCMethodDecl *setterMethod) {
2963 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2964 getterMethod, setterMethod);
2965 }
2966
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002967 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00002968 ///
2969 /// By default, performs semantic analysis to build the new expression.
2970 /// Subclasses may override this routine to provide different behavior.
2971 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002972 MutableArrayRef<ObjCDictionaryElement> Elements) {
2973 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002975
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002976 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002977 ///
2978 /// By default, performs semantic analysis to build the new expression.
2979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002980 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002981 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002982 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002983 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002984 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002985
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002986 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002987 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002988 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002989 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002990 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002991 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002992 MultiExprArg Args,
2993 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002994 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2995 ReceiverTypeInfo->getType(),
2996 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002997 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002998 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002999 }
3000
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003001 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003002 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003003 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003004 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003005 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003006 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003007 MultiExprArg Args,
3008 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003009 return SemaRef.BuildInstanceMessage(Receiver,
3010 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003011 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003012 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003013 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003014 }
3015
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003016 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003017 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3018 Selector Sel,
3019 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003020 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003021 ObjCMethodDecl *Method,
3022 SourceLocation LBracLoc,
3023 MultiExprArg Args,
3024 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003025 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003026 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003027 SuperLoc,
3028 Sel, Method, LBracLoc, SelectorLocs,
3029 RBracLoc, Args)
3030 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003031 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003032 SuperLoc,
3033 Sel, Method, LBracLoc, SelectorLocs,
3034 RBracLoc, Args);
3035
Fangrui Song6907ce22018-07-30 19:24:48 +00003036
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003037 }
3038
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003039 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003040 ///
3041 /// By default, performs semantic analysis to build the new expression.
3042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003043 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003044 SourceLocation IvarLoc,
3045 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003046 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003047 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003048 ExprResult Result = getSema().BuildMemberReferenceExpr(
3049 BaseArg, BaseArg->getType(),
3050 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3051 /*FirstQualifierInScope=*/nullptr, NameInfo,
3052 /*TemplateArgs=*/nullptr,
3053 /*S=*/nullptr);
3054 if (IsFreeIvar && Result.isUsable())
3055 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3056 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003057 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003058
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003059 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003060 ///
3061 /// By default, performs semantic analysis to build the new expression.
3062 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003063 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003064 ObjCPropertyDecl *Property,
3065 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003066 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003067 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3068 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3069 /*FIXME:*/PropertyLoc,
3070 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003071 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003072 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003073 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003074 /*TemplateArgs=*/nullptr,
3075 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003078 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003079 ///
3080 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003081 /// Subclasses may override this routine to provide different behavior.
3082 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3083 ObjCMethodDecl *Getter,
3084 ObjCMethodDecl *Setter,
3085 SourceLocation PropertyLoc) {
3086 // Since these expressions can only be value-dependent, we do not
3087 // need to perform semantic analysis again.
3088 return Owned(
3089 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3090 VK_LValue, OK_ObjCProperty,
3091 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003092 }
3093
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003094 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003095 ///
3096 /// By default, performs semantic analysis to build the new expression.
3097 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003098 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003099 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003100 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003101 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3102 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003103 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003104 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003105 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003106 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003107 /*TemplateArgs=*/nullptr,
3108 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003109 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003110
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003111 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003112 ///
3113 /// By default, performs semantic analysis to build the new expression.
3114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003115 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003116 MultiExprArg SubExprs,
3117 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003118 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003119 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003120 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3121 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3122 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003123 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003124
Douglas Gregora16548e2009-08-11 05:31:07 +00003125 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003126 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003127 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3128 SemaRef.Context.BuiltinFnTy,
3129 VK_RValue, BuiltinLoc);
3130 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3131 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003132 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003133
3134 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003135 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003136 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003137 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003138
Douglas Gregora16548e2009-08-11 05:31:07 +00003139 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003140 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003141 }
John McCall31f82722010-11-12 08:19:04 +00003142
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003143 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003144 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3145 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3146 SourceLocation RParenLoc) {
3147 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3148 BuiltinLoc, RParenLoc);
3149 }
3150
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003151 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003152 ///
3153 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003154 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003155 /// different behavior.
3156 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003157 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003158 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003159 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003160 case TemplateArgument::Expression: {
3161 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003162 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3163 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003164 if (Result.isInvalid())
3165 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Douglas Gregor98318c22011-01-03 21:37:45 +00003167 return TemplateArgumentLoc(Result.get(), Result.get());
3168 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003170 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003171 return TemplateArgumentLoc(TemplateArgument(
3172 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003173 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003174 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003175 Pattern.getTemplateNameLoc(),
3176 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003177
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003178 case TemplateArgument::Null:
3179 case TemplateArgument::Integral:
3180 case TemplateArgument::Declaration:
3181 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003182 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003183 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003184 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003185
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003186 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003187 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003188 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003189 EllipsisLoc,
3190 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003191 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3192 Expansion);
3193 break;
3194 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003195
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003196 return TemplateArgumentLoc();
3197 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003198
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003199 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003200 ///
3201 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003202 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003203 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003204 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003205 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003206 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003207 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003208
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003209 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003210 ///
3211 /// By default, performs semantic analysis in order to build a new fold
3212 /// expression.
3213 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3214 BinaryOperatorKind Operator,
3215 SourceLocation EllipsisLoc, Expr *RHS,
3216 SourceLocation RParenLoc) {
3217 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3218 RHS, RParenLoc);
3219 }
3220
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003221 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003222 ///
3223 /// By default, produces the fallback value for the fold-expression, or
3224 /// produce an error if there is no fallback value.
3225 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3226 BinaryOperatorKind Operator) {
3227 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3228 }
3229
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003230 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003231 ///
3232 /// By default, performs semantic analysis to build the new expression.
3233 /// Subclasses may override this routine to provide different behavior.
3234 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3235 MultiExprArg SubExprs,
3236 QualType RetTy,
3237 AtomicExpr::AtomicOp Op,
3238 SourceLocation RParenLoc) {
3239 // Just create the expression; there is not any interesting semantic
3240 // analysis here because we can't actually build an AtomicExpr until
3241 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003242 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003243 RParenLoc);
3244 }
3245
John McCall31f82722010-11-12 08:19:04 +00003246private:
Douglas Gregor14454802011-02-25 02:25:35 +00003247 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3248 QualType ObjectType,
3249 NamedDecl *FirstQualifierInScope,
3250 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003251
3252 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3253 QualType ObjectType,
3254 NamedDecl *FirstQualifierInScope,
3255 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003256
3257 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3258 NamedDecl *FirstQualifierInScope,
3259 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003260
3261 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3262 DependentNameTypeLoc TL,
3263 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003264};
Douglas Gregora16548e2009-08-11 05:31:07 +00003265
Douglas Gregorebe10102009-08-20 07:17:43 +00003266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003267StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003268 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003269 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003270
Douglas Gregorebe10102009-08-20 07:17:43 +00003271 switch (S->getStmtClass()) {
3272 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003273
Douglas Gregorebe10102009-08-20 07:17:43 +00003274 // Transform individual statement nodes
3275#define STMT(Node, Parent) \
3276 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003277#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003278#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003279#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003280
Douglas Gregorebe10102009-08-20 07:17:43 +00003281 // Transform expressions by calling TransformExpr.
3282#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003283#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003284#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003285#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003286 {
John McCalldadc5752010-08-24 06:29:42 +00003287 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003288 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003289 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003290
Richard Smith945f8d32013-01-14 22:39:08 +00003291 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003292 }
Mike Stump11289f42009-09-09 15:08:12 +00003293 }
3294
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003295 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003296}
Mike Stump11289f42009-09-09 15:08:12 +00003297
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003298template<typename Derived>
3299OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3300 if (!S)
3301 return S;
3302
3303 switch (S->getClauseKind()) {
3304 default: break;
3305 // Transform individual clause nodes
3306#define OPENMP_CLAUSE(Name, Class) \
3307 case OMPC_ ## Name : \
3308 return getDerived().Transform ## Class(cast<Class>(S));
3309#include "clang/Basic/OpenMPKinds.def"
3310 }
3311
3312 return S;
3313}
3314
Mike Stump11289f42009-09-09 15:08:12 +00003315
Douglas Gregore922c772009-08-04 22:27:00 +00003316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003317ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003318 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003319 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003320
3321 switch (E->getStmtClass()) {
3322 case Stmt::NoStmtClass: break;
3323#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003324#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003325#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003326 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003327#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003328 }
3329
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003330 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003331}
3332
3333template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003334ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003335 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003336 // Initializers are instantiated like expressions, except that various outer
3337 // layers are stripped.
3338 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003339 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003340
3341 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3342 Init = ExprTemp->getSubExpr();
3343
Richard Smith410306b2016-12-12 02:53:20 +00003344 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3345 Init = AIL->getCommonExpr();
3346
Richard Smithe6ca4752013-05-30 22:40:16 +00003347 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3348 Init = MTE->GetTemporaryExpr();
3349
Richard Smithd59b8322012-12-19 01:39:02 +00003350 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3351 Init = Binder->getSubExpr();
3352
3353 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3354 Init = ICE->getSubExprAsWritten();
3355
Richard Smithcc1b96d2013-06-12 22:31:48 +00003356 if (CXXStdInitializerListExpr *ILE =
3357 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003358 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003359
Richard Smithc6abd962014-07-25 01:12:44 +00003360 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003361 // InitListExprs. Other forms of copy-initialization will be a no-op if
3362 // the initializer is already the right type.
3363 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003364 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003365 return getDerived().TransformExpr(Init);
3366
3367 // Revert value-initialization back to empty parens.
3368 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3369 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003370 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003371 Parens.getEnd());
3372 }
3373
3374 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3375 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003376 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003377 SourceLocation());
3378
3379 // Revert initialization by constructor back to a parenthesized or braced list
3380 // of expressions. Any other form of initializer can just be reused directly.
3381 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003382 return getDerived().TransformExpr(Init);
3383
Richard Smithf8adcdc2014-07-17 05:12:35 +00003384 // If the initialization implicitly converted an initializer list to a
3385 // std::initializer_list object, unwrap the std::initializer_list too.
3386 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003387 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003388
Richard Smithd59b8322012-12-19 01:39:02 +00003389 SmallVector<Expr*, 8> NewArgs;
3390 bool ArgChanged = false;
3391 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003392 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003393 return ExprError();
3394
Richard Smithd1036122018-01-12 22:21:33 +00003395 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003396 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003397 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003398 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003399
Richard Smithd59b8322012-12-19 01:39:02 +00003400 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003401 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003402 if (Parens.isInvalid()) {
3403 // This was a variable declaration's initialization for which no initializer
3404 // was specified.
3405 assert(NewArgs.empty() &&
3406 "no parens or braces but have direct init with arguments?");
3407 return ExprEmpty();
3408 }
Richard Smithd59b8322012-12-19 01:39:02 +00003409 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3410 Parens.getEnd());
3411}
3412
3413template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003414bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003415 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003416 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003417 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003418 bool *ArgChanged) {
3419 for (unsigned I = 0; I != NumInputs; ++I) {
3420 // If requested, drop call arguments that need to be dropped.
3421 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3422 if (ArgChanged)
3423 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003424
Douglas Gregora3efea12011-01-03 19:04:46 +00003425 break;
3426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregor968f23a2011-01-03 19:31:53 +00003428 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3429 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Chris Lattner01cf8db2011-07-20 06:58:45 +00003431 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003432 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3433 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003434
Douglas Gregor968f23a2011-01-03 19:31:53 +00003435 // Determine whether the set of unexpanded parameter packs can and should
3436 // be expanded.
3437 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003438 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003439 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3440 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003441 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3442 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003443 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003444 Expand, RetainExpansion,
3445 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003446 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor968f23a2011-01-03 19:31:53 +00003448 if (!Expand) {
3449 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003450 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003451 // expansion.
3452 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3453 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3454 if (OutPattern.isInvalid())
3455 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
3457 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003458 Expansion->getEllipsisLoc(),
3459 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003460 if (Out.isInvalid())
3461 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
Douglas Gregor968f23a2011-01-03 19:31:53 +00003463 if (ArgChanged)
3464 *ArgChanged = true;
3465 Outputs.push_back(Out.get());
3466 continue;
3467 }
John McCall542e7c62011-07-06 07:30:07 +00003468
3469 // Record right away that the argument was changed. This needs
3470 // to happen even if the array expands to nothing.
3471 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregor968f23a2011-01-03 19:31:53 +00003473 // The transform has determined that we should perform an elementwise
3474 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003475 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003476 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3477 ExprResult Out = getDerived().TransformExpr(Pattern);
3478 if (Out.isInvalid())
3479 return true;
3480
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003481 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003482 Out = getDerived().RebuildPackExpansion(
3483 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003484 if (Out.isInvalid())
3485 return true;
3486 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003487
Douglas Gregor968f23a2011-01-03 19:31:53 +00003488 Outputs.push_back(Out.get());
3489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Richard Smith9467be42014-06-06 17:33:35 +00003491 // If we're supposed to retain a pack expansion, do so by temporarily
3492 // forgetting the partially-substituted parameter pack.
3493 if (RetainExpansion) {
3494 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3495
3496 ExprResult Out = getDerived().TransformExpr(Pattern);
3497 if (Out.isInvalid())
3498 return true;
3499
3500 Out = getDerived().RebuildPackExpansion(
3501 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3502 if (Out.isInvalid())
3503 return true;
3504
3505 Outputs.push_back(Out.get());
3506 }
3507
Douglas Gregor968f23a2011-01-03 19:31:53 +00003508 continue;
3509 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003510
Richard Smithd59b8322012-12-19 01:39:02 +00003511 ExprResult Result =
3512 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3513 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003514 if (Result.isInvalid())
3515 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregora3efea12011-01-03 19:04:46 +00003517 if (Result.get() != Inputs[I] && ArgChanged)
3518 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
3520 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003522
Douglas Gregora3efea12011-01-03 19:04:46 +00003523 return false;
3524}
3525
Richard Smith03a4aa32016-06-23 19:02:52 +00003526template <typename Derived>
3527Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3528 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3529 if (Var) {
3530 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3531 getDerived().TransformDefinition(Var->getLocation(), Var));
3532
3533 if (!ConditionVar)
3534 return Sema::ConditionError();
3535
3536 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3537 }
3538
3539 if (Expr) {
3540 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3541
3542 if (CondExpr.isInvalid())
3543 return Sema::ConditionError();
3544
3545 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3546 }
3547
3548 return Sema::ConditionResult();
3549}
3550
Douglas Gregora3efea12011-01-03 19:04:46 +00003551template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003552NestedNameSpecifierLoc
3553TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3554 NestedNameSpecifierLoc NNS,
3555 QualType ObjectType,
3556 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003557 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003558 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003559 Qualifier = Qualifier.getPrefix())
3560 Qualifiers.push_back(Qualifier);
3561
3562 CXXScopeSpec SS;
3563 while (!Qualifiers.empty()) {
3564 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3565 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003566
Douglas Gregor14454802011-02-25 02:25:35 +00003567 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003568 case NestedNameSpecifier::Identifier: {
3569 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3570 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3571 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3572 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003573 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003574 }
Douglas Gregor14454802011-02-25 02:25:35 +00003575 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
Douglas Gregor14454802011-02-25 02:25:35 +00003577 case NestedNameSpecifier::Namespace: {
3578 NamespaceDecl *NS
3579 = cast_or_null<NamespaceDecl>(
3580 getDerived().TransformDecl(
3581 Q.getLocalBeginLoc(),
3582 QNNS->getAsNamespace()));
3583 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3584 break;
3585 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003586
Douglas Gregor14454802011-02-25 02:25:35 +00003587 case NestedNameSpecifier::NamespaceAlias: {
3588 NamespaceAliasDecl *Alias
3589 = cast_or_null<NamespaceAliasDecl>(
3590 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3591 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003592 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003593 Q.getLocalEndLoc());
3594 break;
3595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregor14454802011-02-25 02:25:35 +00003597 case NestedNameSpecifier::Global:
3598 // There is no meaningful transformation that one could perform on the
3599 // global scope.
3600 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3601 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003602
Nikola Smiljanic67860242014-09-26 00:28:20 +00003603 case NestedNameSpecifier::Super: {
3604 CXXRecordDecl *RD =
3605 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3606 SourceLocation(), QNNS->getAsRecordDecl()));
3607 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3608 break;
3609 }
3610
Douglas Gregor14454802011-02-25 02:25:35 +00003611 case NestedNameSpecifier::TypeSpecWithTemplate:
3612 case NestedNameSpecifier::TypeSpec: {
3613 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3614 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
Douglas Gregor14454802011-02-25 02:25:35 +00003616 if (!TL)
3617 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor14454802011-02-25 02:25:35 +00003619 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003620 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003621 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003622 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003623 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003624 if (TL.getType()->isEnumeralType())
3625 SemaRef.Diag(TL.getBeginLoc(),
3626 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003627 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3628 Q.getLocalEndLoc());
3629 break;
3630 }
Richard Trieude756fb2011-05-07 01:36:37 +00003631 // If the nested-name-specifier is an invalid type def, don't emit an
3632 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003633 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3634 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003635 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003636 << TL.getType() << SS.getRange();
3637 }
Douglas Gregor14454802011-02-25 02:25:35 +00003638 return NestedNameSpecifierLoc();
3639 }
Douglas Gregore16af532011-02-28 18:50:33 +00003640 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
Douglas Gregore16af532011-02-28 18:50:33 +00003642 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003643 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003644 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003645 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregor14454802011-02-25 02:25:35 +00003647 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003648 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003649 !getDerived().AlwaysRebuild())
3650 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003651
3652 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003653 // nested-name-specifier, do so.
3654 if (SS.location_size() == NNS.getDataLength() &&
3655 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3656 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3657
3658 // Allocate new nested-name-specifier location information.
3659 return SS.getWithLocInContext(SemaRef.Context);
3660}
3661
3662template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003663DeclarationNameInfo
3664TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003665::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003666 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003667 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003668 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003669
3670 switch (Name.getNameKind()) {
3671 case DeclarationName::Identifier:
3672 case DeclarationName::ObjCZeroArgSelector:
3673 case DeclarationName::ObjCOneArgSelector:
3674 case DeclarationName::ObjCMultiArgSelector:
3675 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003676 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003677 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003678 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003679
Richard Smith35845152017-02-07 01:37:30 +00003680 case DeclarationName::CXXDeductionGuideName: {
3681 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3682 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3683 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3684 if (!NewTemplate)
3685 return DeclarationNameInfo();
3686
3687 DeclarationNameInfo NewNameInfo(NameInfo);
3688 NewNameInfo.setName(
3689 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3690 return NewNameInfo;
3691 }
3692
Douglas Gregorf816bd72009-09-03 22:13:48 +00003693 case DeclarationName::CXXConstructorName:
3694 case DeclarationName::CXXDestructorName:
3695 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003696 TypeSourceInfo *NewTInfo;
3697 CanQualType NewCanTy;
3698 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003699 NewTInfo = getDerived().TransformType(OldTInfo);
3700 if (!NewTInfo)
3701 return DeclarationNameInfo();
3702 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003703 }
3704 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003705 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003706 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003707 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003708 if (NewT.isNull())
3709 return DeclarationNameInfo();
3710 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3711 }
Mike Stump11289f42009-09-09 15:08:12 +00003712
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003713 DeclarationName NewName
3714 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3715 NewCanTy);
3716 DeclarationNameInfo NewNameInfo(NameInfo);
3717 NewNameInfo.setName(NewName);
3718 NewNameInfo.setNamedTypeInfo(NewTInfo);
3719 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003720 }
Mike Stump11289f42009-09-09 15:08:12 +00003721 }
3722
David Blaikie83d382b2011-09-23 05:06:16 +00003723 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003724}
3725
3726template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003727TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003728TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3729 TemplateName Name,
3730 SourceLocation NameLoc,
3731 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003732 NamedDecl *FirstQualifierInScope,
3733 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003734 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3735 TemplateDecl *Template = QTN->getTemplateDecl();
3736 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003737
Douglas Gregor9db53502011-03-02 18:07:45 +00003738 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003739 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003740 Template));
3741 if (!TransTemplate)
3742 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Douglas Gregor9db53502011-03-02 18:07:45 +00003744 if (!getDerived().AlwaysRebuild() &&
3745 SS.getScopeRep() == QTN->getQualifier() &&
3746 TransTemplate == Template)
3747 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003748
Douglas Gregor9db53502011-03-02 18:07:45 +00003749 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3750 TransTemplate);
3751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003752
Douglas Gregor9db53502011-03-02 18:07:45 +00003753 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3754 if (SS.getScopeRep()) {
3755 // These apply to the scope specifier, not the template.
3756 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003757 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003758 }
3759
Douglas Gregor9db53502011-03-02 18:07:45 +00003760 if (!getDerived().AlwaysRebuild() &&
3761 SS.getScopeRep() == DTN->getQualifier() &&
3762 ObjectType.isNull())
3763 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Richard Smith79810042018-05-11 02:43:08 +00003765 // FIXME: Preserve the location of the "template" keyword.
3766 SourceLocation TemplateKWLoc = NameLoc;
3767
Douglas Gregor9db53502011-03-02 18:07:45 +00003768 if (DTN->isIdentifier()) {
3769 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003770 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003771 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003772 NameLoc,
3773 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003774 FirstQualifierInScope,
3775 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003776 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003777
Richard Smith79810042018-05-11 02:43:08 +00003778 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3779 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003780 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003781 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregor9db53502011-03-02 18:07:45 +00003783 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3784 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003785 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003786 Template));
3787 if (!TransTemplate)
3788 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003789
Douglas Gregor9db53502011-03-02 18:07:45 +00003790 if (!getDerived().AlwaysRebuild() &&
3791 TransTemplate == Template)
3792 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003793
Douglas Gregor9db53502011-03-02 18:07:45 +00003794 return TemplateName(TransTemplate);
3795 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003796
Douglas Gregor9db53502011-03-02 18:07:45 +00003797 if (SubstTemplateTemplateParmPackStorage *SubstPack
3798 = Name.getAsSubstTemplateTemplateParmPack()) {
3799 TemplateTemplateParmDecl *TransParam
3800 = cast_or_null<TemplateTemplateParmDecl>(
3801 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3802 if (!TransParam)
3803 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003804
Douglas Gregor9db53502011-03-02 18:07:45 +00003805 if (!getDerived().AlwaysRebuild() &&
3806 TransParam == SubstPack->getParameterPack())
3807 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003808
3809 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003810 SubstPack->getArgumentPack());
3811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003812
Douglas Gregor9db53502011-03-02 18:07:45 +00003813 // These should be getting filtered out before they reach the AST.
3814 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003815}
3816
3817template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003818void TreeTransform<Derived>::InventTemplateArgumentLoc(
3819 const TemplateArgument &Arg,
3820 TemplateArgumentLoc &Output) {
3821 SourceLocation Loc = getDerived().getBaseLocation();
3822 switch (Arg.getKind()) {
3823 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003824 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003825 break;
3826
3827 case TemplateArgument::Type:
3828 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003829 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003830
John McCall0ad16662009-10-29 08:12:44 +00003831 break;
3832
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003833 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003834 case TemplateArgument::TemplateExpansion: {
3835 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003836 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003837 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3838 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3839 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3840 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor9d802122011-03-02 17:09:35 +00003842 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003843 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003844 Builder.getWithLocInContext(SemaRef.Context),
3845 Loc);
3846 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003847 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003848 Builder.getWithLocInContext(SemaRef.Context),
3849 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003850
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003851 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003852 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003853
John McCall0ad16662009-10-29 08:12:44 +00003854 case TemplateArgument::Expression:
3855 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3856 break;
3857
3858 case TemplateArgument::Declaration:
3859 case TemplateArgument::Integral:
3860 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003861 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003862 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003863 break;
3864 }
3865}
3866
3867template<typename Derived>
3868bool TreeTransform<Derived>::TransformTemplateArgument(
3869 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003870 TemplateArgumentLoc &Output, bool Uneval) {
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00003871 EnterExpressionEvaluationContext EEEC(
3872 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
3873 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3874 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
John McCall0ad16662009-10-29 08:12:44 +00003875 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003876 switch (Arg.getKind()) {
3877 case TemplateArgument::Null:
3878 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003879 case TemplateArgument::Pack:
3880 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003881 case TemplateArgument::NullPtr:
3882 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003883
Douglas Gregore922c772009-08-04 22:27:00 +00003884 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003885 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003886 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003887 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003888
3889 DI = getDerived().TransformType(DI);
3890 if (!DI) return true;
3891
3892 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3893 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003894 }
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003896 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003897 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3898 if (QualifierLoc) {
3899 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3900 if (!QualifierLoc)
3901 return true;
3902 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003903
Douglas Gregordf846d12011-03-02 18:46:51 +00003904 CXXScopeSpec SS;
3905 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003906 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003907 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3908 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003909 if (Template.isNull())
3910 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003911
Douglas Gregor9d802122011-03-02 17:09:35 +00003912 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003913 Input.getTemplateNameLoc());
3914 return false;
3915 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003916
3917 case TemplateArgument::TemplateExpansion:
3918 llvm_unreachable("Caller should expand pack expansions");
3919
Douglas Gregore922c772009-08-04 22:27:00 +00003920 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003921 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003922 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003923 getSema(), Uneval
3924 ? Sema::ExpressionEvaluationContext::Unevaluated
3925 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003926
John McCall0ad16662009-10-29 08:12:44 +00003927 Expr *InputExpr = Input.getSourceExpression();
3928 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3929
Chris Lattnercdb591a2011-04-25 20:37:58 +00003930 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003931 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003932 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003933 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003934 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003935 }
Douglas Gregore922c772009-08-04 22:27:00 +00003936 }
Mike Stump11289f42009-09-09 15:08:12 +00003937
Douglas Gregore922c772009-08-04 22:27:00 +00003938 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003939 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003940}
3941
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003942/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00003943/// for each of the template arguments in its underlying iterator.
3944template<typename Derived, typename InputIterator>
3945class TemplateArgumentLocInventIterator {
3946 TreeTransform<Derived> &Self;
3947 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003948
Douglas Gregorfe921a72010-12-20 23:36:19 +00003949public:
3950 typedef TemplateArgumentLoc value_type;
3951 typedef TemplateArgumentLoc reference;
3952 typedef typename std::iterator_traits<InputIterator>::difference_type
3953 difference_type;
3954 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003955
Douglas Gregorfe921a72010-12-20 23:36:19 +00003956 class pointer {
3957 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003958
Douglas Gregorfe921a72010-12-20 23:36:19 +00003959 public:
3960 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003961
Douglas Gregorfe921a72010-12-20 23:36:19 +00003962 const TemplateArgumentLoc *operator->() const { return &Arg; }
3963 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003964
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003965 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003966
Douglas Gregorfe921a72010-12-20 23:36:19 +00003967 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3968 InputIterator Iter)
3969 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003970
Douglas Gregorfe921a72010-12-20 23:36:19 +00003971 TemplateArgumentLocInventIterator &operator++() {
3972 ++Iter;
3973 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003975
Douglas Gregorfe921a72010-12-20 23:36:19 +00003976 TemplateArgumentLocInventIterator operator++(int) {
3977 TemplateArgumentLocInventIterator Old(*this);
3978 ++(*this);
3979 return Old;
3980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003981
Douglas Gregorfe921a72010-12-20 23:36:19 +00003982 reference operator*() const {
3983 TemplateArgumentLoc Result;
3984 Self.InventTemplateArgumentLoc(*Iter, Result);
3985 return Result;
3986 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003987
Douglas Gregorfe921a72010-12-20 23:36:19 +00003988 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003989
Douglas Gregorfe921a72010-12-20 23:36:19 +00003990 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3991 const TemplateArgumentLocInventIterator &Y) {
3992 return X.Iter == Y.Iter;
3993 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003994
Douglas Gregorfe921a72010-12-20 23:36:19 +00003995 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3996 const TemplateArgumentLocInventIterator &Y) {
3997 return X.Iter != Y.Iter;
3998 }
3999};
Chad Rosier1dcde962012-08-08 18:46:20 +00004000
Douglas Gregor42cafa82010-12-20 17:42:22 +00004001template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004002template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004003bool TreeTransform<Derived>::TransformTemplateArguments(
4004 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4005 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004006 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004007 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004008 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004009
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004010 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4011 // Unpack argument packs, which we translate them into separate
4012 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004013 // FIXME: We could do much better if we could guarantee that the
4014 // TemplateArgumentLocInfo for the pack expansion would be usable for
4015 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004016 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004017 TemplateArgument::pack_iterator>
4018 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004019 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004020 In.getArgument().pack_begin()),
4021 PackLocIterator(*this,
4022 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004023 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004024 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004025
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004026 continue;
4027 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004028
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004029 if (In.getArgument().isPackExpansion()) {
4030 // We have a pack expansion, for which we will be substituting into
4031 // the pattern.
4032 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004033 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004034 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004035 = getSema().getTemplateArgumentPackExpansionPattern(
4036 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004037
Chris Lattner01cf8db2011-07-20 06:58:45 +00004038 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004039 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4040 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004041
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004042 // Determine whether the set of unexpanded parameter packs can and should
4043 // be expanded.
4044 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004045 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004046 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004047 if (getDerived().TryExpandParameterPacks(Ellipsis,
4048 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004049 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004050 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004051 RetainExpansion,
4052 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004053 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004054
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004055 if (!Expand) {
4056 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004057 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004058 // expansion.
4059 TemplateArgumentLoc OutPattern;
4060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004061 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004062 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004063
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004064 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4065 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004066 if (Out.getArgument().isNull())
4067 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004068
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004069 Outputs.addArgument(Out);
4070 continue;
4071 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004072
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004073 // The transform has determined that we should perform an elementwise
4074 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004075 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004076 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4077
Richard Smithd784e682015-09-23 21:41:42 +00004078 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004079 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004080
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004081 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004082 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4083 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004084 if (Out.getArgument().isNull())
4085 return true;
4086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004087
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004088 Outputs.addArgument(Out);
4089 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004090
Douglas Gregor48d24112011-01-10 20:53:55 +00004091 // If we're supposed to retain a pack expansion, do so by temporarily
4092 // forgetting the partially-substituted parameter pack.
4093 if (RetainExpansion) {
4094 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004095
Richard Smithd784e682015-09-23 21:41:42 +00004096 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004097 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004098
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004099 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4100 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004101 if (Out.getArgument().isNull())
4102 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004103
Douglas Gregor48d24112011-01-10 20:53:55 +00004104 Outputs.addArgument(Out);
4105 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004106
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004107 continue;
4108 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004109
4110 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004111 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004112 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
Douglas Gregor42cafa82010-12-20 17:42:22 +00004114 Outputs.addArgument(Out);
4115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
Douglas Gregor42cafa82010-12-20 17:42:22 +00004117 return false;
4118
4119}
4120
Douglas Gregord6ff3322009-08-04 16:50:30 +00004121//===----------------------------------------------------------------------===//
4122// Type transformation
4123//===----------------------------------------------------------------------===//
4124
4125template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004126QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004127 if (getDerived().AlreadyTransformed(T))
4128 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004129
John McCall550e0c22009-10-21 00:40:46 +00004130 // Temporary workaround. All of these transformations should
4131 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004132 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4133 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004134
John McCall31f82722010-11-12 08:19:04 +00004135 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004136
John McCall550e0c22009-10-21 00:40:46 +00004137 if (!NewDI)
4138 return QualType();
4139
4140 return NewDI->getType();
4141}
4142
4143template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004144TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004145 // Refine the base location to the type's location.
4146 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4147 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004148 if (getDerived().AlreadyTransformed(DI->getType()))
4149 return DI;
4150
4151 TypeLocBuilder TLB;
4152
4153 TypeLoc TL = DI->getTypeLoc();
4154 TLB.reserve(TL.getFullDataSize());
4155
John McCall31f82722010-11-12 08:19:04 +00004156 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004157 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004158 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004159
John McCallbcd03502009-12-07 02:54:59 +00004160 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004161}
4162
4163template<typename Derived>
4164QualType
John McCall31f82722010-11-12 08:19:04 +00004165TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004166 switch (T.getTypeLocClass()) {
4167#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004168#define TYPELOC(CLASS, PARENT) \
4169 case TypeLoc::CLASS: \
4170 return getDerived().Transform##CLASS##Type(TLB, \
4171 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004172#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004173 }
Mike Stump11289f42009-09-09 15:08:12 +00004174
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004175 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004176}
4177
Richard Smithee579842017-01-30 20:39:26 +00004178template<typename Derived>
4179QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4180 if (!isa<DependentNameType>(T))
4181 return TransformType(T);
4182
4183 if (getDerived().AlreadyTransformed(T))
4184 return T;
4185 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4186 getDerived().getBaseLocation());
4187 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4188 return NewDI ? NewDI->getType() : QualType();
4189}
4190
4191template<typename Derived>
4192TypeSourceInfo *
4193TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4194 if (!isa<DependentNameType>(DI->getType()))
4195 return TransformType(DI);
4196
4197 // Refine the base location to the type's location.
4198 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4199 getDerived().getBaseEntity());
4200 if (getDerived().AlreadyTransformed(DI->getType()))
4201 return DI;
4202
4203 TypeLocBuilder TLB;
4204
4205 TypeLoc TL = DI->getTypeLoc();
4206 TLB.reserve(TL.getFullDataSize());
4207
Richard Smithee579842017-01-30 20:39:26 +00004208 auto QTL = TL.getAs<QualifiedTypeLoc>();
4209 if (QTL)
4210 TL = QTL.getUnqualifiedLoc();
4211
4212 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4213
4214 QualType Result = getDerived().TransformDependentNameType(
4215 TLB, DNTL, /*DeducedTSTContext*/true);
4216 if (Result.isNull())
4217 return nullptr;
4218
4219 if (QTL) {
4220 Result = getDerived().RebuildQualifiedType(
4221 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4222 TLB.TypeWasModifiedSafely(Result);
4223 }
4224
4225 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4226}
4227
John McCall550e0c22009-10-21 00:40:46 +00004228template<typename Derived>
4229QualType
4230TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004231 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004232 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004233
John McCall31f82722010-11-12 08:19:04 +00004234 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004235 if (Result.isNull())
4236 return QualType();
4237
Richard Smithee579842017-01-30 20:39:26 +00004238 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4239
4240 // RebuildQualifiedType might have updated the type, but not in a way
4241 // that invalidates the TypeLoc. (There's no location information for
4242 // qualifiers.)
4243 TLB.TypeWasModifiedSafely(Result);
4244
4245 return Result;
4246}
4247
4248template<typename Derived>
4249QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4250 SourceLocation Loc,
4251 Qualifiers Quals) {
4252 // C++ [dcl.fct]p7:
4253 // [When] adding cv-qualifications on top of the function type [...] the
4254 // cv-qualifiers are ignored.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004255 if (T->isFunctionType())
4256 return T;
4257
Richard Smithee579842017-01-30 20:39:26 +00004258 // C++ [dcl.ref]p1:
4259 // when the cv-qualifiers are introduced through the use of a typedef-name
4260 // or decltype-specifier [...] the cv-qualifiers are ignored.
4261 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4262 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004263 if (T->isReferenceType()) {
4264 // The only qualifier that applies to a reference type is restrict.
4265 if (!Quals.hasRestrict())
4266 return T;
4267 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4268 }
Mike Stump11289f42009-09-09 15:08:12 +00004269
John McCall31168b02011-06-15 23:02:42 +00004270 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004271 // resulting type.
4272 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004273 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004274 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004275 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004276 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004277 // A lifetime qualifier applied to a substituted template parameter
4278 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004279 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004280 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004281 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004282 QualType Replacement = SubstTypeParam->getReplacementType();
4283 Qualifiers Qs = Replacement.getQualifiers();
4284 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004285 Replacement = SemaRef.Context.getQualifiedType(
4286 Replacement.getUnqualifiedType(), Qs);
4287 T = SemaRef.Context.getSubstTemplateTypeParmType(
4288 SubstTypeParam->getReplacedParameter(), Replacement);
4289 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004290 // 'auto' types behave the same way as template parameters.
4291 QualType Deduced = AutoTy->getDeducedType();
4292 Qualifiers Qs = Deduced.getQualifiers();
4293 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004294 Deduced =
4295 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4296 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4297 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004298 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004299 // Otherwise, complain about the addition of a qualifier to an
4300 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004301 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4302 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004303 Quals.removeObjCLifetime();
4304 }
4305 }
4306 }
John McCall550e0c22009-10-21 00:40:46 +00004307
Richard Smithee579842017-01-30 20:39:26 +00004308 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004309}
4310
Douglas Gregor14454802011-02-25 02:25:35 +00004311template<typename Derived>
4312TypeLoc
4313TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4314 QualType ObjectType,
4315 NamedDecl *UnqualLookup,
4316 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004317 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004318 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004319
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004320 TypeSourceInfo *TSI =
4321 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4322 if (TSI)
4323 return TSI->getTypeLoc();
4324 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004325}
4326
Douglas Gregor579c15f2011-03-02 18:32:08 +00004327template<typename Derived>
4328TypeSourceInfo *
4329TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4330 QualType ObjectType,
4331 NamedDecl *UnqualLookup,
4332 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004333 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004334 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004335
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004336 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4337 UnqualLookup, SS);
4338}
4339
4340template <typename Derived>
4341TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4342 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4343 CXXScopeSpec &SS) {
4344 QualType T = TL.getType();
4345 assert(!getDerived().AlreadyTransformed(T));
4346
Douglas Gregor579c15f2011-03-02 18:32:08 +00004347 TypeLocBuilder TLB;
4348 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004349
Douglas Gregor579c15f2011-03-02 18:32:08 +00004350 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004351 TemplateSpecializationTypeLoc SpecTL =
4352 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004353
Richard Smithfd3dae02017-01-20 00:20:39 +00004354 TemplateName Template = getDerived().TransformTemplateName(
4355 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4356 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004357 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004358 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004359
4360 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004361 Template);
4362 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004363 DependentTemplateSpecializationTypeLoc SpecTL =
4364 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004365
Douglas Gregor579c15f2011-03-02 18:32:08 +00004366 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004367 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004368 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004369 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004370 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004371 ObjectType, UnqualLookup,
4372 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004373 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004374 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004375
4376 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004377 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004378 Template,
4379 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004380 } else {
4381 // Nothing special needs to be done for these.
4382 Result = getDerived().TransformType(TLB, TL);
4383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004384
4385 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004386 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004387
Douglas Gregor579c15f2011-03-02 18:32:08 +00004388 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4389}
4390
John McCall550e0c22009-10-21 00:40:46 +00004391template <class TyLoc> static inline
4392QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4393 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4394 NewT.setNameLoc(T.getNameLoc());
4395 return T.getType();
4396}
4397
John McCall550e0c22009-10-21 00:40:46 +00004398template<typename Derived>
4399QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004400 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004401 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4402 NewT.setBuiltinLoc(T.getBuiltinLoc());
4403 if (T.needsExtraLocalData())
4404 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4405 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004406}
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregord6ff3322009-08-04 16:50:30 +00004408template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004409QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004410 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004411 // FIXME: recurse?
4412 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004413}
Mike Stump11289f42009-09-09 15:08:12 +00004414
Reid Kleckner0503a872013-12-05 01:23:43 +00004415template <typename Derived>
4416QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4417 AdjustedTypeLoc TL) {
4418 // Adjustments applied during transformation are handled elsewhere.
4419 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4420}
4421
Douglas Gregord6ff3322009-08-04 16:50:30 +00004422template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004423QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4424 DecayedTypeLoc TL) {
4425 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4426 if (OriginalType.isNull())
4427 return QualType();
4428
4429 QualType Result = TL.getType();
4430 if (getDerived().AlwaysRebuild() ||
4431 OriginalType != TL.getOriginalLoc().getType())
4432 Result = SemaRef.Context.getDecayedType(OriginalType);
4433 TLB.push<DecayedTypeLoc>(Result);
4434 // Nothing to set for DecayedTypeLoc.
4435 return Result;
4436}
4437
4438template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004439QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004440 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004441 QualType PointeeType
4442 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004443 if (PointeeType.isNull())
4444 return QualType();
4445
4446 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004447 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004448 // A dependent pointer type 'T *' has is being transformed such
4449 // that an Objective-C class type is being replaced for 'T'. The
4450 // resulting pointer type is an ObjCObjectPointerType, not a
4451 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004452 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004453
John McCall8b07ec22010-05-15 11:32:37 +00004454 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4455 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004456 return Result;
4457 }
John McCall31f82722010-11-12 08:19:04 +00004458
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004459 if (getDerived().AlwaysRebuild() ||
4460 PointeeType != TL.getPointeeLoc().getType()) {
4461 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4462 if (Result.isNull())
4463 return QualType();
4464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004465
John McCall31168b02011-06-15 23:02:42 +00004466 // Objective-C ARC can add lifetime qualifiers to the type that we're
4467 // pointing to.
4468 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004469
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004470 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4471 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004472 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004473}
Mike Stump11289f42009-09-09 15:08:12 +00004474
4475template<typename Derived>
4476QualType
John McCall550e0c22009-10-21 00:40:46 +00004477TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004478 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004479 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004480 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4481 if (PointeeType.isNull())
4482 return QualType();
4483
4484 QualType Result = TL.getType();
4485 if (getDerived().AlwaysRebuild() ||
4486 PointeeType != TL.getPointeeLoc().getType()) {
4487 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004488 TL.getSigilLoc());
4489 if (Result.isNull())
4490 return QualType();
4491 }
4492
Douglas Gregor049211a2010-04-22 16:50:51 +00004493 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004494 NewT.setSigilLoc(TL.getSigilLoc());
4495 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004496}
4497
John McCall70dd5f62009-10-30 00:06:24 +00004498/// Transforms a reference type. Note that somewhat paradoxically we
4499/// don't care whether the type itself is an l-value type or an r-value
4500/// type; we only care if the type was *written* as an l-value type
4501/// or an r-value type.
4502template<typename Derived>
4503QualType
4504TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004505 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004506 const ReferenceType *T = TL.getTypePtr();
4507
4508 // Note that this works with the pointee-as-written.
4509 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4510 if (PointeeType.isNull())
4511 return QualType();
4512
4513 QualType Result = TL.getType();
4514 if (getDerived().AlwaysRebuild() ||
4515 PointeeType != T->getPointeeTypeAsWritten()) {
4516 Result = getDerived().RebuildReferenceType(PointeeType,
4517 T->isSpelledAsLValue(),
4518 TL.getSigilLoc());
4519 if (Result.isNull())
4520 return QualType();
4521 }
4522
John McCall31168b02011-06-15 23:02:42 +00004523 // Objective-C ARC can add lifetime qualifiers to the type that we're
4524 // referring to.
4525 TLB.TypeWasModifiedSafely(
4526 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4527
John McCall70dd5f62009-10-30 00:06:24 +00004528 // r-value references can be rebuilt as l-value references.
4529 ReferenceTypeLoc NewTL;
4530 if (isa<LValueReferenceType>(Result))
4531 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4532 else
4533 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4534 NewTL.setSigilLoc(TL.getSigilLoc());
4535
4536 return Result;
4537}
4538
Mike Stump11289f42009-09-09 15:08:12 +00004539template<typename Derived>
4540QualType
John McCall550e0c22009-10-21 00:40:46 +00004541TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004542 LValueReferenceTypeLoc TL) {
4543 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004544}
4545
Mike Stump11289f42009-09-09 15:08:12 +00004546template<typename Derived>
4547QualType
John McCall550e0c22009-10-21 00:40:46 +00004548TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004549 RValueReferenceTypeLoc TL) {
4550 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004551}
Mike Stump11289f42009-09-09 15:08:12 +00004552
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004554QualType
John McCall550e0c22009-10-21 00:40:46 +00004555TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004556 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004557 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004558 if (PointeeType.isNull())
4559 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004560
Abramo Bagnara509357842011-03-05 14:42:21 +00004561 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004562 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004563 if (OldClsTInfo) {
4564 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4565 if (!NewClsTInfo)
4566 return QualType();
4567 }
4568
4569 const MemberPointerType *T = TL.getTypePtr();
4570 QualType OldClsType = QualType(T->getClass(), 0);
4571 QualType NewClsType;
4572 if (NewClsTInfo)
4573 NewClsType = NewClsTInfo->getType();
4574 else {
4575 NewClsType = getDerived().TransformType(OldClsType);
4576 if (NewClsType.isNull())
4577 return QualType();
4578 }
Mike Stump11289f42009-09-09 15:08:12 +00004579
John McCall550e0c22009-10-21 00:40:46 +00004580 QualType Result = TL.getType();
4581 if (getDerived().AlwaysRebuild() ||
4582 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004583 NewClsType != OldClsType) {
4584 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004585 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004586 if (Result.isNull())
4587 return QualType();
4588 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004589
Reid Kleckner0503a872013-12-05 01:23:43 +00004590 // If we had to adjust the pointee type when building a member pointer, make
4591 // sure to push TypeLoc info for it.
4592 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4593 if (MPT && PointeeType != MPT->getPointeeType()) {
4594 assert(isa<AdjustedType>(MPT->getPointeeType()));
4595 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4596 }
4597
John McCall550e0c22009-10-21 00:40:46 +00004598 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4599 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004600 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004601
4602 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004603}
4604
Mike Stump11289f42009-09-09 15:08:12 +00004605template<typename Derived>
4606QualType
John McCall550e0c22009-10-21 00:40:46 +00004607TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004608 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004609 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004610 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004611 if (ElementType.isNull())
4612 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004613
John McCall550e0c22009-10-21 00:40:46 +00004614 QualType Result = TL.getType();
4615 if (getDerived().AlwaysRebuild() ||
4616 ElementType != T->getElementType()) {
4617 Result = getDerived().RebuildConstantArrayType(ElementType,
4618 T->getSizeModifier(),
4619 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004620 T->getIndexTypeCVRQualifiers(),
4621 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004622 if (Result.isNull())
4623 return QualType();
4624 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004625
4626 // We might have either a ConstantArrayType or a VariableArrayType now:
4627 // a ConstantArrayType is allowed to have an element type which is a
4628 // VariableArrayType if the type is dependent. Fortunately, all array
4629 // types have the same location layout.
4630 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004631 NewTL.setLBracketLoc(TL.getLBracketLoc());
4632 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004633
John McCall550e0c22009-10-21 00:40:46 +00004634 Expr *Size = TL.getSizeExpr();
4635 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004636 EnterExpressionEvaluationContext Unevaluated(
4637 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004638 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4639 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004640 }
4641 NewTL.setSizeExpr(Size);
4642
4643 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004644}
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregord6ff3322009-08-04 16:50:30 +00004646template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004647QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004648 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004649 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004650 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004651 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652 if (ElementType.isNull())
4653 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004654
John McCall550e0c22009-10-21 00:40:46 +00004655 QualType Result = TL.getType();
4656 if (getDerived().AlwaysRebuild() ||
4657 ElementType != T->getElementType()) {
4658 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004659 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004660 T->getIndexTypeCVRQualifiers(),
4661 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004662 if (Result.isNull())
4663 return QualType();
4664 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004665
John McCall550e0c22009-10-21 00:40:46 +00004666 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4667 NewTL.setLBracketLoc(TL.getLBracketLoc());
4668 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004669 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004670
4671 return Result;
4672}
4673
4674template<typename Derived>
4675QualType
4676TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004677 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004678 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004679 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4680 if (ElementType.isNull())
4681 return QualType();
4682
Tim Shenb34d0ef2017-02-14 23:46:37 +00004683 ExprResult SizeResult;
4684 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004685 EnterExpressionEvaluationContext Context(
4686 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004687 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4688 }
4689 if (SizeResult.isInvalid())
4690 return QualType();
4691 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004692 if (SizeResult.isInvalid())
4693 return QualType();
4694
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004695 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004696
4697 QualType Result = TL.getType();
4698 if (getDerived().AlwaysRebuild() ||
4699 ElementType != T->getElementType() ||
4700 Size != T->getSizeExpr()) {
4701 Result = getDerived().RebuildVariableArrayType(ElementType,
4702 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004703 Size,
John McCall550e0c22009-10-21 00:40:46 +00004704 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004705 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004706 if (Result.isNull())
4707 return QualType();
4708 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004709
Serge Pavlov774c6d02014-02-06 03:49:11 +00004710 // We might have constant size array now, but fortunately it has the same
4711 // location layout.
4712 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004713 NewTL.setLBracketLoc(TL.getLBracketLoc());
4714 NewTL.setRBracketLoc(TL.getRBracketLoc());
4715 NewTL.setSizeExpr(Size);
4716
4717 return Result;
4718}
4719
4720template<typename Derived>
4721QualType
4722TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004723 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004724 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004725 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4726 if (ElementType.isNull())
4727 return QualType();
4728
Richard Smith764d2fe2011-12-20 02:08:33 +00004729 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004730 EnterExpressionEvaluationContext Unevaluated(
4731 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004732
John McCall33ddac02011-01-19 10:06:00 +00004733 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4734 Expr *origSize = TL.getSizeExpr();
4735 if (!origSize) origSize = T->getSizeExpr();
4736
4737 ExprResult sizeResult
4738 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004739 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004740 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004741 return QualType();
4742
John McCall33ddac02011-01-19 10:06:00 +00004743 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004744
4745 QualType Result = TL.getType();
4746 if (getDerived().AlwaysRebuild() ||
4747 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004748 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004749 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4750 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004751 size,
John McCall550e0c22009-10-21 00:40:46 +00004752 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004753 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004754 if (Result.isNull())
4755 return QualType();
4756 }
John McCall550e0c22009-10-21 00:40:46 +00004757
4758 // We might have any sort of array type now, but fortunately they
4759 // all have the same location layout.
4760 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4761 NewTL.setLBracketLoc(TL.getLBracketLoc());
4762 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004763 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004764
4765 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004766}
Mike Stump11289f42009-09-09 15:08:12 +00004767
Erich Keanef702b022018-07-13 19:46:04 +00004768template <typename Derived>
4769QualType TreeTransform<Derived>::TransformDependentVectorType(
4770 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4771 const DependentVectorType *T = TL.getTypePtr();
4772 QualType ElementType = getDerived().TransformType(T->getElementType());
4773 if (ElementType.isNull())
4774 return QualType();
4775
4776 EnterExpressionEvaluationContext Unevaluated(
4777 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4778
4779 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4780 Size = SemaRef.ActOnConstantExpression(Size);
4781 if (Size.isInvalid())
4782 return QualType();
4783
4784 QualType Result = TL.getType();
4785 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4786 Size.get() != T->getSizeExpr()) {
4787 Result = getDerived().RebuildDependentVectorType(
4788 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4789 if (Result.isNull())
4790 return QualType();
4791 }
4792
4793 // Result might be dependent or not.
4794 if (isa<DependentVectorType>(Result)) {
4795 DependentVectorTypeLoc NewTL =
4796 TLB.push<DependentVectorTypeLoc>(Result);
4797 NewTL.setNameLoc(TL.getNameLoc());
4798 } else {
4799 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4800 NewTL.setNameLoc(TL.getNameLoc());
4801 }
4802
4803 return Result;
4804}
4805
Mike Stump11289f42009-09-09 15:08:12 +00004806template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004807QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004808 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004809 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004810 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004811
4812 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004813 QualType ElementType = getDerived().TransformType(T->getElementType());
4814 if (ElementType.isNull())
4815 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004816
Richard Smith764d2fe2011-12-20 02:08:33 +00004817 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004818 EnterExpressionEvaluationContext Unevaluated(
4819 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004820
John McCalldadc5752010-08-24 06:29:42 +00004821 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004822 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004823 if (Size.isInvalid())
4824 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004825
John McCall550e0c22009-10-21 00:40:46 +00004826 QualType Result = TL.getType();
4827 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004828 ElementType != T->getElementType() ||
4829 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004830 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004831 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004832 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004833 if (Result.isNull())
4834 return QualType();
4835 }
John McCall550e0c22009-10-21 00:40:46 +00004836
4837 // Result might be dependent or not.
4838 if (isa<DependentSizedExtVectorType>(Result)) {
4839 DependentSizedExtVectorTypeLoc NewTL
4840 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4841 NewTL.setNameLoc(TL.getNameLoc());
4842 } else {
4843 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4844 NewTL.setNameLoc(TL.getNameLoc());
4845 }
4846
4847 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004848}
Mike Stump11289f42009-09-09 15:08:12 +00004849
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004850template <typename Derived>
4851QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4852 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4853 const DependentAddressSpaceType *T = TL.getTypePtr();
4854
4855 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4856
4857 if (pointeeType.isNull())
4858 return QualType();
4859
4860 // Address spaces are constant expressions.
4861 EnterExpressionEvaluationContext Unevaluated(
4862 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4863
4864 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4865 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4866 if (AddrSpace.isInvalid())
4867 return QualType();
4868
4869 QualType Result = TL.getType();
4870 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4871 AddrSpace.get() != T->getAddrSpaceExpr()) {
4872 Result = getDerived().RebuildDependentAddressSpaceType(
4873 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4874 if (Result.isNull())
4875 return QualType();
4876 }
4877
4878 // Result might be dependent or not.
4879 if (isa<DependentAddressSpaceType>(Result)) {
4880 DependentAddressSpaceTypeLoc NewTL =
4881 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4882
4883 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4884 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4885 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4886
4887 } else {
4888 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4889 Result, getDerived().getBaseLocation());
4890 TransformType(TLB, DI->getTypeLoc());
4891 }
4892
4893 return Result;
4894}
4895
4896template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004897QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004898 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004899 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004900 QualType ElementType = getDerived().TransformType(T->getElementType());
4901 if (ElementType.isNull())
4902 return QualType();
4903
John McCall550e0c22009-10-21 00:40:46 +00004904 QualType Result = TL.getType();
4905 if (getDerived().AlwaysRebuild() ||
4906 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004907 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004908 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004909 if (Result.isNull())
4910 return QualType();
4911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004912
John McCall550e0c22009-10-21 00:40:46 +00004913 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4914 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004915
John McCall550e0c22009-10-21 00:40:46 +00004916 return Result;
4917}
4918
4919template<typename Derived>
4920QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004921 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004922 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004923 QualType ElementType = getDerived().TransformType(T->getElementType());
4924 if (ElementType.isNull())
4925 return QualType();
4926
4927 QualType Result = TL.getType();
4928 if (getDerived().AlwaysRebuild() ||
4929 ElementType != T->getElementType()) {
4930 Result = getDerived().RebuildExtVectorType(ElementType,
4931 T->getNumElements(),
4932 /*FIXME*/ SourceLocation());
4933 if (Result.isNull())
4934 return QualType();
4935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004936
John McCall550e0c22009-10-21 00:40:46 +00004937 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4938 NewTL.setNameLoc(TL.getNameLoc());
4939
4940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004941}
Mike Stump11289f42009-09-09 15:08:12 +00004942
David Blaikie05785d12013-02-20 22:23:23 +00004943template <typename Derived>
4944ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4945 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4946 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004947 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004948 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
Douglas Gregor715e4612011-01-14 22:40:04 +00004950 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004951 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004952 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004953 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004954 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004955
Douglas Gregor715e4612011-01-14 22:40:04 +00004956 TypeLocBuilder TLB;
4957 TypeLoc NewTL = OldDI->getTypeLoc();
4958 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004959
4960 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004961 OldExpansionTL.getPatternLoc());
4962 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004963 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004964
4965 Result = RebuildPackExpansionType(Result,
4966 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004967 OldExpansionTL.getEllipsisLoc(),
4968 NumExpansions);
4969 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004970 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004971
Douglas Gregor715e4612011-01-14 22:40:04 +00004972 PackExpansionTypeLoc NewExpansionTL
4973 = TLB.push<PackExpansionTypeLoc>(Result);
4974 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4975 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4976 } else
4977 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004978 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004979 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004980
John McCall8fb0d9d2011-05-01 22:35:37 +00004981 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004982 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004983
4984 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4985 OldParm->getDeclContext(),
4986 OldParm->getInnerLocStart(),
4987 OldParm->getLocation(),
4988 OldParm->getIdentifier(),
4989 NewDI->getType(),
4990 NewDI,
4991 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004992 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004993 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4994 OldParm->getFunctionScopeIndex() + indexAdjustment);
4995 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004996}
4997
David Majnemer59f77922016-06-24 04:05:48 +00004998template <typename Derived>
4999bool TreeTransform<Derived>::TransformFunctionTypeParams(
5000 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5001 const QualType *ParamTypes,
5002 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5003 SmallVectorImpl<QualType> &OutParamTypes,
5004 SmallVectorImpl<ParmVarDecl *> *PVars,
5005 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005006 int indexAdjustment = 0;
5007
David Majnemer59f77922016-06-24 04:05:48 +00005008 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005009 for (unsigned i = 0; i != NumParams; ++i) {
5010 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005011 assert(OldParm->getFunctionScopeIndex() == i);
5012
David Blaikie05785d12013-02-20 22:23:23 +00005013 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005014 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005015 if (OldParm->isParameterPack()) {
5016 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005017 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005018
Douglas Gregor5499af42011-01-05 23:12:31 +00005019 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005020 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005021 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005022 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5023 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005024 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5025
Douglas Gregor5499af42011-01-05 23:12:31 +00005026 // Determine whether we should expand the parameter packs.
5027 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005028 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005029 Optional<unsigned> OrigNumExpansions =
5030 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005031 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005032 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5033 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005034 Unexpanded,
5035 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005036 RetainExpansion,
5037 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005038 return true;
5039 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005040
Douglas Gregor5499af42011-01-05 23:12:31 +00005041 if (ShouldExpand) {
5042 // Expand the function parameter pack into multiple, separate
5043 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005044 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005045 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005046 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005047 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005048 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005049 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005050 OrigNumExpansions,
5051 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +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 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005061
5062 // If we're supposed to retain a pack expansion, do so by temporarily
5063 // forgetting the partially-substituted parameter pack.
5064 if (RetainExpansion) {
5065 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005066 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005067 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005068 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005069 OrigNumExpansions,
5070 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005071 if (!NewParm)
5072 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005073
John McCallc8e321d2016-03-01 02:09:25 +00005074 if (ParamInfos)
5075 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005076 OutParamTypes.push_back(NewParm->getType());
5077 if (PVars)
5078 PVars->push_back(NewParm);
5079 }
5080
John McCall8fb0d9d2011-05-01 22:35:37 +00005081 // The next parameter should have the same adjustment as the
5082 // last thing we pushed, but we post-incremented indexAdjustment
5083 // on every push. Also, if we push nothing, the adjustment should
5084 // go down by one.
5085 indexAdjustment--;
5086
Douglas Gregor5499af42011-01-05 23:12:31 +00005087 // We're done with the pack expansion.
5088 continue;
5089 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005090
5091 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005092 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005093 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5094 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005095 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005096 NumExpansions,
5097 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005098 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005099 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005100 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005101 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005102
John McCall58f10c32010-03-11 09:03:00 +00005103 if (!NewParm)
5104 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005105
John McCallc8e321d2016-03-01 02:09:25 +00005106 if (ParamInfos)
5107 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005108 OutParamTypes.push_back(NewParm->getType());
5109 if (PVars)
5110 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005111 continue;
5112 }
John McCall58f10c32010-03-11 09:03:00 +00005113
5114 // Deal with the possibility that we don't have a parameter
5115 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005116 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005117 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005118 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005119 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005120 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005121 = dyn_cast<PackExpansionType>(OldType)) {
5122 // We have a function parameter pack that may need to be expanded.
5123 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005124 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005125 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005126
Douglas Gregor5499af42011-01-05 23:12:31 +00005127 // Determine whether we should expand the parameter packs.
5128 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005129 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005130 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005131 Unexpanded,
5132 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005133 RetainExpansion,
5134 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005135 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005137
Douglas Gregor5499af42011-01-05 23:12:31 +00005138 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005139 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005140 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005141 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005142 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5143 QualType NewType = getDerived().TransformType(Pattern);
5144 if (NewType.isNull())
5145 return true;
John McCall58f10c32010-03-11 09:03:00 +00005146
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005147 if (NewType->containsUnexpandedParameterPack()) {
5148 NewType =
5149 getSema().getASTContext().getPackExpansionType(NewType, None);
5150
5151 if (NewType.isNull())
5152 return true;
5153 }
5154
John McCallc8e321d2016-03-01 02:09:25 +00005155 if (ParamInfos)
5156 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005157 OutParamTypes.push_back(NewType);
5158 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005159 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005160 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005161
Douglas Gregor5499af42011-01-05 23:12:31 +00005162 // We're done with the pack expansion.
5163 continue;
5164 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005165
Douglas Gregor48d24112011-01-10 20:53:55 +00005166 // If we're supposed to retain a pack expansion, do so by temporarily
5167 // forgetting the partially-substituted parameter pack.
5168 if (RetainExpansion) {
5169 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5170 QualType NewType = getDerived().TransformType(Pattern);
5171 if (NewType.isNull())
5172 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005173
John McCallc8e321d2016-03-01 02:09:25 +00005174 if (ParamInfos)
5175 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005176 OutParamTypes.push_back(NewType);
5177 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005178 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005179 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005180
Chad Rosier1dcde962012-08-08 18:46:20 +00005181 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005182 // expansion.
5183 OldType = Expansion->getPattern();
5184 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005185 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5186 NewType = getDerived().TransformType(OldType);
5187 } else {
5188 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
Douglas Gregor5499af42011-01-05 23:12:31 +00005191 if (NewType.isNull())
5192 return true;
5193
5194 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005195 NewType = getSema().Context.getPackExpansionType(NewType,
5196 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005197
John McCallc8e321d2016-03-01 02:09:25 +00005198 if (ParamInfos)
5199 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005200 OutParamTypes.push_back(NewType);
5201 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005202 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005203 }
5204
John McCall8fb0d9d2011-05-01 22:35:37 +00005205#ifndef NDEBUG
5206 if (PVars) {
5207 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5208 if (ParmVarDecl *parm = (*PVars)[i])
5209 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005210 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005211#endif
5212
5213 return false;
5214}
John McCall58f10c32010-03-11 09:03:00 +00005215
5216template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005217QualType
John McCall550e0c22009-10-21 00:40:46 +00005218TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005219 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005220 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005221 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005222 return getDerived().TransformFunctionProtoType(
5223 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005224 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5225 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5226 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005227 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005228}
5229
Richard Smith2e321552014-11-12 02:00:47 +00005230template<typename Derived> template<typename Fn>
5231QualType TreeTransform<Derived>::TransformFunctionProtoType(
5232 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5233 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005234
Douglas Gregor4afc2362010-08-31 00:26:14 +00005235 // Transform the parameters and return type.
5236 //
Richard Smithf623c962012-04-17 00:58:00 +00005237 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005238 // When the function has a trailing return type, we instantiate the
5239 // parameters before the return type, since the return type can then refer
5240 // to the parameters themselves (via decltype, sizeof, etc.).
5241 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005242 SmallVector<QualType, 4> ParamTypes;
5243 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005244 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005245 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005246
Douglas Gregor7fb25412010-10-01 18:44:50 +00005247 QualType ResultType;
5248
Richard Smith1226c602012-08-14 22:51:13 +00005249 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005250 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005251 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005252 TL.getTypePtr()->param_type_begin(),
5253 T->getExtParameterInfosOrNull(),
5254 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005255 return QualType();
5256
Douglas Gregor3024f072012-04-16 07:05:22 +00005257 {
5258 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005259 // If a declaration declares a member function or member function
5260 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005261 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005262 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005263 // declarator.
5264 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005265
Alp Toker42a16a62014-01-25 23:51:36 +00005266 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005267 if (ResultType.isNull())
5268 return QualType();
5269 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005270 }
5271 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005272 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005273 if (ResultType.isNull())
5274 return QualType();
5275
Alp Toker9cacbab2014-01-20 20:26:09 +00005276 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005277 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005278 TL.getTypePtr()->param_type_begin(),
5279 T->getExtParameterInfosOrNull(),
5280 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005281 return QualType();
5282 }
5283
Richard Smith2e321552014-11-12 02:00:47 +00005284 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5285
5286 bool EPIChanged = false;
5287 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5288 return QualType();
5289
John McCallc8e321d2016-03-01 02:09:25 +00005290 // Handle extended parameter information.
5291 if (auto NewExtParamInfos =
5292 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5293 if (!EPI.ExtParameterInfos ||
5294 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5295 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5296 EPIChanged = true;
5297 }
5298 EPI.ExtParameterInfos = NewExtParamInfos;
5299 } else if (EPI.ExtParameterInfos) {
5300 EPIChanged = true;
5301 EPI.ExtParameterInfos = nullptr;
5302 }
Richard Smithf623c962012-04-17 00:58:00 +00005303
John McCall550e0c22009-10-21 00:40:46 +00005304 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005305 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005306 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005307 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005308 if (Result.isNull())
5309 return QualType();
5310 }
Mike Stump11289f42009-09-09 15:08:12 +00005311
John McCall550e0c22009-10-21 00:40:46 +00005312 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005313 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005314 NewTL.setLParenLoc(TL.getLParenLoc());
5315 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005316 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005317 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005318 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5319 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005320
5321 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005322}
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregord6ff3322009-08-04 16:50:30 +00005324template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005325bool TreeTransform<Derived>::TransformExceptionSpec(
5326 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5327 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5328 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5329
5330 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005331 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005332 EnterExpressionEvaluationContext Unevaluated(
5333 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005334 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5335 if (NoexceptExpr.isInvalid())
5336 return true;
5337
Richard Smitheaf11ad2018-05-03 03:58:32 +00005338 ExceptionSpecificationType EST = ESI.Type;
5339 NoexceptExpr =
5340 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005341 if (NoexceptExpr.isInvalid())
5342 return true;
5343
Richard Smitheaf11ad2018-05-03 03:58:32 +00005344 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005345 Changed = true;
5346 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005347 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005348 }
5349
5350 if (ESI.Type != EST_Dynamic)
5351 return false;
5352
5353 // Instantiate a dynamic exception specification's type.
5354 for (QualType T : ESI.Exceptions) {
5355 if (const PackExpansionType *PackExpansion =
5356 T->getAs<PackExpansionType>()) {
5357 Changed = true;
5358
5359 // We have a pack expansion. Instantiate it.
5360 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5361 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5362 Unexpanded);
5363 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5364
5365 // Determine whether the set of unexpanded parameter packs can and
5366 // should
5367 // be expanded.
5368 bool Expand = false;
5369 bool RetainExpansion = false;
5370 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5371 // FIXME: Track the location of the ellipsis (and track source location
5372 // information for the types in the exception specification in general).
5373 if (getDerived().TryExpandParameterPacks(
5374 Loc, SourceRange(), Unexpanded, Expand,
5375 RetainExpansion, NumExpansions))
5376 return true;
5377
5378 if (!Expand) {
5379 // We can't expand this pack expansion into separate arguments yet;
5380 // just substitute into the pattern and create a new pack expansion
5381 // type.
5382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5383 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5384 if (U.isNull())
5385 return true;
5386
5387 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5388 Exceptions.push_back(U);
5389 continue;
5390 }
5391
5392 // Substitute into the pack expansion pattern for each slice of the
5393 // pack.
5394 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5395 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5396
5397 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5398 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5399 return true;
5400
5401 Exceptions.push_back(U);
5402 }
5403 } else {
5404 QualType U = getDerived().TransformType(T);
5405 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5406 return true;
5407 if (T != U)
5408 Changed = true;
5409
5410 Exceptions.push_back(U);
5411 }
5412 }
5413
5414 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005415 if (ESI.Exceptions.empty())
5416 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005417 return false;
5418}
5419
5420template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005421QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005422 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005423 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005424 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005425 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005426 if (ResultType.isNull())
5427 return QualType();
5428
5429 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005430 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005431 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5432
5433 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005434 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005435 NewTL.setLParenLoc(TL.getLParenLoc());
5436 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005437 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005438
5439 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005440}
Mike Stump11289f42009-09-09 15:08:12 +00005441
John McCallb96ec562009-12-04 22:46:56 +00005442template<typename Derived> QualType
5443TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005444 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005445 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005446 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005447 if (!D)
5448 return QualType();
5449
5450 QualType Result = TL.getType();
5451 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005452 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005453 if (Result.isNull())
5454 return QualType();
5455 }
5456
5457 // We might get an arbitrary type spec type back. We should at
5458 // least always get a type spec type, though.
5459 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5460 NewTL.setNameLoc(TL.getNameLoc());
5461
5462 return Result;
5463}
5464
Douglas Gregord6ff3322009-08-04 16:50:30 +00005465template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005466QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005467 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005468 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005469 TypedefNameDecl *Typedef
5470 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5471 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005472 if (!Typedef)
5473 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005474
John McCall550e0c22009-10-21 00:40:46 +00005475 QualType Result = TL.getType();
5476 if (getDerived().AlwaysRebuild() ||
5477 Typedef != T->getDecl()) {
5478 Result = getDerived().RebuildTypedefType(Typedef);
5479 if (Result.isNull())
5480 return QualType();
5481 }
Mike Stump11289f42009-09-09 15:08:12 +00005482
John McCall550e0c22009-10-21 00:40:46 +00005483 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5484 NewTL.setNameLoc(TL.getNameLoc());
5485
5486 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005487}
Mike Stump11289f42009-09-09 15:08:12 +00005488
Douglas Gregord6ff3322009-08-04 16:50:30 +00005489template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005490QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005491 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005492 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005493 EnterExpressionEvaluationContext Unevaluated(
5494 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5495 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005496
John McCalldadc5752010-08-24 06:29:42 +00005497 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005498 if (E.isInvalid())
5499 return QualType();
5500
Eli Friedmane4f22df2012-02-29 04:03:55 +00005501 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5502 if (E.isInvalid())
5503 return QualType();
5504
John McCall550e0c22009-10-21 00:40:46 +00005505 QualType Result = TL.getType();
5506 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005507 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005508 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005509 if (Result.isNull())
5510 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005511 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005512 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005513
John McCall550e0c22009-10-21 00:40:46 +00005514 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005515 NewTL.setTypeofLoc(TL.getTypeofLoc());
5516 NewTL.setLParenLoc(TL.getLParenLoc());
5517 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005518
5519 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005520}
Mike Stump11289f42009-09-09 15:08:12 +00005521
5522template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005523QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005524 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005525 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5526 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5527 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005528 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005529
John McCall550e0c22009-10-21 00:40:46 +00005530 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005531 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5532 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005533 if (Result.isNull())
5534 return QualType();
5535 }
Mike Stump11289f42009-09-09 15:08:12 +00005536
John McCall550e0c22009-10-21 00:40:46 +00005537 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005538 NewTL.setTypeofLoc(TL.getTypeofLoc());
5539 NewTL.setLParenLoc(TL.getLParenLoc());
5540 NewTL.setRParenLoc(TL.getRParenLoc());
5541 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005542
5543 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005544}
Mike Stump11289f42009-09-09 15:08:12 +00005545
5546template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005547QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005548 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005549 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005550
Douglas Gregore922c772009-08-04 22:27:00 +00005551 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005552 EnterExpressionEvaluationContext Unevaluated(
5553 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005554 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005555
John McCalldadc5752010-08-24 06:29:42 +00005556 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005557 if (E.isInvalid())
5558 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005559
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005560 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005561 if (E.isInvalid())
5562 return QualType();
5563
John McCall550e0c22009-10-21 00:40:46 +00005564 QualType Result = TL.getType();
5565 if (getDerived().AlwaysRebuild() ||
5566 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005567 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005568 if (Result.isNull())
5569 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005570 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005571 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005572
John McCall550e0c22009-10-21 00:40:46 +00005573 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5574 NewTL.setNameLoc(TL.getNameLoc());
5575
5576 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005577}
5578
5579template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005580QualType TreeTransform<Derived>::TransformUnaryTransformType(
5581 TypeLocBuilder &TLB,
5582 UnaryTransformTypeLoc TL) {
5583 QualType Result = TL.getType();
5584 if (Result->isDependentType()) {
5585 const UnaryTransformType *T = TL.getTypePtr();
5586 QualType NewBase =
5587 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5588 Result = getDerived().RebuildUnaryTransformType(NewBase,
5589 T->getUTTKind(),
5590 TL.getKWLoc());
5591 if (Result.isNull())
5592 return QualType();
5593 }
5594
5595 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5596 NewTL.setKWLoc(TL.getKWLoc());
5597 NewTL.setParensRange(TL.getParensRange());
5598 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5599 return Result;
5600}
5601
5602template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005603QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5604 AutoTypeLoc TL) {
5605 const AutoType *T = TL.getTypePtr();
5606 QualType OldDeduced = T->getDeducedType();
5607 QualType NewDeduced;
5608 if (!OldDeduced.isNull()) {
5609 NewDeduced = getDerived().TransformType(OldDeduced);
5610 if (NewDeduced.isNull())
5611 return QualType();
5612 }
5613
5614 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005615 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5616 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005617 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005618 if (Result.isNull())
5619 return QualType();
5620 }
5621
5622 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5623 NewTL.setNameLoc(TL.getNameLoc());
5624
5625 return Result;
5626}
5627
5628template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005629QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5630 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5631 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5632
5633 CXXScopeSpec SS;
5634 TemplateName TemplateName = getDerived().TransformTemplateName(
5635 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5636 if (TemplateName.isNull())
5637 return QualType();
5638
5639 QualType OldDeduced = T->getDeducedType();
5640 QualType NewDeduced;
5641 if (!OldDeduced.isNull()) {
5642 NewDeduced = getDerived().TransformType(OldDeduced);
5643 if (NewDeduced.isNull())
5644 return QualType();
5645 }
5646
5647 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5648 TemplateName, NewDeduced);
5649 if (Result.isNull())
5650 return QualType();
5651
5652 DeducedTemplateSpecializationTypeLoc NewTL =
5653 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5654 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5655
5656 return Result;
5657}
5658
5659template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005660QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005661 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005662 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005663 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005664 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5665 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005666 if (!Record)
5667 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005668
John McCall550e0c22009-10-21 00:40:46 +00005669 QualType Result = TL.getType();
5670 if (getDerived().AlwaysRebuild() ||
5671 Record != T->getDecl()) {
5672 Result = getDerived().RebuildRecordType(Record);
5673 if (Result.isNull())
5674 return QualType();
5675 }
Mike Stump11289f42009-09-09 15:08:12 +00005676
John McCall550e0c22009-10-21 00:40:46 +00005677 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5678 NewTL.setNameLoc(TL.getNameLoc());
5679
5680 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005681}
Mike Stump11289f42009-09-09 15:08:12 +00005682
5683template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005684QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005685 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005686 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005687 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005688 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5689 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005690 if (!Enum)
5691 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005692
John McCall550e0c22009-10-21 00:40:46 +00005693 QualType Result = TL.getType();
5694 if (getDerived().AlwaysRebuild() ||
5695 Enum != T->getDecl()) {
5696 Result = getDerived().RebuildEnumType(Enum);
5697 if (Result.isNull())
5698 return QualType();
5699 }
Mike Stump11289f42009-09-09 15:08:12 +00005700
John McCall550e0c22009-10-21 00:40:46 +00005701 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5702 NewTL.setNameLoc(TL.getNameLoc());
5703
5704 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005705}
John McCallfcc33b02009-09-05 00:15:47 +00005706
John McCalle78aac42010-03-10 03:28:59 +00005707template<typename Derived>
5708QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5709 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005710 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005711 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5712 TL.getTypePtr()->getDecl());
5713 if (!D) return QualType();
5714
5715 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5716 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5717 return T;
5718}
5719
Douglas Gregord6ff3322009-08-04 16:50:30 +00005720template<typename Derived>
5721QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005722 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005723 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005724 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005725}
5726
Mike Stump11289f42009-09-09 15:08:12 +00005727template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005728QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005729 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005730 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005731 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005732
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005733 // Substitute into the replacement type, which itself might involve something
5734 // that needs to be transformed. This only tends to occur with default
5735 // template arguments of template template parameters.
5736 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5737 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5738 if (Replacement.isNull())
5739 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005740
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005741 // Always canonicalize the replacement type.
5742 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5743 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005744 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005745 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005746
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005747 // Propagate type-source information.
5748 SubstTemplateTypeParmTypeLoc NewTL
5749 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5750 NewTL.setNameLoc(TL.getNameLoc());
5751 return Result;
5752
John McCallcebee162009-10-18 09:09:24 +00005753}
5754
5755template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005756QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5757 TypeLocBuilder &TLB,
5758 SubstTemplateTypeParmPackTypeLoc TL) {
5759 return TransformTypeSpecType(TLB, TL);
5760}
5761
5762template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005763QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005764 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005765 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005766 const TemplateSpecializationType *T = TL.getTypePtr();
5767
Douglas Gregordf846d12011-03-02 18:46:51 +00005768 // The nested-name-specifier never matters in a TemplateSpecializationType,
5769 // because we can't have a dependent nested-name-specifier anyway.
5770 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005771 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005772 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5773 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005774 if (Template.isNull())
5775 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005776
John McCall31f82722010-11-12 08:19:04 +00005777 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5778}
5779
Eli Friedman0dfb8892011-10-06 23:00:33 +00005780template<typename Derived>
5781QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5782 AtomicTypeLoc TL) {
5783 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5784 if (ValueType.isNull())
5785 return QualType();
5786
5787 QualType Result = TL.getType();
5788 if (getDerived().AlwaysRebuild() ||
5789 ValueType != TL.getValueLoc().getType()) {
5790 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5791 if (Result.isNull())
5792 return QualType();
5793 }
5794
5795 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5796 NewTL.setKWLoc(TL.getKWLoc());
5797 NewTL.setLParenLoc(TL.getLParenLoc());
5798 NewTL.setRParenLoc(TL.getRParenLoc());
5799
5800 return Result;
5801}
5802
Xiuli Pan9c14e282016-01-09 12:53:17 +00005803template <typename Derived>
5804QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5805 PipeTypeLoc TL) {
5806 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5807 if (ValueType.isNull())
5808 return QualType();
5809
5810 QualType Result = TL.getType();
5811 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005812 const PipeType *PT = Result->getAs<PipeType>();
5813 bool isReadPipe = PT->isReadOnly();
5814 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005815 if (Result.isNull())
5816 return QualType();
5817 }
5818
5819 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5820 NewTL.setKWLoc(TL.getKWLoc());
5821
5822 return Result;
5823}
5824
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005825 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005826 /// container that provides a \c getArgLoc() member function.
5827 ///
5828 /// This iterator is intended to be used with the iterator form of
5829 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5830 template<typename ArgLocContainer>
5831 class TemplateArgumentLocContainerIterator {
5832 ArgLocContainer *Container;
5833 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005834
Douglas Gregorfe921a72010-12-20 23:36:19 +00005835 public:
5836 typedef TemplateArgumentLoc value_type;
5837 typedef TemplateArgumentLoc reference;
5838 typedef int difference_type;
5839 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005840
Douglas Gregorfe921a72010-12-20 23:36:19 +00005841 class pointer {
5842 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005843
Douglas Gregorfe921a72010-12-20 23:36:19 +00005844 public:
5845 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005846
Douglas Gregorfe921a72010-12-20 23:36:19 +00005847 const TemplateArgumentLoc *operator->() const {
5848 return &Arg;
5849 }
5850 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005851
5852
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005853 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005854
Douglas Gregorfe921a72010-12-20 23:36:19 +00005855 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5856 unsigned Index)
5857 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Douglas Gregorfe921a72010-12-20 23:36:19 +00005859 TemplateArgumentLocContainerIterator &operator++() {
5860 ++Index;
5861 return *this;
5862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Douglas Gregorfe921a72010-12-20 23:36:19 +00005864 TemplateArgumentLocContainerIterator operator++(int) {
5865 TemplateArgumentLocContainerIterator Old(*this);
5866 ++(*this);
5867 return Old;
5868 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005869
Douglas Gregorfe921a72010-12-20 23:36:19 +00005870 TemplateArgumentLoc operator*() const {
5871 return Container->getArgLoc(Index);
5872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005873
Douglas Gregorfe921a72010-12-20 23:36:19 +00005874 pointer operator->() const {
5875 return pointer(Container->getArgLoc(Index));
5876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005877
Douglas Gregorfe921a72010-12-20 23:36:19 +00005878 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005879 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005880 return X.Container == Y.Container && X.Index == Y.Index;
5881 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
Douglas Gregorfe921a72010-12-20 23:36:19 +00005883 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005884 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005885 return !(X == Y);
5886 }
5887 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005888
5889
John McCall31f82722010-11-12 08:19:04 +00005890template <typename Derived>
5891QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5892 TypeLocBuilder &TLB,
5893 TemplateSpecializationTypeLoc TL,
5894 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005895 TemplateArgumentListInfo NewTemplateArgs;
5896 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5897 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005898 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5899 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005900 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005901 ArgIterator(TL, TL.getNumArgs()),
5902 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005903 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005904
John McCall0ad16662009-10-29 08:12:44 +00005905 // FIXME: maybe don't rebuild if all the template arguments are the same.
5906
5907 QualType Result =
5908 getDerived().RebuildTemplateSpecializationType(Template,
5909 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005910 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005911
5912 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005913 // Specializations of template template parameters are represented as
5914 // TemplateSpecializationTypes, and substitution of type alias templates
5915 // within a dependent context can transform them into
5916 // DependentTemplateSpecializationTypes.
5917 if (isa<DependentTemplateSpecializationType>(Result)) {
5918 DependentTemplateSpecializationTypeLoc NewTL
5919 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005920 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005921 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005922 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005923 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005924 NewTL.setLAngleLoc(TL.getLAngleLoc());
5925 NewTL.setRAngleLoc(TL.getRAngleLoc());
5926 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5927 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5928 return Result;
5929 }
5930
John McCall0ad16662009-10-29 08:12:44 +00005931 TemplateSpecializationTypeLoc NewTL
5932 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005933 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005934 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5935 NewTL.setLAngleLoc(TL.getLAngleLoc());
5936 NewTL.setRAngleLoc(TL.getRAngleLoc());
5937 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5938 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005939 }
Mike Stump11289f42009-09-09 15:08:12 +00005940
John McCall0ad16662009-10-29 08:12:44 +00005941 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005942}
Mike Stump11289f42009-09-09 15:08:12 +00005943
Douglas Gregor5a064722011-02-28 17:23:35 +00005944template <typename Derived>
5945QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5946 TypeLocBuilder &TLB,
5947 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005948 TemplateName Template,
5949 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005950 TemplateArgumentListInfo NewTemplateArgs;
5951 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5952 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5953 typedef TemplateArgumentLocContainerIterator<
5954 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005955 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005956 ArgIterator(TL, TL.getNumArgs()),
5957 NewTemplateArgs))
5958 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
Douglas Gregor5a064722011-02-28 17:23:35 +00005960 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005961
Douglas Gregor5a064722011-02-28 17:23:35 +00005962 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5963 QualType Result
5964 = getSema().Context.getDependentTemplateSpecializationType(
5965 TL.getTypePtr()->getKeyword(),
5966 DTN->getQualifier(),
5967 DTN->getIdentifier(),
5968 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005969
Douglas Gregor5a064722011-02-28 17:23:35 +00005970 DependentTemplateSpecializationTypeLoc NewTL
5971 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005972 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005973 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005974 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005975 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005976 NewTL.setLAngleLoc(TL.getLAngleLoc());
5977 NewTL.setRAngleLoc(TL.getRAngleLoc());
5978 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5979 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5980 return Result;
5981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005982
5983 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005984 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005985 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005986 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005987
Douglas Gregor5a064722011-02-28 17:23:35 +00005988 if (!Result.isNull()) {
5989 /// FIXME: Wrap this in an elaborated-type-specifier?
5990 TemplateSpecializationTypeLoc NewTL
5991 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005992 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005993 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005994 NewTL.setLAngleLoc(TL.getLAngleLoc());
5995 NewTL.setRAngleLoc(TL.getRAngleLoc());
5996 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5997 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005999
Douglas Gregor5a064722011-02-28 17:23:35 +00006000 return Result;
6001}
6002
Mike Stump11289f42009-09-09 15:08:12 +00006003template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006004QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006005TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006006 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006007 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006008
Douglas Gregor844cb502011-03-01 18:12:44 +00006009 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006010 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006011 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006012 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006013 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6014 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006015 return QualType();
6016 }
Mike Stump11289f42009-09-09 15:08:12 +00006017
John McCall31f82722010-11-12 08:19:04 +00006018 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6019 if (NamedT.isNull())
6020 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006021
Richard Smith3f1b5d02011-05-05 21:57:07 +00006022 // C++0x [dcl.type.elab]p2:
6023 // If the identifier resolves to a typedef-name or the simple-template-id
6024 // resolves to an alias template specialization, the
6025 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006026 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6027 if (const TemplateSpecializationType *TST =
6028 NamedT->getAs<TemplateSpecializationType>()) {
6029 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006030 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6031 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006032 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006033 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006034 << TAT << Sema::NTK_TypeAliasTemplate
6035 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006036 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6037 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006038 }
6039 }
6040
John McCall550e0c22009-10-21 00:40:46 +00006041 QualType Result = TL.getType();
6042 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006043 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006044 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006045 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006046 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006047 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006048 if (Result.isNull())
6049 return QualType();
6050 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006051
Abramo Bagnara6150c882010-05-11 21:36:43 +00006052 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006053 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006054 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006055 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006056}
Mike Stump11289f42009-09-09 15:08:12 +00006057
6058template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006059QualType TreeTransform<Derived>::TransformAttributedType(
6060 TypeLocBuilder &TLB,
6061 AttributedTypeLoc TL) {
6062 const AttributedType *oldType = TL.getTypePtr();
6063 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6064 if (modifiedType.isNull())
6065 return QualType();
6066
Richard Smithe43e2b32018-08-20 21:47:29 +00006067 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6068 const Attr *oldAttr = TL.getAttr();
6069 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6070 if (oldAttr && !newAttr)
6071 return QualType();
6072
John McCall81904512011-01-06 01:58:22 +00006073 QualType result = TL.getType();
6074
6075 // FIXME: dependent operand expressions?
6076 if (getDerived().AlwaysRebuild() ||
6077 modifiedType != oldType->getModifiedType()) {
6078 // TODO: this is really lame; we should really be rebuilding the
6079 // equivalent type from first principles.
6080 QualType equivalentType
6081 = getDerived().TransformType(oldType->getEquivalentType());
6082 if (equivalentType.isNull())
6083 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006084
6085 // Check whether we can add nullability; it is only represented as
6086 // type sugar, and therefore cannot be diagnosed in any other way.
6087 if (auto nullability = oldType->getImmediateNullability()) {
6088 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006089 SemaRef.Diag(TL.getAttr()->getLocation(),
6090 diag::err_nullability_nonpointer)
6091 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006092 return QualType();
6093 }
6094 }
6095
Richard Smithe43e2b32018-08-20 21:47:29 +00006096 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006097 modifiedType,
6098 equivalentType);
6099 }
6100
6101 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006102 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006103 return result;
6104}
6105
6106template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006107QualType
6108TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6109 ParenTypeLoc TL) {
6110 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6111 if (Inner.isNull())
6112 return QualType();
6113
6114 QualType Result = TL.getType();
6115 if (getDerived().AlwaysRebuild() ||
6116 Inner != TL.getInnerLoc().getType()) {
6117 Result = getDerived().RebuildParenType(Inner);
6118 if (Result.isNull())
6119 return QualType();
6120 }
6121
6122 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6123 NewTL.setLParenLoc(TL.getLParenLoc());
6124 NewTL.setRParenLoc(TL.getRParenLoc());
6125 return Result;
6126}
6127
6128template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006129QualType TreeTransform<Derived>::TransformDependentNameType(
6130 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6131 return TransformDependentNameType(TLB, TL, false);
6132}
6133
6134template<typename Derived>
6135QualType TreeTransform<Derived>::TransformDependentNameType(
6136 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006137 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006138
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006139 NestedNameSpecifierLoc QualifierLoc
6140 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6141 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006142 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006143
John McCallc392f372010-06-11 00:33:02 +00006144 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006145 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006146 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006147 QualifierLoc,
6148 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006149 TL.getNameLoc(),
6150 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006151 if (Result.isNull())
6152 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006153
Abramo Bagnarad7548482010-05-19 21:37:53 +00006154 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6155 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006156 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6157
Abramo Bagnarad7548482010-05-19 21:37:53 +00006158 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006159 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006160 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006161 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006162 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006163 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006164 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006165 NewTL.setNameLoc(TL.getNameLoc());
6166 }
John McCall550e0c22009-10-21 00:40:46 +00006167 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006168}
Mike Stump11289f42009-09-09 15:08:12 +00006169
Douglas Gregord6ff3322009-08-04 16:50:30 +00006170template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006171QualType TreeTransform<Derived>::
6172 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006173 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006174 NestedNameSpecifierLoc QualifierLoc;
6175 if (TL.getQualifierLoc()) {
6176 QualifierLoc
6177 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6178 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006179 return QualType();
6180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006181
John McCall31f82722010-11-12 08:19:04 +00006182 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006183 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006184}
6185
6186template<typename Derived>
6187QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006188TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6189 DependentTemplateSpecializationTypeLoc TL,
6190 NestedNameSpecifierLoc QualifierLoc) {
6191 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006192
Douglas Gregora7a795b2011-03-01 20:11:18 +00006193 TemplateArgumentListInfo NewTemplateArgs;
6194 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6195 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006196
Douglas Gregora7a795b2011-03-01 20:11:18 +00006197 typedef TemplateArgumentLocContainerIterator<
6198 DependentTemplateSpecializationTypeLoc> ArgIterator;
6199 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6200 ArgIterator(TL, TL.getNumArgs()),
6201 NewTemplateArgs))
6202 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006203
Richard Smithfd3dae02017-01-20 00:20:39 +00006204 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006205 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6206 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006207 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006208 if (Result.isNull())
6209 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006210
Douglas Gregora7a795b2011-03-01 20:11:18 +00006211 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6212 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006213
Douglas Gregora7a795b2011-03-01 20:11:18 +00006214 // Copy information relevant to the template specialization.
6215 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006216 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006217 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006218 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006219 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6220 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006221 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006222 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006223
Douglas Gregora7a795b2011-03-01 20:11:18 +00006224 // Copy information relevant to the elaborated type.
6225 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006226 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006227 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006228 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6229 DependentTemplateSpecializationTypeLoc SpecTL
6230 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006231 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006232 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006233 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006234 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006235 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6236 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006237 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006238 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006239 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006240 TemplateSpecializationTypeLoc SpecTL
6241 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006242 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006243 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006244 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6245 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006246 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006247 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006248 }
6249 return Result;
6250}
6251
6252template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006253QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6254 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006255 QualType Pattern
6256 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006257 if (Pattern.isNull())
6258 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006259
6260 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006261 if (getDerived().AlwaysRebuild() ||
6262 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006263 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006264 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006265 TL.getEllipsisLoc(),
6266 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006267 if (Result.isNull())
6268 return QualType();
6269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006270
Douglas Gregor822d0302011-01-12 17:07:58 +00006271 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6272 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6273 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006274}
6275
6276template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006277QualType
6278TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006279 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006280 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006281 TLB.pushFullCopy(TL);
6282 return TL.getType();
6283}
6284
6285template<typename Derived>
6286QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006287TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6288 ObjCTypeParamTypeLoc TL) {
6289 const ObjCTypeParamType *T = TL.getTypePtr();
6290 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6291 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6292 if (!OTP)
6293 return QualType();
6294
6295 QualType Result = TL.getType();
6296 if (getDerived().AlwaysRebuild() ||
6297 OTP != T->getDecl()) {
6298 Result = getDerived().RebuildObjCTypeParamType(OTP,
6299 TL.getProtocolLAngleLoc(),
6300 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6301 TL.getNumProtocols()),
6302 TL.getProtocolLocs(),
6303 TL.getProtocolRAngleLoc());
6304 if (Result.isNull())
6305 return QualType();
6306 }
6307
6308 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6309 if (TL.getNumProtocols()) {
6310 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6311 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6312 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6313 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6314 }
6315 return Result;
6316}
6317
6318template<typename Derived>
6319QualType
John McCall8b07ec22010-05-15 11:32:37 +00006320TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006321 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006322 // Transform base type.
6323 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6324 if (BaseType.isNull())
6325 return QualType();
6326
6327 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6328
6329 // Transform type arguments.
6330 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6331 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6332 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6333 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6334 QualType TypeArg = TypeArgInfo->getType();
6335 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6336 AnyChanged = true;
6337
6338 // We have a pack expansion. Instantiate it.
6339 const auto *PackExpansion = PackExpansionLoc.getType()
6340 ->castAs<PackExpansionType>();
6341 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6342 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6343 Unexpanded);
6344 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6345
6346 // Determine whether the set of unexpanded parameter packs can
6347 // and should be expanded.
6348 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6349 bool Expand = false;
6350 bool RetainExpansion = false;
6351 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6352 if (getDerived().TryExpandParameterPacks(
6353 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6354 Unexpanded, Expand, RetainExpansion, NumExpansions))
6355 return QualType();
6356
6357 if (!Expand) {
6358 // We can't expand this pack expansion into separate arguments yet;
6359 // just substitute into the pattern and create a new pack expansion
6360 // type.
6361 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6362
6363 TypeLocBuilder TypeArgBuilder;
6364 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006365 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006366 PatternLoc);
6367 if (NewPatternType.isNull())
6368 return QualType();
6369
6370 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6371 NewPatternType, NumExpansions);
6372 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6373 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6374 NewTypeArgInfos.push_back(
6375 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6376 continue;
6377 }
6378
6379 // Substitute into the pack expansion pattern for each slice of the
6380 // pack.
6381 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6383
6384 TypeLocBuilder TypeArgBuilder;
6385 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6386
6387 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6388 PatternLoc);
6389 if (NewTypeArg.isNull())
6390 return QualType();
6391
6392 NewTypeArgInfos.push_back(
6393 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6394 }
6395
6396 continue;
6397 }
6398
6399 TypeLocBuilder TypeArgBuilder;
6400 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6401 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6402 if (NewTypeArg.isNull())
6403 return QualType();
6404
6405 // If nothing changed, just keep the old TypeSourceInfo.
6406 if (NewTypeArg == TypeArg) {
6407 NewTypeArgInfos.push_back(TypeArgInfo);
6408 continue;
6409 }
6410
6411 NewTypeArgInfos.push_back(
6412 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6413 AnyChanged = true;
6414 }
6415
6416 QualType Result = TL.getType();
6417 if (getDerived().AlwaysRebuild() || AnyChanged) {
6418 // Rebuild the type.
6419 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006420 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6421 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6422 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6423 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006424
6425 if (Result.isNull())
6426 return QualType();
6427 }
6428
6429 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006430 NewT.setHasBaseTypeAsWritten(true);
6431 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6432 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6433 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6434 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6435 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6436 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6437 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6438 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6439 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006440}
Mike Stump11289f42009-09-09 15:08:12 +00006441
6442template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006443QualType
6444TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006445 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006446 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6447 if (PointeeType.isNull())
6448 return QualType();
6449
6450 QualType Result = TL.getType();
6451 if (getDerived().AlwaysRebuild() ||
6452 PointeeType != TL.getPointeeLoc().getType()) {
6453 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6454 TL.getStarLoc());
6455 if (Result.isNull())
6456 return QualType();
6457 }
6458
6459 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6460 NewT.setStarLoc(TL.getStarLoc());
6461 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006462}
6463
Douglas Gregord6ff3322009-08-04 16:50:30 +00006464//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006465// Statement transformation
6466//===----------------------------------------------------------------------===//
6467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006468StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006469TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006470 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006471}
6472
6473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006474StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006475TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6476 return getDerived().TransformCompoundStmt(S, false);
6477}
6478
6479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006480StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006481TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006482 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006483 Sema::CompoundScopeRAII CompoundScope(getSema());
6484
John McCall1ababa62010-08-27 19:56:05 +00006485 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006486 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006487 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006488 for (auto *B : S->body()) {
6489 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006490 if (Result.isInvalid()) {
6491 // Immediately fail if this was a DeclStmt, since it's very
6492 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006493 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006494 return StmtError();
6495
6496 // Otherwise, just keep processing substatements and fail later.
6497 SubStmtInvalid = true;
6498 continue;
6499 }
Mike Stump11289f42009-09-09 15:08:12 +00006500
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006501 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006502 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006503 }
Mike Stump11289f42009-09-09 15:08:12 +00006504
John McCall1ababa62010-08-27 19:56:05 +00006505 if (SubStmtInvalid)
6506 return StmtError();
6507
Douglas Gregorebe10102009-08-20 07:17:43 +00006508 if (!getDerived().AlwaysRebuild() &&
6509 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006510 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006511
6512 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006513 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006514 S->getRBracLoc(),
6515 IsStmtExpr);
6516}
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregorebe10102009-08-20 07:17:43 +00006518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006519StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006520TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006521 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006522 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006523 EnterExpressionEvaluationContext Unevaluated(
6524 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006525
Eli Friedman06577382009-11-19 03:14:00 +00006526 // Transform the left-hand case value.
6527 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006528 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006529 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006530 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006531
Eli Friedman06577382009-11-19 03:14:00 +00006532 // Transform the right-hand case value (for the GNU case-range extension).
6533 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006534 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006535 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006536 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006537 }
Mike Stump11289f42009-09-09 15:08:12 +00006538
Douglas Gregorebe10102009-08-20 07:17:43 +00006539 // Build the case statement.
6540 // Case statements are always rebuilt so that they will attached to their
6541 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006542 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006543 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006544 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006545 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006546 S->getColonLoc());
6547 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006549
Douglas Gregorebe10102009-08-20 07:17:43 +00006550 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006551 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006552 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006553 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006554
Douglas Gregorebe10102009-08-20 07:17:43 +00006555 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006556 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006557}
6558
6559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006561TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006562 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006563 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006564 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006565 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006566
Douglas Gregorebe10102009-08-20 07:17:43 +00006567 // Default statements are always rebuilt
6568 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006569 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006570}
Mike Stump11289f42009-09-09 15:08:12 +00006571
Douglas Gregorebe10102009-08-20 07:17:43 +00006572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006573StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006574TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006575 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006576 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006577 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006578
Chris Lattnercab02a62011-02-17 20:34:02 +00006579 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6580 S->getDecl());
6581 if (!LD)
6582 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006583
6584
Douglas Gregorebe10102009-08-20 07:17:43 +00006585 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006586 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006587 cast<LabelDecl>(LD), SourceLocation(),
6588 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006589}
Mike Stump11289f42009-09-09 15:08:12 +00006590
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006591template <typename Derived>
6592const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6593 if (!R)
6594 return R;
6595
6596 switch (R->getKind()) {
6597// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6598#define ATTR(X)
6599#define PRAGMA_SPELLING_ATTR(X) \
6600 case attr::X: \
6601 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6602#include "clang/Basic/AttrList.inc"
6603 default:
6604 return R;
6605 }
6606}
6607
6608template <typename Derived>
6609StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6610 bool AttrsChanged = false;
6611 SmallVector<const Attr *, 1> Attrs;
6612
6613 // Visit attributes and keep track if any are transformed.
6614 for (const auto *I : S->getAttrs()) {
6615 const Attr *R = getDerived().TransformAttr(I);
6616 AttrsChanged |= (I != R);
6617 Attrs.push_back(R);
6618 }
6619
Richard Smithc202b282012-04-14 00:33:13 +00006620 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6621 if (SubStmt.isInvalid())
6622 return StmtError();
6623
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006624 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006625 return S;
6626
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006627 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006628 SubStmt.get());
6629}
6630
6631template<typename Derived>
6632StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006633TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006634 // Transform the initialization statement
6635 StmtResult Init = getDerived().TransformStmt(S->getInit());
6636 if (Init.isInvalid())
6637 return StmtError();
6638
Douglas Gregorebe10102009-08-20 07:17:43 +00006639 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006640 Sema::ConditionResult Cond = getDerived().TransformCondition(
6641 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006642 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6643 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006644 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006645 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006646
Richard Smithb130fe72016-06-23 19:16:49 +00006647 // If this is a constexpr if, determine which arm we should instantiate.
6648 llvm::Optional<bool> ConstexprConditionValue;
6649 if (S->isConstexpr())
6650 ConstexprConditionValue = Cond.getKnownValue();
6651
Douglas Gregorebe10102009-08-20 07:17:43 +00006652 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006653 StmtResult Then;
6654 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6655 Then = getDerived().TransformStmt(S->getThen());
6656 if (Then.isInvalid())
6657 return StmtError();
6658 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006659 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006660 }
Mike Stump11289f42009-09-09 15:08:12 +00006661
Douglas Gregorebe10102009-08-20 07:17:43 +00006662 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006663 StmtResult Else;
6664 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6665 Else = getDerived().TransformStmt(S->getElse());
6666 if (Else.isInvalid())
6667 return StmtError();
6668 }
Mike Stump11289f42009-09-09 15:08:12 +00006669
Douglas Gregorebe10102009-08-20 07:17:43 +00006670 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006671 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006672 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006673 Then.get() == S->getThen() &&
6674 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006675 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006676
Richard Smithb130fe72016-06-23 19:16:49 +00006677 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006678 Init.get(), Then.get(), S->getElseLoc(),
6679 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006680}
6681
6682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006683StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006684TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006685 // Transform the initialization statement
6686 StmtResult Init = getDerived().TransformStmt(S->getInit());
6687 if (Init.isInvalid())
6688 return StmtError();
6689
Douglas Gregorebe10102009-08-20 07:17:43 +00006690 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006691 Sema::ConditionResult Cond = getDerived().TransformCondition(
6692 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6693 Sema::ConditionKind::Switch);
6694 if (Cond.isInvalid())
6695 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregorebe10102009-08-20 07:17:43 +00006697 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006698 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006699 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006700 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006701 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006702
Douglas Gregorebe10102009-08-20 07:17:43 +00006703 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006704 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006705 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006706 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006707
Douglas Gregorebe10102009-08-20 07:17:43 +00006708 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006709 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6710 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006711}
Mike Stump11289f42009-09-09 15:08:12 +00006712
Douglas Gregorebe10102009-08-20 07:17:43 +00006713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006714StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006715TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006716 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006717 Sema::ConditionResult Cond = getDerived().TransformCondition(
6718 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6719 Sema::ConditionKind::Boolean);
6720 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006721 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006722
Douglas Gregorebe10102009-08-20 07:17:43 +00006723 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006724 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006725 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006726 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006727
Douglas Gregorebe10102009-08-20 07:17:43 +00006728 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006729 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006730 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006731 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006732
Richard Smith03a4aa32016-06-23 19:02:52 +00006733 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006734}
Mike Stump11289f42009-09-09 15:08:12 +00006735
Douglas Gregorebe10102009-08-20 07:17:43 +00006736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006737StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006738TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006739 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006740 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006741 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006742 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006743
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006744 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006745 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006746 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006747 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006748
Douglas Gregorebe10102009-08-20 07:17:43 +00006749 if (!getDerived().AlwaysRebuild() &&
6750 Cond.get() == S->getCond() &&
6751 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006752 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006753
John McCallb268a282010-08-23 23:25:46 +00006754 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6755 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006756 S->getRParenLoc());
6757}
Mike Stump11289f42009-09-09 15:08:12 +00006758
Douglas Gregorebe10102009-08-20 07:17:43 +00006759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006760StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006761TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006762 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006763 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006764 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006765 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006766
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006767 // In OpenMP loop region loop control variable must be captured and be
6768 // private. Perform analysis of first part (if any).
6769 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6770 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6771
Douglas Gregorebe10102009-08-20 07:17:43 +00006772 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006773 Sema::ConditionResult Cond = getDerived().TransformCondition(
6774 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6775 Sema::ConditionKind::Boolean);
6776 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006777 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006778
Douglas Gregorebe10102009-08-20 07:17:43 +00006779 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006780 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006781 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006783
Richard Smith945f8d32013-01-14 22:39:08 +00006784 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006785 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006786 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006787
Douglas Gregorebe10102009-08-20 07:17:43 +00006788 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006789 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006790 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006791 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006792
Douglas Gregorebe10102009-08-20 07:17:43 +00006793 if (!getDerived().AlwaysRebuild() &&
6794 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006795 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006796 Inc.get() == S->getInc() &&
6797 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006798 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006799
Douglas Gregorebe10102009-08-20 07:17:43 +00006800 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006801 Init.get(), Cond, FullInc,
6802 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006803}
6804
6805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006806StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006807TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006808 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6809 S->getLabel());
6810 if (!LD)
6811 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006812
Douglas Gregorebe10102009-08-20 07:17:43 +00006813 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006814 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006815 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006816}
6817
6818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006819StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006820TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006821 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006822 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006823 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006824 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006825
Douglas Gregorebe10102009-08-20 07:17:43 +00006826 if (!getDerived().AlwaysRebuild() &&
6827 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006828 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006829
6830 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006831 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006832}
6833
6834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006836TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006837 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006838}
Mike Stump11289f42009-09-09 15:08:12 +00006839
Douglas Gregorebe10102009-08-20 07:17:43 +00006840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006841StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006842TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006843 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006844}
Mike Stump11289f42009-09-09 15:08:12 +00006845
Douglas Gregorebe10102009-08-20 07:17:43 +00006846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006847StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006848TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006849 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6850 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006851 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006852 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006853
Mike Stump11289f42009-09-09 15:08:12 +00006854 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006855 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006856 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006857}
Mike Stump11289f42009-09-09 15:08:12 +00006858
Douglas Gregorebe10102009-08-20 07:17:43 +00006859template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006860StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006861TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006862 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006863 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006864 for (auto *D : S->decls()) {
6865 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006866 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006868
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006869 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006870 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006871
Douglas Gregorebe10102009-08-20 07:17:43 +00006872 Decls.push_back(Transformed);
6873 }
Mike Stump11289f42009-09-09 15:08:12 +00006874
Douglas Gregorebe10102009-08-20 07:17:43 +00006875 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006876 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006877
Stephen Kellya6e43582018-08-09 21:05:56 +00006878 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006879}
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregorebe10102009-08-20 07:17:43 +00006881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006882StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006883TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006884
Benjamin Kramerf0623432012-08-23 22:51:59 +00006885 SmallVector<Expr*, 8> Constraints;
6886 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006887 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006888
John McCalldadc5752010-08-24 06:29:42 +00006889 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006890 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006891
6892 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006893
Anders Carlssonaaeef072010-01-24 05:50:09 +00006894 // Go through the outputs.
6895 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006896 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006897
Anders Carlssonaaeef072010-01-24 05:50:09 +00006898 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006899 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006900
Anders Carlssonaaeef072010-01-24 05:50:09 +00006901 // Transform the output expr.
6902 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006903 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006904 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006905 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006906
Anders Carlssonaaeef072010-01-24 05:50:09 +00006907 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006908
John McCallb268a282010-08-23 23:25:46 +00006909 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006910 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006911
Anders Carlssonaaeef072010-01-24 05:50:09 +00006912 // Go through the inputs.
6913 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006914 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006915
Anders Carlssonaaeef072010-01-24 05:50:09 +00006916 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006917 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006918
Anders Carlssonaaeef072010-01-24 05:50:09 +00006919 // Transform the input expr.
6920 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006921 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006922 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006923 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006924
Anders Carlssonaaeef072010-01-24 05:50:09 +00006925 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006926
John McCallb268a282010-08-23 23:25:46 +00006927 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006929
Anders Carlssonaaeef072010-01-24 05:50:09 +00006930 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006931 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006932
6933 // Go through the clobbers.
6934 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006935 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006936
6937 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006938 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006939 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6940 S->isVolatile(), S->getNumOutputs(),
6941 S->getNumInputs(), Names.data(),
6942 Constraints, Exprs, AsmString.get(),
6943 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006944}
6945
Chad Rosier32503022012-06-11 20:47:18 +00006946template<typename Derived>
6947StmtResult
6948TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006949 ArrayRef<Token> AsmToks =
6950 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006951
John McCallf413f5e2013-05-03 00:10:13 +00006952 bool HadError = false, HadChange = false;
6953
6954 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6955 SmallVector<Expr*, 8> TransformedExprs;
6956 TransformedExprs.reserve(SrcExprs.size());
6957 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6958 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6959 if (!Result.isUsable()) {
6960 HadError = true;
6961 } else {
6962 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006963 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006964 }
6965 }
6966
6967 if (HadError) return StmtError();
6968 if (!HadChange && !getDerived().AlwaysRebuild())
6969 return Owned(S);
6970
Chad Rosierb6f46c12012-08-15 16:53:30 +00006971 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006972 AsmToks, S->getAsmString(),
6973 S->getNumOutputs(), S->getNumInputs(),
6974 S->getAllConstraints(), S->getClobbers(),
6975 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006976}
Douglas Gregorebe10102009-08-20 07:17:43 +00006977
Richard Smith9f690bd2015-10-27 06:02:45 +00006978// C++ Coroutines TS
6979
6980template<typename Derived>
6981StmtResult
6982TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006983 auto *ScopeInfo = SemaRef.getCurFunction();
6984 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00006985 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006986 ScopeInfo->NeedsCoroutineSuspends &&
6987 ScopeInfo->CoroutineSuspends.first == nullptr &&
6988 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00006989 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006990
6991 // Set that we have (possibly-invalid) suspend points before we do anything
6992 // that may fail.
6993 ScopeInfo->setNeedsCoroutineSuspends(false);
6994
6995 // The new CoroutinePromise object needs to be built and put into the current
6996 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00006997 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
6998 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006999 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7000 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007001 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007002 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
7003 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007004
7005 // Transform the implicit coroutine statements we built during the initial
7006 // parse.
7007 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7008 if (InitSuspend.isInvalid())
7009 return StmtError();
7010 StmtResult FinalSuspend =
7011 getDerived().TransformStmt(S->getFinalSuspendStmt());
7012 if (FinalSuspend.isInvalid())
7013 return StmtError();
7014 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7015 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007016
7017 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7018 if (BodyRes.isInvalid())
7019 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007020
Eric Fiselierbee782b2017-04-03 19:21:00 +00007021 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7022 if (Builder.isInvalid())
7023 return StmtError();
7024
7025 Expr *ReturnObject = S->getReturnValueInit();
7026 assert(ReturnObject && "the return object is expected to be valid");
7027 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7028 /*NoCopyInit*/ false);
7029 if (Res.isInvalid())
7030 return StmtError();
7031 Builder.ReturnValue = Res.get();
7032
7033 if (S->hasDependentPromiseType()) {
7034 assert(!Promise->getType()->isDependentType() &&
7035 "the promise type must no longer be dependent");
7036 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7037 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7038 "these nodes should not have been built yet");
7039 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007040 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007041 } else {
7042 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7043 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7044 if (Res.isInvalid())
7045 return StmtError();
7046 Builder.OnFallthrough = Res.get();
7047 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007048
Eric Fiselierbee782b2017-04-03 19:21:00 +00007049 if (auto *OnException = S->getExceptionHandler()) {
7050 StmtResult Res = getDerived().TransformStmt(OnException);
7051 if (Res.isInvalid())
7052 return StmtError();
7053 Builder.OnException = Res.get();
7054 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007055
Eric Fiselierbee782b2017-04-03 19:21:00 +00007056 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7057 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7058 if (Res.isInvalid())
7059 return StmtError();
7060 Builder.ReturnStmtOnAllocFailure = Res.get();
7061 }
7062
7063 // Transform any additional statements we may have already built
7064 assert(S->getAllocate() && S->getDeallocate() &&
7065 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007066 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7067 if (AllocRes.isInvalid())
7068 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007069 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007070
7071 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7072 if (DeallocRes.isInvalid())
7073 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007074 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007075
7076 assert(S->getResultDecl() && "ResultDecl must already be built");
7077 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7078 if (ResultDecl.isInvalid())
7079 return StmtError();
7080 Builder.ResultDecl = ResultDecl.get();
7081
7082 if (auto *ReturnStmt = S->getReturnStmt()) {
7083 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7084 if (Res.isInvalid())
7085 return StmtError();
7086 Builder.ReturnStmt = Res.get();
7087 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007088 }
7089
Eric Fiselierbee782b2017-04-03 19:21:00 +00007090 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007091}
7092
7093template<typename Derived>
7094StmtResult
7095TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7096 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7097 /*NotCopyInit*/false);
7098 if (Result.isInvalid())
7099 return StmtError();
7100
7101 // Always rebuild; we don't know if this needs to be injected into a new
7102 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007103 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7104 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007105}
7106
7107template<typename Derived>
7108ExprResult
7109TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7110 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7111 /*NotCopyInit*/false);
7112 if (Result.isInvalid())
7113 return ExprError();
7114
7115 // Always rebuild; we don't know if this needs to be injected into a new
7116 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007117 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7118 E->isImplicit());
7119}
7120
7121template <typename Derived>
7122ExprResult
7123TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7124 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7125 /*NotCopyInit*/ false);
7126 if (OperandResult.isInvalid())
7127 return ExprError();
7128
7129 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7130 E->getOperatorCoawaitLookup());
7131
7132 if (LookupResult.isInvalid())
7133 return ExprError();
7134
7135 // Always rebuild; we don't know if this needs to be injected into a new
7136 // context or if the promise type has changed.
7137 return getDerived().RebuildDependentCoawaitExpr(
7138 E->getKeywordLoc(), OperandResult.get(),
7139 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007140}
7141
7142template<typename Derived>
7143ExprResult
7144TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7145 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7146 /*NotCopyInit*/false);
7147 if (Result.isInvalid())
7148 return ExprError();
7149
7150 // Always rebuild; we don't know if this needs to be injected into a new
7151 // context or if the promise type has changed.
7152 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7153}
7154
7155// Objective-C Statements.
7156
Douglas Gregorebe10102009-08-20 07:17:43 +00007157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007158StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007159TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007160 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007161 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007162 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007163 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007164
Douglas Gregor96c79492010-04-23 22:50:49 +00007165 // Transform the @catch statements (if present).
7166 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007167 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007168 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007169 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007170 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007171 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007172 if (Catch.get() != S->getCatchStmt(I))
7173 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007174 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007176
Douglas Gregor306de2f2010-04-22 23:59:56 +00007177 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007178 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007179 if (S->getFinallyStmt()) {
7180 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7181 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007182 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007183 }
7184
7185 // If nothing changed, just retain this statement.
7186 if (!getDerived().AlwaysRebuild() &&
7187 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007188 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007189 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007190 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007191
Douglas Gregor306de2f2010-04-22 23:59:56 +00007192 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007193 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007194 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007195}
Mike Stump11289f42009-09-09 15:08:12 +00007196
Douglas Gregorebe10102009-08-20 07:17:43 +00007197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007198StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007199TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007200 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007201 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007202 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007203 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007204 if (FromVar->getTypeSourceInfo()) {
7205 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7206 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007207 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007208 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007209
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007210 QualType T;
7211 if (TSInfo)
7212 T = TSInfo->getType();
7213 else {
7214 T = getDerived().TransformType(FromVar->getType());
7215 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007216 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007217 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007218
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007219 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7220 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007221 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007222 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007223
John McCalldadc5752010-08-24 06:29:42 +00007224 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007225 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007226 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007227
7228 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007229 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007230 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007231}
Mike Stump11289f42009-09-09 15:08:12 +00007232
Douglas Gregorebe10102009-08-20 07:17:43 +00007233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007234StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007235TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007236 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007237 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007238 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007239 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007240
Douglas Gregor306de2f2010-04-22 23:59:56 +00007241 // If nothing changed, just retain this statement.
7242 if (!getDerived().AlwaysRebuild() &&
7243 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007244 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007245
7246 // Build a new statement.
7247 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007248 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007249}
Mike Stump11289f42009-09-09 15:08:12 +00007250
Douglas Gregorebe10102009-08-20 07:17:43 +00007251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007252StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007253TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007254 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007255 if (S->getThrowExpr()) {
7256 Operand = getDerived().TransformExpr(S->getThrowExpr());
7257 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007258 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007259 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007260
Douglas Gregor2900c162010-04-22 21:44:01 +00007261 if (!getDerived().AlwaysRebuild() &&
7262 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007263 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007264
John McCallb268a282010-08-23 23:25:46 +00007265 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007266}
Mike Stump11289f42009-09-09 15:08:12 +00007267
Douglas Gregorebe10102009-08-20 07:17:43 +00007268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007269StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007270TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007271 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007272 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007273 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007274 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007275 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007276 Object =
7277 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7278 Object.get());
7279 if (Object.isInvalid())
7280 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007281
Douglas Gregor6148de72010-04-22 22:01:21 +00007282 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007283 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007284 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007285 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007286
Douglas Gregor6148de72010-04-22 22:01:21 +00007287 // If nothing change, just retain the current statement.
7288 if (!getDerived().AlwaysRebuild() &&
7289 Object.get() == S->getSynchExpr() &&
7290 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007291 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007292
7293 // Build a new statement.
7294 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007295 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007296}
7297
7298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007299StmtResult
John McCall31168b02011-06-15 23:02:42 +00007300TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7301 ObjCAutoreleasePoolStmt *S) {
7302 // Transform the body.
7303 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7304 if (Body.isInvalid())
7305 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007306
John McCall31168b02011-06-15 23:02:42 +00007307 // If nothing changed, just retain this statement.
7308 if (!getDerived().AlwaysRebuild() &&
7309 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007310 return S;
John McCall31168b02011-06-15 23:02:42 +00007311
7312 // Build a new statement.
7313 return getDerived().RebuildObjCAutoreleasePoolStmt(
7314 S->getAtLoc(), Body.get());
7315}
7316
7317template<typename Derived>
7318StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007319TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007320 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007321 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007322 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007323 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007324 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007325
Douglas Gregorf68a5082010-04-22 23:10:45 +00007326 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007327 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007328 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007329 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007330
Douglas Gregorf68a5082010-04-22 23:10:45 +00007331 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007332 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007333 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007334 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007335
Douglas Gregorf68a5082010-04-22 23:10:45 +00007336 // If nothing changed, just retain this statement.
7337 if (!getDerived().AlwaysRebuild() &&
7338 Element.get() == S->getElement() &&
7339 Collection.get() == S->getCollection() &&
7340 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007341 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007342
Douglas Gregorf68a5082010-04-22 23:10:45 +00007343 // Build a new statement.
7344 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007345 Element.get(),
7346 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007347 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007348 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007349}
7350
David Majnemer5f7efef2013-10-15 09:50:08 +00007351template <typename Derived>
7352StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007353 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007354 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007355 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7356 TypeSourceInfo *T =
7357 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007358 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007359 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007360
David Majnemer5f7efef2013-10-15 09:50:08 +00007361 Var = getDerived().RebuildExceptionDecl(
7362 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7363 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007364 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007365 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007366 }
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregorebe10102009-08-20 07:17:43 +00007368 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007369 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007370 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007371 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007372
David Majnemer5f7efef2013-10-15 09:50:08 +00007373 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007374 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007375 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007376
David Majnemer5f7efef2013-10-15 09:50:08 +00007377 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007378}
Mike Stump11289f42009-09-09 15:08:12 +00007379
David Majnemer5f7efef2013-10-15 09:50:08 +00007380template <typename Derived>
7381StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007382 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007383 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007384 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007385 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007386
Douglas Gregorebe10102009-08-20 07:17:43 +00007387 // Transform the handlers.
7388 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007389 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007390 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007391 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007392 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007393 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007394
Douglas Gregorebe10102009-08-20 07:17:43 +00007395 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007396 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007397 }
Mike Stump11289f42009-09-09 15:08:12 +00007398
David Majnemer5f7efef2013-10-15 09:50:08 +00007399 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007400 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007401 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007402
John McCallb268a282010-08-23 23:25:46 +00007403 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007404 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007405}
Mike Stump11289f42009-09-09 15:08:12 +00007406
Richard Smith02e85f32011-04-14 22:09:26 +00007407template<typename Derived>
7408StmtResult
7409TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7410 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7411 if (Range.isInvalid())
7412 return StmtError();
7413
Richard Smith01694c32016-03-20 10:33:40 +00007414 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7415 if (Begin.isInvalid())
7416 return StmtError();
7417 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7418 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007419 return StmtError();
7420
7421 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7422 if (Cond.isInvalid())
7423 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007424 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007425 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007426 if (Cond.isInvalid())
7427 return StmtError();
7428 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007429 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007430
7431 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7432 if (Inc.isInvalid())
7433 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007434 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007435 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007436
7437 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7438 if (LoopVar.isInvalid())
7439 return StmtError();
7440
7441 StmtResult NewStmt = S;
7442 if (getDerived().AlwaysRebuild() ||
7443 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007444 Begin.get() != S->getBeginStmt() ||
7445 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007446 Cond.get() != S->getCond() ||
7447 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007448 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007449 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007450 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007451 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007452 Begin.get(), End.get(),
7453 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007454 Inc.get(), LoopVar.get(),
7455 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007456 if (NewStmt.isInvalid())
7457 return StmtError();
7458 }
Richard Smith02e85f32011-04-14 22:09:26 +00007459
7460 StmtResult Body = getDerived().TransformStmt(S->getBody());
7461 if (Body.isInvalid())
7462 return StmtError();
7463
7464 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7465 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007466 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007467 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007468 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007469 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007470 Begin.get(), End.get(),
7471 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007472 Inc.get(), LoopVar.get(),
7473 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007474 if (NewStmt.isInvalid())
7475 return StmtError();
7476 }
Richard Smith02e85f32011-04-14 22:09:26 +00007477
7478 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007479 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007480
7481 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7482}
7483
John Wiegley1c0675e2011-04-28 01:08:34 +00007484template<typename Derived>
7485StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007486TreeTransform<Derived>::TransformMSDependentExistsStmt(
7487 MSDependentExistsStmt *S) {
7488 // Transform the nested-name-specifier, if any.
7489 NestedNameSpecifierLoc QualifierLoc;
7490 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007491 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007492 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7493 if (!QualifierLoc)
7494 return StmtError();
7495 }
7496
7497 // Transform the declaration name.
7498 DeclarationNameInfo NameInfo = S->getNameInfo();
7499 if (NameInfo.getName()) {
7500 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7501 if (!NameInfo.getName())
7502 return StmtError();
7503 }
7504
7505 // Check whether anything changed.
7506 if (!getDerived().AlwaysRebuild() &&
7507 QualifierLoc == S->getQualifierLoc() &&
7508 NameInfo.getName() == S->getNameInfo().getName())
7509 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007510
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007511 // Determine whether this name exists, if we can.
7512 CXXScopeSpec SS;
7513 SS.Adopt(QualifierLoc);
7514 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007515 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007516 case Sema::IER_Exists:
7517 if (S->isIfExists())
7518 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007519
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007520 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7521
7522 case Sema::IER_DoesNotExist:
7523 if (S->isIfNotExists())
7524 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007525
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007526 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007527
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007528 case Sema::IER_Dependent:
7529 Dependent = true;
7530 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007531
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007532 case Sema::IER_Error:
7533 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007534 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007535
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007536 // We need to continue with the instantiation, so do so now.
7537 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7538 if (SubStmt.isInvalid())
7539 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007540
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007541 // If we have resolved the name, just transform to the substatement.
7542 if (!Dependent)
7543 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007544
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007545 // The name is still dependent, so build a dependent expression again.
7546 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7547 S->isIfExists(),
7548 QualifierLoc,
7549 NameInfo,
7550 SubStmt.get());
7551}
7552
7553template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007554ExprResult
7555TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7556 NestedNameSpecifierLoc QualifierLoc;
7557 if (E->getQualifierLoc()) {
7558 QualifierLoc
7559 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7560 if (!QualifierLoc)
7561 return ExprError();
7562 }
7563
7564 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7565 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7566 if (!PD)
7567 return ExprError();
7568
7569 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7570 if (Base.isInvalid())
7571 return ExprError();
7572
7573 return new (SemaRef.getASTContext())
7574 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7575 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7576 QualifierLoc, E->getMemberLoc());
7577}
7578
David Majnemerfad8f482013-10-15 09:33:02 +00007579template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007580ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7581 MSPropertySubscriptExpr *E) {
7582 auto BaseRes = getDerived().TransformExpr(E->getBase());
7583 if (BaseRes.isInvalid())
7584 return ExprError();
7585 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7586 if (IdxRes.isInvalid())
7587 return ExprError();
7588
7589 if (!getDerived().AlwaysRebuild() &&
7590 BaseRes.get() == E->getBase() &&
7591 IdxRes.get() == E->getIdx())
7592 return E;
7593
7594 return getDerived().RebuildArraySubscriptExpr(
7595 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7596}
7597
7598template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007599StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007600 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007601 if (TryBlock.isInvalid())
7602 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007603
7604 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007605 if (Handler.isInvalid())
7606 return StmtError();
7607
David Majnemerfad8f482013-10-15 09:33:02 +00007608 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7609 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007610 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007611
Warren Huntf6be4cb2014-07-25 20:52:51 +00007612 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7613 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007614}
7615
David Majnemerfad8f482013-10-15 09:33:02 +00007616template <typename Derived>
7617StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007618 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007619 if (Block.isInvalid())
7620 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007621
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007622 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007623}
7624
David Majnemerfad8f482013-10-15 09:33:02 +00007625template <typename Derived>
7626StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007627 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007628 if (FilterExpr.isInvalid())
7629 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007630
David Majnemer7e755502013-10-15 09:30:14 +00007631 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007632 if (Block.isInvalid())
7633 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007634
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007635 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7636 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007637}
7638
David Majnemerfad8f482013-10-15 09:33:02 +00007639template <typename Derived>
7640StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7641 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007642 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7643 else
7644 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7645}
7646
Nico Weber9b982072014-07-07 00:12:30 +00007647template<typename Derived>
7648StmtResult
7649TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7650 return S;
7651}
7652
Alexander Musman64d33f12014-06-04 07:53:32 +00007653//===----------------------------------------------------------------------===//
7654// OpenMP directive transformation
7655//===----------------------------------------------------------------------===//
7656template <typename Derived>
7657StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7658 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007659
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007660 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007661 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007662 ArrayRef<OMPClause *> Clauses = D->clauses();
7663 TClauses.reserve(Clauses.size());
7664 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7665 I != E; ++I) {
7666 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007667 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007668 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007669 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007670 if (Clause)
7671 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007672 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007673 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007674 }
7675 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007676 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007677 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007678 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7679 /*CurScope=*/nullptr);
7680 StmtResult Body;
7681 {
7682 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007683 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007684 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007685 }
7686 AssociatedStmt =
7687 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007688 if (AssociatedStmt.isInvalid()) {
7689 return StmtError();
7690 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007691 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007692 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007693 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007694 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007695
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007696 // Transform directive name for 'omp critical' directive.
7697 DeclarationNameInfo DirName;
7698 if (D->getDirectiveKind() == OMPD_critical) {
7699 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7700 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7701 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007702 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7703 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7704 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007705 } else if (D->getDirectiveKind() == OMPD_cancel) {
7706 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007707 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007708
Alexander Musman64d33f12014-06-04 07:53:32 +00007709 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007710 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007711 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007712}
7713
Alexander Musman64d33f12014-06-04 07:53:32 +00007714template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007715StmtResult
7716TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7717 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007718 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007719 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007720 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7721 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7722 return Res;
7723}
7724
Alexander Musman64d33f12014-06-04 07:53:32 +00007725template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007726StmtResult
7727TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7728 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007729 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007730 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007731 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7732 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007733 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007734}
7735
Alexey Bataevf29276e2014-06-18 04:14:57 +00007736template <typename Derived>
7737StmtResult
7738TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7739 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007740 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007741 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007742 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7743 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7744 return Res;
7745}
7746
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007747template <typename Derived>
7748StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007749TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7750 DeclarationNameInfo DirName;
7751 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007752 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007753 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7754 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7755 return Res;
7756}
7757
7758template <typename Derived>
7759StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007760TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7761 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007762 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007763 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007764 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7765 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7766 return Res;
7767}
7768
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007769template <typename Derived>
7770StmtResult
7771TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7772 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007773 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007774 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007775 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7776 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7777 return Res;
7778}
7779
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007780template <typename Derived>
7781StmtResult
7782TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7783 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007784 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007785 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007786 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7787 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7788 return Res;
7789}
7790
Alexey Bataev4acb8592014-07-07 13:01:15 +00007791template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007792StmtResult
7793TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7794 DeclarationNameInfo DirName;
7795 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007796 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00007797 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7798 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7799 return Res;
7800}
7801
7802template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007803StmtResult
7804TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7805 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007806 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007807 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7808 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7809 return Res;
7810}
7811
7812template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007813StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7814 OMPParallelForDirective *D) {
7815 DeclarationNameInfo DirName;
7816 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007817 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00007818 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7819 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7820 return Res;
7821}
7822
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007823template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007824StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7825 OMPParallelForSimdDirective *D) {
7826 DeclarationNameInfo DirName;
7827 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007828 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00007829 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7830 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7831 return Res;
7832}
7833
7834template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007835StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7836 OMPParallelSectionsDirective *D) {
7837 DeclarationNameInfo DirName;
7838 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007839 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007840 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7841 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7842 return Res;
7843}
7844
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007845template <typename Derived>
7846StmtResult
7847TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7848 DeclarationNameInfo DirName;
7849 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007850 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007851 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7852 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7853 return Res;
7854}
7855
Alexey Bataev68446b72014-07-18 07:47:19 +00007856template <typename Derived>
7857StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7858 OMPTaskyieldDirective *D) {
7859 DeclarationNameInfo DirName;
7860 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007861 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00007862 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7863 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7864 return Res;
7865}
7866
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007867template <typename Derived>
7868StmtResult
7869TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7870 DeclarationNameInfo DirName;
7871 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007872 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007873 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7874 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7875 return Res;
7876}
7877
Alexey Bataev2df347a2014-07-18 10:17:07 +00007878template <typename Derived>
7879StmtResult
7880TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7881 DeclarationNameInfo DirName;
7882 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007883 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00007884 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7885 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7886 return Res;
7887}
7888
Alexey Bataev6125da92014-07-21 11:26:11 +00007889template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007890StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7891 OMPTaskgroupDirective *D) {
7892 DeclarationNameInfo DirName;
7893 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007894 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007895 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7896 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7897 return Res;
7898}
7899
7900template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007901StmtResult
7902TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7903 DeclarationNameInfo DirName;
7904 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007905 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00007906 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7907 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7908 return Res;
7909}
7910
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007911template <typename Derived>
7912StmtResult
7913TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7914 DeclarationNameInfo DirName;
7915 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007916 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007917 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7918 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7919 return Res;
7920}
7921
Alexey Bataev0162e452014-07-22 10:10:35 +00007922template <typename Derived>
7923StmtResult
7924TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7925 DeclarationNameInfo DirName;
7926 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007927 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00007928 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7929 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7930 return Res;
7931}
7932
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007933template <typename Derived>
7934StmtResult
7935TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7936 DeclarationNameInfo DirName;
7937 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007938 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007939 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7940 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7941 return Res;
7942}
7943
Alexey Bataev13314bf2014-10-09 04:18:56 +00007944template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007945StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7946 OMPTargetDataDirective *D) {
7947 DeclarationNameInfo DirName;
7948 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007949 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00007950 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7951 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7952 return Res;
7953}
7954
7955template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007956StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7957 OMPTargetEnterDataDirective *D) {
7958 DeclarationNameInfo DirName;
7959 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007960 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00007961 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7962 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7963 return Res;
7964}
7965
7966template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007967StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7968 OMPTargetExitDataDirective *D) {
7969 DeclarationNameInfo DirName;
7970 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007971 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00007972 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7973 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7974 return Res;
7975}
7976
7977template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007978StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7979 OMPTargetParallelDirective *D) {
7980 DeclarationNameInfo DirName;
7981 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007982 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007983 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7984 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7985 return Res;
7986}
7987
7988template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007989StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7990 OMPTargetParallelForDirective *D) {
7991 DeclarationNameInfo DirName;
7992 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007993 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007994 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7995 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7996 return Res;
7997}
7998
7999template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008000StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8001 OMPTargetUpdateDirective *D) {
8002 DeclarationNameInfo DirName;
8003 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008004 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008005 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8006 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8007 return Res;
8008}
8009
8010template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008011StmtResult
8012TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8013 DeclarationNameInfo DirName;
8014 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008015 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008016 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8017 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8018 return Res;
8019}
8020
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008021template <typename Derived>
8022StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8023 OMPCancellationPointDirective *D) {
8024 DeclarationNameInfo DirName;
8025 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008026 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008027 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8028 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8029 return Res;
8030}
8031
Alexey Bataev80909872015-07-02 11:25:17 +00008032template <typename Derived>
8033StmtResult
8034TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8035 DeclarationNameInfo DirName;
8036 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008037 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008038 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8039 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8040 return Res;
8041}
8042
Alexey Bataev49f6e782015-12-01 04:18:41 +00008043template <typename Derived>
8044StmtResult
8045TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8046 DeclarationNameInfo DirName;
8047 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008048 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008049 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8050 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8051 return Res;
8052}
8053
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008054template <typename Derived>
8055StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8056 OMPTaskLoopSimdDirective *D) {
8057 DeclarationNameInfo DirName;
8058 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008059 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008060 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8061 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8062 return Res;
8063}
8064
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008065template <typename Derived>
8066StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8067 OMPDistributeDirective *D) {
8068 DeclarationNameInfo DirName;
8069 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008070 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008071 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8072 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8073 return Res;
8074}
8075
Carlo Bertolli9925f152016-06-27 14:55:37 +00008076template <typename Derived>
8077StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8078 OMPDistributeParallelForDirective *D) {
8079 DeclarationNameInfo DirName;
8080 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008081 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008082 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8083 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8084 return Res;
8085}
8086
Kelvin Li4a39add2016-07-05 05:00:15 +00008087template <typename Derived>
8088StmtResult
8089TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8090 OMPDistributeParallelForSimdDirective *D) {
8091 DeclarationNameInfo DirName;
8092 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008093 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008094 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8095 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8096 return Res;
8097}
8098
Kelvin Li787f3fc2016-07-06 04:45:38 +00008099template <typename Derived>
8100StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8101 OMPDistributeSimdDirective *D) {
8102 DeclarationNameInfo DirName;
8103 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008104 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008105 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8106 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8107 return Res;
8108}
8109
Kelvin Lia579b912016-07-14 02:54:56 +00008110template <typename Derived>
8111StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8112 OMPTargetParallelForSimdDirective *D) {
8113 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008114 getDerived().getSema().StartOpenMPDSABlock(
8115 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008116 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8117 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8118 return Res;
8119}
8120
Kelvin Li986330c2016-07-20 22:57:10 +00008121template <typename Derived>
8122StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8123 OMPTargetSimdDirective *D) {
8124 DeclarationNameInfo DirName;
8125 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008126 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008127 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8128 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8129 return Res;
8130}
8131
Kelvin Li02532872016-08-05 14:37:37 +00008132template <typename Derived>
8133StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8134 OMPTeamsDistributeDirective *D) {
8135 DeclarationNameInfo DirName;
8136 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008137 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008138 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8139 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8140 return Res;
8141}
8142
Kelvin Li4e325f72016-10-25 12:50:55 +00008143template <typename Derived>
8144StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8145 OMPTeamsDistributeSimdDirective *D) {
8146 DeclarationNameInfo DirName;
8147 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008148 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008149 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8150 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8151 return Res;
8152}
8153
Kelvin Li579e41c2016-11-30 23:51:03 +00008154template <typename Derived>
8155StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8156 OMPTeamsDistributeParallelForSimdDirective *D) {
8157 DeclarationNameInfo DirName;
8158 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008159 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8160 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008161 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8162 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8163 return Res;
8164}
8165
Kelvin Li7ade93f2016-12-09 03:24:30 +00008166template <typename Derived>
8167StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8168 OMPTeamsDistributeParallelForDirective *D) {
8169 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008170 getDerived().getSema().StartOpenMPDSABlock(
8171 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008172 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8173 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8174 return Res;
8175}
8176
Kelvin Libf594a52016-12-17 05:48:59 +00008177template <typename Derived>
8178StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8179 OMPTargetTeamsDirective *D) {
8180 DeclarationNameInfo DirName;
8181 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008182 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008183 auto Res = getDerived().TransformOMPExecutableDirective(D);
8184 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8185 return Res;
8186}
Kelvin Li579e41c2016-11-30 23:51:03 +00008187
Kelvin Li83c451e2016-12-25 04:52:54 +00008188template <typename Derived>
8189StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8190 OMPTargetTeamsDistributeDirective *D) {
8191 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008192 getDerived().getSema().StartOpenMPDSABlock(
8193 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008194 auto Res = getDerived().TransformOMPExecutableDirective(D);
8195 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8196 return Res;
8197}
8198
Kelvin Li80e8f562016-12-29 22:16:30 +00008199template <typename Derived>
8200StmtResult
8201TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8202 OMPTargetTeamsDistributeParallelForDirective *D) {
8203 DeclarationNameInfo DirName;
8204 getDerived().getSema().StartOpenMPDSABlock(
8205 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008206 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008207 auto Res = getDerived().TransformOMPExecutableDirective(D);
8208 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8209 return Res;
8210}
8211
Kelvin Li1851df52017-01-03 05:23:48 +00008212template <typename Derived>
8213StmtResult TreeTransform<Derived>::
8214 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8215 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8216 DeclarationNameInfo DirName;
8217 getDerived().getSema().StartOpenMPDSABlock(
8218 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008219 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008220 auto Res = getDerived().TransformOMPExecutableDirective(D);
8221 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8222 return Res;
8223}
8224
Kelvin Lida681182017-01-10 18:08:18 +00008225template <typename Derived>
8226StmtResult
8227TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8228 OMPTargetTeamsDistributeSimdDirective *D) {
8229 DeclarationNameInfo DirName;
8230 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008231 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008232 auto Res = getDerived().TransformOMPExecutableDirective(D);
8233 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8234 return Res;
8235}
8236
Kelvin Li1851df52017-01-03 05:23:48 +00008237
Alexander Musman64d33f12014-06-04 07:53:32 +00008238//===----------------------------------------------------------------------===//
8239// OpenMP clause transformation
8240//===----------------------------------------------------------------------===//
8241template <typename Derived>
8242OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008243 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8244 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008245 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008246 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008247 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008248 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008249}
8250
Alexander Musman64d33f12014-06-04 07:53:32 +00008251template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008252OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8253 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8254 if (Cond.isInvalid())
8255 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008256 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008257 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008258}
8259
8260template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008261OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008262TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8263 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8264 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008265 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008266 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008267 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008268}
8269
Alexey Bataev62c87d22014-03-21 04:51:18 +00008270template <typename Derived>
8271OMPClause *
8272TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8273 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8274 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008275 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008276 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008277 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008278}
8279
Alexander Musman8bd31e62014-05-27 15:12:19 +00008280template <typename Derived>
8281OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008282TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8283 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8284 if (E.isInvalid())
8285 return nullptr;
8286 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008287 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008288}
8289
8290template <typename Derived>
8291OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008292TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8293 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8294 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008295 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008296 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008297 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008298}
8299
Alexander Musman64d33f12014-06-04 07:53:32 +00008300template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008301OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008302TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008303 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008304 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008305 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008306}
8307
Alexander Musman64d33f12014-06-04 07:53:32 +00008308template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008309OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008310TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008311 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008312 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008313 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008314}
8315
Alexander Musman64d33f12014-06-04 07:53:32 +00008316template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008317OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008318TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8319 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8320 if (E.isInvalid())
8321 return nullptr;
8322 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008323 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008324 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008325 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008326 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008327}
8328
8329template <typename Derived>
8330OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008331TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008332 ExprResult E;
8333 if (auto *Num = C->getNumForLoops()) {
8334 E = getDerived().TransformExpr(Num);
8335 if (E.isInvalid())
8336 return nullptr;
8337 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008338 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008339 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008340}
8341
8342template <typename Derived>
8343OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008344TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8345 // No need to rebuild this clause, no template-dependent parameters.
8346 return C;
8347}
8348
8349template <typename Derived>
8350OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008351TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8352 // No need to rebuild this clause, no template-dependent parameters.
8353 return C;
8354}
8355
8356template <typename Derived>
8357OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008358TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8359 // No need to rebuild this clause, no template-dependent parameters.
8360 return C;
8361}
8362
8363template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008364OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8365 // No need to rebuild this clause, no template-dependent parameters.
8366 return C;
8367}
8368
8369template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008370OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8371 // No need to rebuild this clause, no template-dependent parameters.
8372 return C;
8373}
8374
8375template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008376OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008377TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8378 // No need to rebuild this clause, no template-dependent parameters.
8379 return C;
8380}
8381
8382template <typename Derived>
8383OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008384TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8385 // No need to rebuild this clause, no template-dependent parameters.
8386 return C;
8387}
8388
8389template <typename Derived>
8390OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008391TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8392 // No need to rebuild this clause, no template-dependent parameters.
8393 return C;
8394}
8395
8396template <typename Derived>
8397OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008398TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8399 // No need to rebuild this clause, no template-dependent parameters.
8400 return C;
8401}
8402
8403template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008404OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8405 // No need to rebuild this clause, no template-dependent parameters.
8406 return C;
8407}
8408
8409template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008410OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008411TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8412 // No need to rebuild this clause, no template-dependent parameters.
8413 return C;
8414}
8415
8416template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008417OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8418 OMPUnifiedAddressClause *C) {
8419 llvm_unreachable("unified address clause cannot appear in dependent context");
8420}
8421
8422template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008423OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008424TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008425 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008426 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008427 for (auto *VE : C->varlists()) {
8428 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008429 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008430 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008431 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008432 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008433 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008434 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008435}
8436
Alexander Musman64d33f12014-06-04 07:53:32 +00008437template <typename Derived>
8438OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8439 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008440 llvm::SmallVector<Expr *, 16> Vars;
8441 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008442 for (auto *VE : C->varlists()) {
8443 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008444 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008445 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008446 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008447 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008448 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008449 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008450}
8451
Alexander Musman64d33f12014-06-04 07:53:32 +00008452template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008453OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008454TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8455 llvm::SmallVector<Expr *, 16> Vars;
8456 Vars.reserve(C->varlist_size());
8457 for (auto *VE : C->varlists()) {
8458 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8459 if (EVar.isInvalid())
8460 return nullptr;
8461 Vars.push_back(EVar.get());
8462 }
8463 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008464 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008465}
8466
8467template <typename Derived>
8468OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008469TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8470 llvm::SmallVector<Expr *, 16> Vars;
8471 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008472 for (auto *VE : C->varlists()) {
8473 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008474 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008475 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008476 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008477 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008478 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008479 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008480}
8481
Alexander Musman64d33f12014-06-04 07:53:32 +00008482template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008483OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008484TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8485 llvm::SmallVector<Expr *, 16> Vars;
8486 Vars.reserve(C->varlist_size());
8487 for (auto *VE : C->varlists()) {
8488 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8489 if (EVar.isInvalid())
8490 return nullptr;
8491 Vars.push_back(EVar.get());
8492 }
8493 CXXScopeSpec ReductionIdScopeSpec;
8494 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8495
8496 DeclarationNameInfo NameInfo = C->getNameInfo();
8497 if (NameInfo.getName()) {
8498 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8499 if (!NameInfo.getName())
8500 return nullptr;
8501 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008502 // Build a list of all UDR decls with the same names ranged by the Scopes.
8503 // The Scope boundary is a duplication of the previous decl.
8504 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8505 for (auto *E : C->reduction_ops()) {
8506 // Transform all the decls.
8507 if (E) {
8508 auto *ULE = cast<UnresolvedLookupExpr>(E);
8509 UnresolvedSet<8> Decls;
8510 for (auto *D : ULE->decls()) {
8511 NamedDecl *InstD =
8512 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8513 Decls.addDecl(InstD, InstD->getAccess());
8514 }
8515 UnresolvedReductions.push_back(
8516 UnresolvedLookupExpr::Create(
8517 SemaRef.Context, /*NamingClass=*/nullptr,
8518 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8519 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8520 Decls.begin(), Decls.end()));
8521 } else
8522 UnresolvedReductions.push_back(nullptr);
8523 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008524 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008525 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008526 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008527}
8528
8529template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008530OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8531 OMPTaskReductionClause *C) {
8532 llvm::SmallVector<Expr *, 16> Vars;
8533 Vars.reserve(C->varlist_size());
8534 for (auto *VE : C->varlists()) {
8535 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8536 if (EVar.isInvalid())
8537 return nullptr;
8538 Vars.push_back(EVar.get());
8539 }
8540 CXXScopeSpec ReductionIdScopeSpec;
8541 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8542
8543 DeclarationNameInfo NameInfo = C->getNameInfo();
8544 if (NameInfo.getName()) {
8545 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8546 if (!NameInfo.getName())
8547 return nullptr;
8548 }
8549 // Build a list of all UDR decls with the same names ranged by the Scopes.
8550 // The Scope boundary is a duplication of the previous decl.
8551 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8552 for (auto *E : C->reduction_ops()) {
8553 // Transform all the decls.
8554 if (E) {
8555 auto *ULE = cast<UnresolvedLookupExpr>(E);
8556 UnresolvedSet<8> Decls;
8557 for (auto *D : ULE->decls()) {
8558 NamedDecl *InstD =
8559 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8560 Decls.addDecl(InstD, InstD->getAccess());
8561 }
8562 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8563 SemaRef.Context, /*NamingClass=*/nullptr,
8564 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8565 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8566 } else
8567 UnresolvedReductions.push_back(nullptr);
8568 }
8569 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008570 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008571 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008572}
8573
8574template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008575OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008576TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8577 llvm::SmallVector<Expr *, 16> Vars;
8578 Vars.reserve(C->varlist_size());
8579 for (auto *VE : C->varlists()) {
8580 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8581 if (EVar.isInvalid())
8582 return nullptr;
8583 Vars.push_back(EVar.get());
8584 }
8585 CXXScopeSpec ReductionIdScopeSpec;
8586 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8587
8588 DeclarationNameInfo NameInfo = C->getNameInfo();
8589 if (NameInfo.getName()) {
8590 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8591 if (!NameInfo.getName())
8592 return nullptr;
8593 }
8594 // Build a list of all UDR decls with the same names ranged by the Scopes.
8595 // The Scope boundary is a duplication of the previous decl.
8596 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8597 for (auto *E : C->reduction_ops()) {
8598 // Transform all the decls.
8599 if (E) {
8600 auto *ULE = cast<UnresolvedLookupExpr>(E);
8601 UnresolvedSet<8> Decls;
8602 for (auto *D : ULE->decls()) {
8603 NamedDecl *InstD =
8604 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8605 Decls.addDecl(InstD, InstD->getAccess());
8606 }
8607 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8608 SemaRef.Context, /*NamingClass=*/nullptr,
8609 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8610 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8611 } else
8612 UnresolvedReductions.push_back(nullptr);
8613 }
8614 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008615 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008616 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008617}
8618
8619template <typename Derived>
8620OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008621TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8622 llvm::SmallVector<Expr *, 16> Vars;
8623 Vars.reserve(C->varlist_size());
8624 for (auto *VE : C->varlists()) {
8625 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8626 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008627 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008628 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008629 }
8630 ExprResult Step = getDerived().TransformExpr(C->getStep());
8631 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008632 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008633 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008634 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008635 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008636}
8637
Alexander Musman64d33f12014-06-04 07:53:32 +00008638template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008639OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008640TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8641 llvm::SmallVector<Expr *, 16> Vars;
8642 Vars.reserve(C->varlist_size());
8643 for (auto *VE : C->varlists()) {
8644 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8645 if (EVar.isInvalid())
8646 return nullptr;
8647 Vars.push_back(EVar.get());
8648 }
8649 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8650 if (Alignment.isInvalid())
8651 return nullptr;
8652 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008653 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008654 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008655}
8656
Alexander Musman64d33f12014-06-04 07:53:32 +00008657template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008658OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008659TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8660 llvm::SmallVector<Expr *, 16> Vars;
8661 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008662 for (auto *VE : C->varlists()) {
8663 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008664 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008665 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008666 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008667 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008668 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008669 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008670}
8671
Alexey Bataevbae9a792014-06-27 10:37:06 +00008672template <typename Derived>
8673OMPClause *
8674TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8675 llvm::SmallVector<Expr *, 16> Vars;
8676 Vars.reserve(C->varlist_size());
8677 for (auto *VE : C->varlists()) {
8678 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8679 if (EVar.isInvalid())
8680 return nullptr;
8681 Vars.push_back(EVar.get());
8682 }
8683 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008684 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008685}
8686
Alexey Bataev6125da92014-07-21 11:26:11 +00008687template <typename Derived>
8688OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *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 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008697 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008698 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008699}
8700
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008701template <typename Derived>
8702OMPClause *
8703TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8704 llvm::SmallVector<Expr *, 16> Vars;
8705 Vars.reserve(C->varlist_size());
8706 for (auto *VE : C->varlists()) {
8707 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8708 if (EVar.isInvalid())
8709 return nullptr;
8710 Vars.push_back(EVar.get());
8711 }
8712 return getDerived().RebuildOMPDependClause(
8713 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008714 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008715}
8716
Michael Wonge710d542015-08-07 16:16:36 +00008717template <typename Derived>
8718OMPClause *
8719TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8720 ExprResult E = getDerived().TransformExpr(C->getDevice());
8721 if (E.isInvalid())
8722 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008723 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008724 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00008725}
8726
Kelvin Li0bff7af2015-11-23 05:32:03 +00008727template <typename Derived>
8728OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8729 llvm::SmallVector<Expr *, 16> Vars;
8730 Vars.reserve(C->varlist_size());
8731 for (auto *VE : C->varlists()) {
8732 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8733 if (EVar.isInvalid())
8734 return nullptr;
8735 Vars.push_back(EVar.get());
8736 }
8737 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008738 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008739 C->getMapLoc(), C->getColonLoc(), Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008740 C->getLParenLoc(), C->getEndLoc());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008741}
8742
Kelvin Li099bb8c2015-11-24 20:50:12 +00008743template <typename Derived>
8744OMPClause *
8745TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8746 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8747 if (E.isInvalid())
8748 return nullptr;
8749 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008750 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00008751}
8752
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008753template <typename Derived>
8754OMPClause *
8755TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8756 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8757 if (E.isInvalid())
8758 return nullptr;
8759 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008760 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008761}
8762
Alexey Bataeva0569352015-12-01 10:17:31 +00008763template <typename Derived>
8764OMPClause *
8765TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8766 ExprResult E = getDerived().TransformExpr(C->getPriority());
8767 if (E.isInvalid())
8768 return nullptr;
8769 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008770 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00008771}
8772
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008773template <typename Derived>
8774OMPClause *
8775TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8776 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8777 if (E.isInvalid())
8778 return nullptr;
8779 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008780 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008781}
8782
Alexey Bataev382967a2015-12-08 12:06:20 +00008783template <typename Derived>
8784OMPClause *
8785TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8786 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8787 if (E.isInvalid())
8788 return nullptr;
8789 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008790 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00008791}
8792
Alexey Bataev28c75412015-12-15 08:19:24 +00008793template <typename Derived>
8794OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8795 ExprResult E = getDerived().TransformExpr(C->getHint());
8796 if (E.isInvalid())
8797 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008798 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008799 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00008800}
8801
Carlo Bertollib4adf552016-01-15 18:50:31 +00008802template <typename Derived>
8803OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8804 OMPDistScheduleClause *C) {
8805 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8806 if (E.isInvalid())
8807 return nullptr;
8808 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008809 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008810 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00008811}
8812
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008813template <typename Derived>
8814OMPClause *
8815TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8816 return C;
8817}
8818
Samuel Antao661c0902016-05-26 17:39:58 +00008819template <typename Derived>
8820OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8821 llvm::SmallVector<Expr *, 16> Vars;
8822 Vars.reserve(C->varlist_size());
8823 for (auto *VE : C->varlists()) {
8824 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8825 if (EVar.isInvalid())
8826 return 0;
8827 Vars.push_back(EVar.get());
8828 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008829 return getDerived().RebuildOMPToClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008830 C->getLParenLoc(), C->getEndLoc());
Samuel Antao661c0902016-05-26 17:39:58 +00008831}
8832
Samuel Antaoec172c62016-05-26 17:49:04 +00008833template <typename Derived>
8834OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8835 llvm::SmallVector<Expr *, 16> Vars;
8836 Vars.reserve(C->varlist_size());
8837 for (auto *VE : C->varlists()) {
8838 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8839 if (EVar.isInvalid())
8840 return 0;
8841 Vars.push_back(EVar.get());
8842 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008843 return getDerived().RebuildOMPFromClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008844 C->getLParenLoc(), C->getEndLoc());
Samuel Antaoec172c62016-05-26 17:49:04 +00008845}
8846
Carlo Bertolli2404b172016-07-13 15:37:16 +00008847template <typename Derived>
8848OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8849 OMPUseDevicePtrClause *C) {
8850 llvm::SmallVector<Expr *, 16> Vars;
8851 Vars.reserve(C->varlist_size());
8852 for (auto *VE : C->varlists()) {
8853 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8854 if (EVar.isInvalid())
8855 return nullptr;
8856 Vars.push_back(EVar.get());
8857 }
8858 return getDerived().RebuildOMPUseDevicePtrClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008859 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Carlo Bertolli2404b172016-07-13 15:37:16 +00008860}
8861
Carlo Bertolli70594e92016-07-13 17:16:49 +00008862template <typename Derived>
8863OMPClause *
8864TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8865 llvm::SmallVector<Expr *, 16> Vars;
8866 Vars.reserve(C->varlist_size());
8867 for (auto *VE : C->varlists()) {
8868 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8869 if (EVar.isInvalid())
8870 return nullptr;
8871 Vars.push_back(EVar.get());
8872 }
8873 return getDerived().RebuildOMPIsDevicePtrClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008874 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Carlo Bertolli70594e92016-07-13 17:16:49 +00008875}
8876
Douglas Gregorebe10102009-08-20 07:17:43 +00008877//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008878// Expression transformation
8879//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008881ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008882TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008883 if (!E->isTypeDependent())
8884 return E;
8885
8886 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8887 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008888}
Mike Stump11289f42009-09-09 15:08:12 +00008889
8890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008891ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008892TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008893 NestedNameSpecifierLoc QualifierLoc;
8894 if (E->getQualifierLoc()) {
8895 QualifierLoc
8896 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8897 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008898 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008899 }
John McCallce546572009-12-08 09:08:17 +00008900
8901 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008902 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8903 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008904 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008906
John McCall815039a2010-08-17 21:27:17 +00008907 DeclarationNameInfo NameInfo = E->getNameInfo();
8908 if (NameInfo.getName()) {
8909 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8910 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008911 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008912 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008913
8914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008915 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008916 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008917 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008918 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008919
8920 // Mark it referenced in the new context regardless.
8921 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008922 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008923
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008924 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008925 }
John McCallce546572009-12-08 09:08:17 +00008926
Craig Topperc3ec1492014-05-26 06:22:03 +00008927 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008928 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008929 TemplateArgs = &TransArgs;
8930 TransArgs.setLAngleLoc(E->getLAngleLoc());
8931 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008932 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8933 E->getNumTemplateArgs(),
8934 TransArgs))
8935 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008936 }
8937
Chad Rosier1dcde962012-08-08 18:46:20 +00008938 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008939 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008940}
Mike Stump11289f42009-09-09 15:08:12 +00008941
Douglas Gregora16548e2009-08-11 05:31:07 +00008942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008944TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008945 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008946}
Mike Stump11289f42009-09-09 15:08:12 +00008947
Leonard Chandb01c3a2018-06-20 17:19:40 +00008948template <typename Derived>
8949ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
8950 FixedPointLiteral *E) {
8951 return E;
8952}
8953
Douglas Gregora16548e2009-08-11 05:31:07 +00008954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008955ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008956TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008957 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008958}
Mike Stump11289f42009-09-09 15:08:12 +00008959
Douglas Gregora16548e2009-08-11 05:31:07 +00008960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008961ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008962TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008963 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008964}
Mike Stump11289f42009-09-09 15:08:12 +00008965
Douglas Gregora16548e2009-08-11 05:31:07 +00008966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008967ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008968TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008969 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008970}
Mike Stump11289f42009-09-09 15:08:12 +00008971
Douglas Gregora16548e2009-08-11 05:31:07 +00008972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008973ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008974TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008975 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008976}
8977
8978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008979ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008980TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008981 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008982 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008983 return SemaRef.MaybeBindToTemporary(E);
8984}
8985
8986template<typename Derived>
8987ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008988TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8989 ExprResult ControllingExpr =
8990 getDerived().TransformExpr(E->getControllingExpr());
8991 if (ControllingExpr.isInvalid())
8992 return ExprError();
8993
Chris Lattner01cf8db2011-07-20 06:58:45 +00008994 SmallVector<Expr *, 4> AssocExprs;
8995 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008996 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8997 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8998 if (TS) {
8999 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
9000 if (!AssocType)
9001 return ExprError();
9002 AssocTypes.push_back(AssocType);
9003 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009004 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009005 }
9006
9007 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
9008 if (AssocExpr.isInvalid())
9009 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009010 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009011 }
9012
9013 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9014 E->getDefaultLoc(),
9015 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009016 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009017 AssocTypes,
9018 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009019}
9020
9021template<typename Derived>
9022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009023TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009024 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009025 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009027
Douglas Gregora16548e2009-08-11 05:31:07 +00009028 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009029 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009030
John McCallb268a282010-08-23 23:25:46 +00009031 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009032 E->getRParen());
9033}
9034
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009035/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009036/// allowed to refer to a non-static member of a class even if there's no 'this'
9037/// object available.
9038template<typename Derived>
9039ExprResult
9040TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9041 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009042 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009043 else
9044 return getDerived().TransformExpr(E);
9045}
9046
Mike Stump11289f42009-09-09 15:08:12 +00009047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009048ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009049TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009050 ExprResult SubExpr;
9051 if (E->getOpcode() == UO_AddrOf)
9052 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9053 else
9054 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009057
Douglas Gregora16548e2009-08-11 05:31:07 +00009058 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009059 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009060
Douglas Gregora16548e2009-08-11 05:31:07 +00009061 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9062 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009063 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009064}
Mike Stump11289f42009-09-09 15:08:12 +00009065
Douglas Gregora16548e2009-08-11 05:31:07 +00009066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009067ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009068TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9069 // Transform the type.
9070 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9071 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009072 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009073
Douglas Gregor882211c2010-04-28 22:16:22 +00009074 // Transform all of the components into components similar to what the
9075 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009076 // FIXME: It would be slightly more efficient in the non-dependent case to
9077 // just map FieldDecls, rather than requiring the rebuilder to look for
9078 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009079 // template code that we don't care.
9080 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009081 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009082 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009083 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009084 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009085 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009086 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009087 Comp.LocStart = ON.getSourceRange().getBegin();
9088 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009089 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009090 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009091 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009092 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009093 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009094 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
Douglas Gregor882211c2010-04-28 22:16:22 +00009096 ExprChanged = ExprChanged || Index.get() != FromIndex;
9097 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009098 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009099 break;
9100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009101
James Y Knight7281c352015-12-29 22:31:18 +00009102 case OffsetOfNode::Field:
9103 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009104 Comp.isBrackets = false;
9105 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009106 if (!Comp.U.IdentInfo)
9107 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009108
Douglas Gregor882211c2010-04-28 22:16:22 +00009109 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009110
James Y Knight7281c352015-12-29 22:31:18 +00009111 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009112 // Will be recomputed during the rebuild.
9113 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009114 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregor882211c2010-04-28 22:16:22 +00009116 Components.push_back(Comp);
9117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009118
Douglas Gregor882211c2010-04-28 22:16:22 +00009119 // If nothing changed, retain the existing expression.
9120 if (!getDerived().AlwaysRebuild() &&
9121 Type == E->getTypeSourceInfo() &&
9122 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009123 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009124
Douglas Gregor882211c2010-04-28 22:16:22 +00009125 // Build a new offsetof expression.
9126 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009127 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009128}
9129
9130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009131ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009132TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009133 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009134 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009135 return E;
John McCall8d69a212010-11-15 23:31:06 +00009136}
9137
9138template<typename Derived>
9139ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009140TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9141 return E;
9142}
9143
9144template<typename Derived>
9145ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009146TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009147 // Rebuild the syntactic form. The original syntactic form has
9148 // opaque-value expressions in it, so strip those away and rebuild
9149 // the result. This is a really awful way of doing this, but the
9150 // better solution (rebuilding the semantic expressions and
9151 // rebinding OVEs as necessary) doesn't work; we'd need
9152 // TreeTransform to not strip away implicit conversions.
9153 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9154 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009155 if (result.isInvalid()) return ExprError();
9156
9157 // If that gives us a pseudo-object result back, the pseudo-object
9158 // expression must have been an lvalue-to-rvalue conversion which we
9159 // should reapply.
9160 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009161 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009162
9163 return result;
9164}
9165
9166template<typename Derived>
9167ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009168TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9169 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009171 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009172
John McCallbcd03502009-12-07 02:54:59 +00009173 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009174 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009176
John McCall4c98fd82009-11-04 07:28:41 +00009177 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009178 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009179
Peter Collingbournee190dee2011-03-11 19:24:49 +00009180 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9181 E->getKind(),
9182 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009183 }
Mike Stump11289f42009-09-09 15:08:12 +00009184
Eli Friedmane4f22df2012-02-29 04:03:55 +00009185 // C++0x [expr.sizeof]p1:
9186 // The operand is either an expression, which is an unevaluated operand
9187 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009188 EnterExpressionEvaluationContext Unevaluated(
9189 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9190 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009191
Reid Kleckner32506ed2014-06-12 23:03:48 +00009192 // Try to recover if we have something like sizeof(T::X) where X is a type.
9193 // Notably, there must be *exactly* one set of parens if X is a type.
9194 TypeSourceInfo *RecoveryTSI = nullptr;
9195 ExprResult SubExpr;
9196 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9197 if (auto *DRE =
9198 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9199 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9200 PE, DRE, false, &RecoveryTSI);
9201 else
9202 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9203
9204 if (RecoveryTSI) {
9205 return getDerived().RebuildUnaryExprOrTypeTrait(
9206 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9207 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009208 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009209
Eli Friedmane4f22df2012-02-29 04:03:55 +00009210 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009211 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009212
Peter Collingbournee190dee2011-03-11 19:24:49 +00009213 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9214 E->getOperatorLoc(),
9215 E->getKind(),
9216 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009217}
Mike Stump11289f42009-09-09 15:08:12 +00009218
Douglas Gregora16548e2009-08-11 05:31:07 +00009219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009221TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009222 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009223 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009225
John McCalldadc5752010-08-24 06:29:42 +00009226 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009227 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009228 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009229
9230
Douglas Gregora16548e2009-08-11 05:31:07 +00009231 if (!getDerived().AlwaysRebuild() &&
9232 LHS.get() == E->getLHS() &&
9233 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009234 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009235
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009236 return getDerived().RebuildArraySubscriptExpr(
9237 LHS.get(),
9238 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009239}
Mike Stump11289f42009-09-09 15:08:12 +00009240
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009241template <typename Derived>
9242ExprResult
9243TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9244 ExprResult Base = getDerived().TransformExpr(E->getBase());
9245 if (Base.isInvalid())
9246 return ExprError();
9247
9248 ExprResult LowerBound;
9249 if (E->getLowerBound()) {
9250 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9251 if (LowerBound.isInvalid())
9252 return ExprError();
9253 }
9254
9255 ExprResult Length;
9256 if (E->getLength()) {
9257 Length = getDerived().TransformExpr(E->getLength());
9258 if (Length.isInvalid())
9259 return ExprError();
9260 }
9261
9262 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9263 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9264 return E;
9265
9266 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009267 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009268 Length.get(), E->getRBracketLoc());
9269}
9270
Mike Stump11289f42009-09-09 15:08:12 +00009271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009273TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009274 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009275 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009276 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009277 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009278
9279 // Transform arguments.
9280 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009281 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009282 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009283 &ArgChanged))
9284 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009285
Douglas Gregora16548e2009-08-11 05:31:07 +00009286 if (!getDerived().AlwaysRebuild() &&
9287 Callee.get() == E->getCallee() &&
9288 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009289 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009290
Douglas Gregora16548e2009-08-11 05:31:07 +00009291 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009292 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009293 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009294 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009295 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009296 E->getRParenLoc());
9297}
Mike Stump11289f42009-09-09 15:08:12 +00009298
9299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009300ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009301TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009302 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009303 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009305
Douglas Gregorea972d32011-02-28 21:54:11 +00009306 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009307 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009308 QualifierLoc
9309 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009310
Douglas Gregorea972d32011-02-28 21:54:11 +00009311 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009312 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009313 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009314 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009315
Eli Friedman2cfcef62009-12-04 06:40:45 +00009316 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009317 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9318 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009319 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009321
John McCall16df1e52010-03-30 21:47:33 +00009322 NamedDecl *FoundDecl = E->getFoundDecl();
9323 if (FoundDecl == E->getMemberDecl()) {
9324 FoundDecl = Member;
9325 } else {
9326 FoundDecl = cast_or_null<NamedDecl>(
9327 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9328 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009329 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009330 }
9331
Douglas Gregora16548e2009-08-11 05:31:07 +00009332 if (!getDerived().AlwaysRebuild() &&
9333 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009334 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009335 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009336 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009337 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009338
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009339 // Mark it referenced in the new context regardless.
9340 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009341 SemaRef.MarkMemberReferenced(E);
9342
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009343 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009344 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009345
John McCall6b51f282009-11-23 01:53:49 +00009346 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009347 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009348 TransArgs.setLAngleLoc(E->getLAngleLoc());
9349 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009350 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9351 E->getNumTemplateArgs(),
9352 TransArgs))
9353 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009355
Douglas Gregora16548e2009-08-11 05:31:07 +00009356 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009357 SourceLocation FakeOperatorLoc =
9358 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009359
John McCall38836f02010-01-15 08:34:02 +00009360 // FIXME: to do this check properly, we will need to preserve the
9361 // first-qualifier-in-scope here, just in case we had a dependent
9362 // base (and therefore couldn't do the check) and a
9363 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009364 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009365 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9366 if (MemberNameInfo.getName()) {
9367 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9368 if (!MemberNameInfo.getName())
9369 return ExprError();
9370 }
John McCall38836f02010-01-15 08:34:02 +00009371
John McCallb268a282010-08-23 23:25:46 +00009372 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009373 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009374 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009375 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009376 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009377 Member,
John McCall16df1e52010-03-30 21:47:33 +00009378 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009379 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009380 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009381 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009382}
Mike Stump11289f42009-09-09 15:08:12 +00009383
Douglas Gregora16548e2009-08-11 05:31:07 +00009384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009385ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009386TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009387 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009388 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009390
John McCalldadc5752010-08-24 06:29:42 +00009391 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009392 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009393 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009394
Douglas Gregora16548e2009-08-11 05:31:07 +00009395 if (!getDerived().AlwaysRebuild() &&
9396 LHS.get() == E->getLHS() &&
9397 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009398 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009399
Lang Hames5de91cc2012-10-02 04:45:10 +00009400 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009401 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009402
Douglas Gregora16548e2009-08-11 05:31:07 +00009403 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009404 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009405}
9406
Mike Stump11289f42009-09-09 15:08:12 +00009407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009408ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009409TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009410 CompoundAssignOperator *E) {
9411 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009412}
Mike Stump11289f42009-09-09 15:08:12 +00009413
Douglas Gregora16548e2009-08-11 05:31:07 +00009414template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009415ExprResult TreeTransform<Derived>::
9416TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9417 // Just rebuild the common and RHS expressions and see whether we
9418 // get any changes.
9419
9420 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9421 if (commonExpr.isInvalid())
9422 return ExprError();
9423
9424 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9425 if (rhs.isInvalid())
9426 return ExprError();
9427
9428 if (!getDerived().AlwaysRebuild() &&
9429 commonExpr.get() == e->getCommon() &&
9430 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009431 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009432
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009433 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009434 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009435 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009436 e->getColonLoc(),
9437 rhs.get());
9438}
9439
9440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009442TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009443 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009444 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009446
John McCalldadc5752010-08-24 06:29:42 +00009447 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009448 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009450
John McCalldadc5752010-08-24 06:29:42 +00009451 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009452 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009454
Douglas Gregora16548e2009-08-11 05:31:07 +00009455 if (!getDerived().AlwaysRebuild() &&
9456 Cond.get() == E->getCond() &&
9457 LHS.get() == E->getLHS() &&
9458 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009459 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009460
John McCallb268a282010-08-23 23:25:46 +00009461 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009462 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009463 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009464 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009465 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009466}
Mike Stump11289f42009-09-09 15:08:12 +00009467
9468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009469ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009470TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009471 // Implicit casts are eliminated during transformation, since they
9472 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009473 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009474}
Mike Stump11289f42009-09-09 15:08:12 +00009475
Douglas Gregora16548e2009-08-11 05:31:07 +00009476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009478TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009479 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9480 if (!Type)
9481 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009482
John McCalldadc5752010-08-24 06:29:42 +00009483 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009484 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009485 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009487
Douglas Gregora16548e2009-08-11 05:31:07 +00009488 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009489 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009490 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009491 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009492
John McCall97513962010-01-15 18:39:57 +00009493 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009494 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009495 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009496 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009497}
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>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009502 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9503 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9504 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009506
John McCalldadc5752010-08-24 06:29:42 +00009507 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009508 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009510
Douglas Gregora16548e2009-08-11 05:31:07 +00009511 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009512 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009513 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009514 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009515
John McCall5d7aa7f2010-01-19 22:33:45 +00009516 // Note: the expression type doesn't necessarily match the
9517 // type-as-written, but that's okay, because it should always be
9518 // derivable from the initializer.
9519
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009520 return getDerived().RebuildCompoundLiteralExpr(
9521 E->getLParenLoc(), NewT,
9522 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009523}
Mike Stump11289f42009-09-09 15:08:12 +00009524
Douglas Gregora16548e2009-08-11 05:31:07 +00009525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009526ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009527TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009528 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009529 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009531
Douglas Gregora16548e2009-08-11 05:31:07 +00009532 if (!getDerived().AlwaysRebuild() &&
9533 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009534 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009535
Douglas Gregora16548e2009-08-11 05:31:07 +00009536 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009537 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009538 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009539 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009540 E->getAccessorLoc(),
9541 E->getAccessor());
9542}
Mike Stump11289f42009-09-09 15:08:12 +00009543
Douglas Gregora16548e2009-08-11 05:31:07 +00009544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009545ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009546TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009547 if (InitListExpr *Syntactic = E->getSyntacticForm())
9548 E = Syntactic;
9549
Douglas Gregora16548e2009-08-11 05:31:07 +00009550 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009551
Benjamin Kramerf0623432012-08-23 22:51:59 +00009552 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009553 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009554 Inits, &InitChanged))
9555 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009556
Richard Smith520449d2015-02-05 06:15:50 +00009557 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9558 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9559 // in some cases. We can't reuse it in general, because the syntactic and
9560 // semantic forms are linked, and we can't know that semantic form will
9561 // match even if the syntactic form does.
9562 }
Mike Stump11289f42009-09-09 15:08:12 +00009563
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009564 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009565 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009566}
Mike Stump11289f42009-09-09 15:08:12 +00009567
Douglas Gregora16548e2009-08-11 05:31:07 +00009568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009569ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009570TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009571 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009572
Douglas Gregorebe10102009-08-20 07:17:43 +00009573 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009574 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009575 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009577
Douglas Gregorebe10102009-08-20 07:17:43 +00009578 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009579 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009580 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009581 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9582 if (D.isFieldDesignator()) {
9583 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9584 D.getDotLoc(),
9585 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009586 if (D.getField()) {
9587 FieldDecl *Field = cast_or_null<FieldDecl>(
9588 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9589 if (Field != D.getField())
9590 // Rebuild the expression when the transformed FieldDecl is
9591 // different to the already assigned FieldDecl.
9592 ExprChanged = true;
9593 } else {
9594 // Ensure that the designator expression is rebuilt when there isn't
9595 // a resolved FieldDecl in the designator as we don't want to assign
9596 // a FieldDecl to a pattern designator that will be instantiated again.
9597 ExprChanged = true;
9598 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009599 continue;
9600 }
Mike Stump11289f42009-09-09 15:08:12 +00009601
David Majnemerf7e36092016-06-23 00:15:04 +00009602 if (D.isArrayDesignator()) {
9603 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009604 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009605 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009606
David Majnemerf7e36092016-06-23 00:15:04 +00009607 Desig.AddDesignator(
9608 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009609
David Majnemerf7e36092016-06-23 00:15:04 +00009610 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009611 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009612 continue;
9613 }
Mike Stump11289f42009-09-09 15:08:12 +00009614
David Majnemerf7e36092016-06-23 00:15:04 +00009615 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009616 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009617 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009618 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009619 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009620
David Majnemerf7e36092016-06-23 00:15:04 +00009621 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009622 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009624
9625 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009626 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009627 D.getLBracketLoc(),
9628 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009629
David Majnemerf7e36092016-06-23 00:15:04 +00009630 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9631 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009632
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009633 ArrayExprs.push_back(Start.get());
9634 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009635 }
Mike Stump11289f42009-09-09 15:08:12 +00009636
Douglas Gregora16548e2009-08-11 05:31:07 +00009637 if (!getDerived().AlwaysRebuild() &&
9638 Init.get() == E->getInit() &&
9639 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009640 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009641
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009642 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009643 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009644 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009645}
Mike Stump11289f42009-09-09 15:08:12 +00009646
Yunzhong Gaocb779302015-06-10 00:27:52 +00009647// Seems that if TransformInitListExpr() only works on the syntactic form of an
9648// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9649template<typename Derived>
9650ExprResult
9651TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9652 DesignatedInitUpdateExpr *E) {
9653 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9654 "initializer");
9655 return ExprError();
9656}
9657
9658template<typename Derived>
9659ExprResult
9660TreeTransform<Derived>::TransformNoInitExpr(
9661 NoInitExpr *E) {
9662 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9663 return ExprError();
9664}
9665
Douglas Gregora16548e2009-08-11 05:31:07 +00009666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009667ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009668TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9669 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9670 return ExprError();
9671}
9672
9673template<typename Derived>
9674ExprResult
9675TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9676 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9677 return ExprError();
9678}
9679
9680template<typename Derived>
9681ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009682TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009683 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009684 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009685
Douglas Gregor3da3c062009-10-28 00:29:27 +00009686 // FIXME: Will we ever have proper type location here? Will we actually
9687 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009688 QualType T = getDerived().TransformType(E->getType());
9689 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009690 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009691
Douglas Gregora16548e2009-08-11 05:31:07 +00009692 if (!getDerived().AlwaysRebuild() &&
9693 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009694 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009695
Douglas Gregora16548e2009-08-11 05:31:07 +00009696 return getDerived().RebuildImplicitValueInitExpr(T);
9697}
Mike Stump11289f42009-09-09 15:08:12 +00009698
Douglas Gregora16548e2009-08-11 05:31:07 +00009699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009700ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009701TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009702 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9703 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009705
John McCalldadc5752010-08-24 06:29:42 +00009706 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009707 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009708 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009709
Douglas Gregora16548e2009-08-11 05:31:07 +00009710 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009711 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009712 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009713 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009714
John McCallb268a282010-08-23 23:25:46 +00009715 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009716 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009717}
9718
9719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009721TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009722 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009723 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009724 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9725 &ArgumentChanged))
9726 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009727
Douglas Gregora16548e2009-08-11 05:31:07 +00009728 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009729 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009730 E->getRParenLoc());
9731}
Mike Stump11289f42009-09-09 15:08:12 +00009732
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009733/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00009734///
9735/// By default, the transformation of an address-of-label expression always
9736/// rebuilds the expression, so that the label identifier can be resolved to
9737/// the corresponding label statement by semantic analysis.
9738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009740TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009741 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9742 E->getLabel());
9743 if (!LD)
9744 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009745
Douglas Gregora16548e2009-08-11 05:31:07 +00009746 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009747 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009748}
Mike Stump11289f42009-09-09 15:08:12 +00009749
9750template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009751ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009752TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009753 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009754 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009755 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009756 if (SubStmt.isInvalid()) {
9757 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009758 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009759 }
Mike Stump11289f42009-09-09 15:08:12 +00009760
Douglas Gregora16548e2009-08-11 05:31:07 +00009761 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009762 SubStmt.get() == E->getSubStmt()) {
9763 // Calling this an 'error' is unintuitive, but it does the right thing.
9764 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009765 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009766 }
Mike Stump11289f42009-09-09 15:08:12 +00009767
9768 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009769 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009770 E->getRParenLoc());
9771}
Mike Stump11289f42009-09-09 15:08:12 +00009772
Douglas Gregora16548e2009-08-11 05:31:07 +00009773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009774ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009775TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009776 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009777 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009779
John McCalldadc5752010-08-24 06:29:42 +00009780 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009783
John McCalldadc5752010-08-24 06:29:42 +00009784 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009785 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009787
Douglas Gregora16548e2009-08-11 05:31:07 +00009788 if (!getDerived().AlwaysRebuild() &&
9789 Cond.get() == E->getCond() &&
9790 LHS.get() == E->getLHS() &&
9791 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009792 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009793
Douglas Gregora16548e2009-08-11 05:31:07 +00009794 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009795 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009796 E->getRParenLoc());
9797}
Mike Stump11289f42009-09-09 15:08:12 +00009798
Douglas Gregora16548e2009-08-11 05:31:07 +00009799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009801TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009803}
9804
9805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009807TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009808 switch (E->getOperator()) {
9809 case OO_New:
9810 case OO_Delete:
9811 case OO_Array_New:
9812 case OO_Array_Delete:
9813 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009814
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009815 case OO_Call: {
9816 // This is a call to an object's operator().
9817 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9818
9819 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009820 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009821 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009822 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009823
9824 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009825 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009826 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009827
9828 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009829 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009830 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009831 Args))
9832 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009833
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009834 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
9835 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009836 }
9837
9838#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9839 case OO_##Name:
9840#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9841#include "clang/Basic/OperatorKinds.def"
9842 case OO_Subscript:
9843 // Handled below.
9844 break;
9845
9846 case OO_Conditional:
9847 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009848
9849 case OO_None:
9850 case NUM_OVERLOADED_OPERATORS:
9851 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009852 }
9853
John McCalldadc5752010-08-24 06:29:42 +00009854 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009855 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009856 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009857
Richard Smithdb2630f2012-10-21 03:28:35 +00009858 ExprResult First;
9859 if (E->getOperator() == OO_Amp)
9860 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9861 else
9862 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009863 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009864 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009865
John McCalldadc5752010-08-24 06:29:42 +00009866 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009867 if (E->getNumArgs() == 2) {
9868 Second = getDerived().TransformExpr(E->getArg(1));
9869 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009870 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009871 }
Mike Stump11289f42009-09-09 15:08:12 +00009872
Douglas Gregora16548e2009-08-11 05:31:07 +00009873 if (!getDerived().AlwaysRebuild() &&
9874 Callee.get() == E->getCallee() &&
9875 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009876 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009877 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009878
Lang Hames5de91cc2012-10-02 04:45:10 +00009879 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009880 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009881
Douglas Gregora16548e2009-08-11 05:31:07 +00009882 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9883 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009884 Callee.get(),
9885 First.get(),
9886 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009887}
Mike Stump11289f42009-09-09 15:08:12 +00009888
Douglas Gregora16548e2009-08-11 05:31:07 +00009889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009891TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9892 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009893}
Mike Stump11289f42009-09-09 15:08:12 +00009894
Douglas Gregora16548e2009-08-11 05:31:07 +00009895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009896ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009897TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9898 // Transform the callee.
9899 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9900 if (Callee.isInvalid())
9901 return ExprError();
9902
9903 // Transform exec config.
9904 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9905 if (EC.isInvalid())
9906 return ExprError();
9907
9908 // Transform arguments.
9909 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009910 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009911 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009912 &ArgChanged))
9913 return ExprError();
9914
9915 if (!getDerived().AlwaysRebuild() &&
9916 Callee.get() == E->getCallee() &&
9917 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009918 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009919
9920 // FIXME: Wrong source location information for the '('.
9921 SourceLocation FakeLParenLoc
9922 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9923 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009924 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009925 E->getRParenLoc(), EC.get());
9926}
9927
9928template<typename Derived>
9929ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009930TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009931 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9932 if (!Type)
9933 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009934
John McCalldadc5752010-08-24 06:29:42 +00009935 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009936 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009937 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009938 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009939
Douglas Gregora16548e2009-08-11 05:31:07 +00009940 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009941 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009942 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009943 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009944 return getDerived().RebuildCXXNamedCastExpr(
9945 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9946 Type, E->getAngleBrackets().getEnd(),
9947 // FIXME. this should be '(' location
9948 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009949}
Mike Stump11289f42009-09-09 15:08:12 +00009950
Douglas Gregora16548e2009-08-11 05:31:07 +00009951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009953TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9954 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009955}
Mike Stump11289f42009-09-09 15:08:12 +00009956
9957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009959TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9960 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009961}
9962
Douglas Gregora16548e2009-08-11 05:31:07 +00009963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009964ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009965TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009966 CXXReinterpretCastExpr *E) {
9967 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009968}
Mike Stump11289f42009-09-09 15:08:12 +00009969
Douglas Gregora16548e2009-08-11 05:31:07 +00009970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009972TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9973 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009974}
Mike Stump11289f42009-09-09 15:08:12 +00009975
Douglas Gregora16548e2009-08-11 05:31:07 +00009976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009977ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009978TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009979 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009980 TypeSourceInfo *Type =
9981 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009982 if (!Type)
9983 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009984
John McCalldadc5752010-08-24 06:29:42 +00009985 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009986 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009987 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009989
Douglas Gregora16548e2009-08-11 05:31:07 +00009990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009991 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009992 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009993 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009994
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009995 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009996 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009997 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +00009998 E->getRParenLoc(),
9999 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010000}
Mike Stump11289f42009-09-09 15:08:12 +000010001
Douglas Gregora16548e2009-08-11 05:31:07 +000010002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010003ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010004TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010005 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010006 TypeSourceInfo *TInfo
10007 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10008 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010010
Douglas Gregora16548e2009-08-11 05:31:07 +000010011 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010012 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010013 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010014
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010015 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010016 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010017 }
Mike Stump11289f42009-09-09 15:08:12 +000010018
Eli Friedman456f0182012-01-20 01:26:23 +000010019 // We don't know whether the subexpression is potentially evaluated until
10020 // after we perform semantic analysis. We speculatively assume it is
10021 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010022 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010023 EnterExpressionEvaluationContext Unevaluated(
10024 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10025 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010026
John McCalldadc5752010-08-24 06:29:42 +000010027 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010028 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010029 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010030
Douglas Gregora16548e2009-08-11 05:31:07 +000010031 if (!getDerived().AlwaysRebuild() &&
10032 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010033 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010034
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010035 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010036 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010037}
10038
10039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010040ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010041TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10042 if (E->isTypeOperand()) {
10043 TypeSourceInfo *TInfo
10044 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10045 if (!TInfo)
10046 return ExprError();
10047
10048 if (!getDerived().AlwaysRebuild() &&
10049 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010050 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010051
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010052 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010053 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010054 }
10055
Faisal Valid143a0c2017-04-01 21:30:49 +000010056 EnterExpressionEvaluationContext Unevaluated(
10057 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010058
10059 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10060 if (SubExpr.isInvalid())
10061 return ExprError();
10062
10063 if (!getDerived().AlwaysRebuild() &&
10064 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010065 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010066
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010067 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010068 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010069}
10070
10071template<typename Derived>
10072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010073TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010074 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010075}
Mike Stump11289f42009-09-09 15:08:12 +000010076
Douglas Gregora16548e2009-08-11 05:31:07 +000010077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010078ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010079TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010080 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010081 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010082}
Mike Stump11289f42009-09-09 15:08:12 +000010083
Douglas Gregora16548e2009-08-11 05:31:07 +000010084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010086TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010087 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010088
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010089 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10090 // Make sure that we capture 'this'.
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010091 getSema().CheckCXXThisCapture(E->getBeginLoc());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010092 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010093 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010094
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010095 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010096}
Mike Stump11289f42009-09-09 15:08:12 +000010097
Douglas Gregora16548e2009-08-11 05:31:07 +000010098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010100TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010101 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010102 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010103 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010104
Douglas Gregora16548e2009-08-11 05:31:07 +000010105 if (!getDerived().AlwaysRebuild() &&
10106 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010107 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010108
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010109 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10110 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010111}
Mike Stump11289f42009-09-09 15:08:12 +000010112
Douglas Gregora16548e2009-08-11 05:31:07 +000010113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010115TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010116 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10117 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010118 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010120
Chandler Carruth794da4c2010-02-08 06:42:49 +000010121 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010122 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010123 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010124
Douglas Gregor033f6752009-12-23 23:03:06 +000010125 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010126}
Mike Stump11289f42009-09-09 15:08:12 +000010127
Douglas Gregora16548e2009-08-11 05:31:07 +000010128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010129ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010130TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010131 FieldDecl *Field = cast_or_null<FieldDecl>(
10132 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010133 if (!Field)
10134 return ExprError();
10135
10136 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010137 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010138
10139 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10140}
10141
10142template<typename Derived>
10143ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010144TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10145 CXXScalarValueInitExpr *E) {
10146 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10147 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010148 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010149
Douglas Gregora16548e2009-08-11 05:31:07 +000010150 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010151 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010152 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010153
Chad Rosier1dcde962012-08-08 18:46:20 +000010154 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010155 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010156 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010157}
Mike Stump11289f42009-09-09 15:08:12 +000010158
Douglas Gregora16548e2009-08-11 05:31:07 +000010159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010161TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010162 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010163 TypeSourceInfo *AllocTypeInfo =
10164 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010165 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010167
Douglas Gregora16548e2009-08-11 05:31:07 +000010168 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010169 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010170 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010172
Douglas Gregora16548e2009-08-11 05:31:07 +000010173 // Transform the placement arguments (if any).
10174 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010175 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010176 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010177 E->getNumPlacementArgs(), true,
10178 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010180
Sebastian Redl6047f072012-02-16 12:22:20 +000010181 // Transform the initializer (if any).
10182 Expr *OldInit = E->getInitializer();
10183 ExprResult NewInit;
10184 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010185 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010186 if (NewInit.isInvalid())
10187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010188
Sebastian Redl6047f072012-02-16 12:22:20 +000010189 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010190 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010191 if (E->getOperatorNew()) {
10192 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010193 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010194 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010195 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010196 }
10197
Craig Topperc3ec1492014-05-26 06:22:03 +000010198 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010199 if (E->getOperatorDelete()) {
10200 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010201 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010202 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010203 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010204 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010205
Douglas Gregora16548e2009-08-11 05:31:07 +000010206 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010207 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010208 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010209 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010210 OperatorNew == E->getOperatorNew() &&
10211 OperatorDelete == E->getOperatorDelete() &&
10212 !ArgumentChanged) {
10213 // Mark any declarations we need as referenced.
10214 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010215 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010216 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010217 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010218 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010219
Sebastian Redl6047f072012-02-16 12:22:20 +000010220 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010221 QualType ElementType
10222 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10223 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10224 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10225 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010226 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010227 }
10228 }
10229 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010230
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010231 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010232 }
Mike Stump11289f42009-09-09 15:08:12 +000010233
Douglas Gregor0744ef62010-09-07 21:49:58 +000010234 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010235 if (!ArraySize.get()) {
10236 // If no array size was specified, but the new expression was
10237 // instantiated with an array type (e.g., "new T" where T is
10238 // instantiated with "int[4]"), extract the outer bound from the
10239 // array type as our array size. We do this with constant and
10240 // dependently-sized array types.
10241 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10242 if (!ArrayT) {
10243 // Do nothing
10244 } else if (const ConstantArrayType *ConsArrayT
10245 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010246 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10247 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010248 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010249 AllocType = ConsArrayT->getElementType();
10250 } else if (const DependentSizedArrayType *DepArrayT
10251 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10252 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010253 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010254 AllocType = DepArrayT->getElementType();
10255 }
10256 }
10257 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010258
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010259 return getDerived().RebuildCXXNewExpr(
10260 E->getBeginLoc(), E->isGlobalNew(),
10261 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10262 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
10263 AllocTypeInfo, ArraySize.get(), E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010264}
Mike Stump11289f42009-09-09 15:08:12 +000010265
Douglas Gregora16548e2009-08-11 05:31:07 +000010266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010268TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010269 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010270 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010272
Douglas Gregord2d9da02010-02-26 00:38:10 +000010273 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010274 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010275 if (E->getOperatorDelete()) {
10276 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010277 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010278 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010279 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010280 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010281
Douglas Gregora16548e2009-08-11 05:31:07 +000010282 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010283 Operand.get() == E->getArgument() &&
10284 OperatorDelete == E->getOperatorDelete()) {
10285 // Mark any declarations we need as referenced.
10286 // FIXME: instantiation-specific.
10287 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010288 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010289
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010290 if (!E->getArgument()->isTypeDependent()) {
10291 QualType Destroyed = SemaRef.Context.getBaseElementType(
10292 E->getDestroyedType());
10293 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10294 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010295 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010296 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010297 }
10298 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010299
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010300 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010301 }
Mike Stump11289f42009-09-09 15:08:12 +000010302
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010303 return getDerived().RebuildCXXDeleteExpr(
10304 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010305}
Mike Stump11289f42009-09-09 15:08:12 +000010306
Douglas Gregora16548e2009-08-11 05:31:07 +000010307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010308ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010309TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010310 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010311 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010312 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010314
John McCallba7bf592010-08-24 05:47:05 +000010315 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010316 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010317 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010318 E->getOperatorLoc(),
10319 E->isArrow()? tok::arrow : tok::period,
10320 ObjectTypePtr,
10321 MayBePseudoDestructor);
10322 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010323 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010324
John McCallba7bf592010-08-24 05:47:05 +000010325 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010326 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10327 if (QualifierLoc) {
10328 QualifierLoc
10329 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10330 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010331 return ExprError();
10332 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010333 CXXScopeSpec SS;
10334 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010335
Douglas Gregor678f90d2010-02-25 01:56:36 +000010336 PseudoDestructorTypeStorage Destroyed;
10337 if (E->getDestroyedTypeInfo()) {
10338 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010339 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010340 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010341 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010342 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010343 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010344 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010345 // We aren't likely to be able to resolve the identifier down to a type
10346 // now anyway, so just retain the identifier.
10347 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10348 E->getDestroyedTypeLoc());
10349 } else {
10350 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010351 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010352 *E->getDestroyedTypeIdentifier(),
10353 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010354 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010355 SS, ObjectTypePtr,
10356 false);
10357 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010358 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010359
Douglas Gregor678f90d2010-02-25 01:56:36 +000010360 Destroyed
10361 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10362 E->getDestroyedTypeLoc());
10363 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010364
Craig Topperc3ec1492014-05-26 06:22:03 +000010365 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010366 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010367 CXXScopeSpec EmptySS;
10368 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010369 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010370 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010371 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010372 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010373
John McCallb268a282010-08-23 23:25:46 +000010374 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010375 E->getOperatorLoc(),
10376 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010377 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010378 ScopeTypeInfo,
10379 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010380 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010381 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010382}
Mike Stump11289f42009-09-09 15:08:12 +000010383
Richard Smith151c4562016-12-20 21:35:28 +000010384template <typename Derived>
10385bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10386 bool RequiresADL,
10387 LookupResult &R) {
10388 // Transform all the decls.
10389 bool AllEmptyPacks = true;
10390 for (auto *OldD : Old->decls()) {
10391 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10392 if (!InstD) {
10393 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10394 // This can happen because of dependent hiding.
10395 if (isa<UsingShadowDecl>(OldD))
10396 continue;
10397 else {
10398 R.clear();
10399 return true;
10400 }
10401 }
10402
10403 // Expand using pack declarations.
10404 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10405 ArrayRef<NamedDecl*> Decls = SingleDecl;
10406 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10407 Decls = UPD->expansions();
10408
10409 // Expand using declarations.
10410 for (auto *D : Decls) {
10411 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10412 for (auto *SD : UD->shadows())
10413 R.addDecl(SD);
10414 } else {
10415 R.addDecl(D);
10416 }
10417 }
10418
10419 AllEmptyPacks &= Decls.empty();
10420 };
10421
10422 // C++ [temp.res]/8.4.2:
10423 // The program is ill-formed, no diagnostic required, if [...] lookup for
10424 // a name in the template definition found a using-declaration, but the
10425 // lookup in the corresponding scope in the instantiation odoes not find
10426 // any declarations because the using-declaration was a pack expansion and
10427 // the corresponding pack is empty
10428 if (AllEmptyPacks && !RequiresADL) {
10429 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010430 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010431 return true;
10432 }
10433
10434 // Resolve a kind, but don't do any further analysis. If it's
10435 // ambiguous, the callee needs to deal with it.
10436 R.resolveKind();
10437 return false;
10438}
10439
Douglas Gregorad8a3362009-09-04 17:36:40 +000010440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010441ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010442TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010443 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010444 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10445 Sema::LookupOrdinaryName);
10446
Richard Smith151c4562016-12-20 21:35:28 +000010447 // Transform the declaration set.
10448 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10449 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010450
10451 // Rebuild the nested-name qualifier, if present.
10452 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010453 if (Old->getQualifierLoc()) {
10454 NestedNameSpecifierLoc QualifierLoc
10455 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10456 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010457 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010458
Douglas Gregor0da1d432011-02-28 20:01:57 +000010459 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010460 }
10461
Douglas Gregor9262f472010-04-27 18:19:34 +000010462 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010463 CXXRecordDecl *NamingClass
10464 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10465 Old->getNameLoc(),
10466 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010467 if (!NamingClass) {
10468 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010469 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010470 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010471
Douglas Gregorda7be082010-04-27 16:10:10 +000010472 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010473 }
10474
Abramo Bagnara7945c982012-01-27 09:46:47 +000010475 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10476
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010477 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010478 // it's a normal declaration name or member reference.
10479 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10480 NamedDecl *D = R.getAsSingle<NamedDecl>();
10481 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10482 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10483 // give a good diagnostic.
10484 if (D && D->isCXXInstanceMember()) {
10485 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10486 /*TemplateArgs=*/nullptr,
10487 /*Scope=*/nullptr);
10488 }
10489
John McCalle66edc12009-11-24 19:00:30 +000010490 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010491 }
John McCalle66edc12009-11-24 19:00:30 +000010492
10493 // If we have template arguments, rebuild them, then rebuild the
10494 // templateid expression.
10495 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010496 if (Old->hasExplicitTemplateArgs() &&
10497 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010498 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010499 TransArgs)) {
10500 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010501 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010502 }
John McCalle66edc12009-11-24 19:00:30 +000010503
Abramo Bagnara7945c982012-01-27 09:46:47 +000010504 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010505 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010506}
Mike Stump11289f42009-09-09 15:08:12 +000010507
Douglas Gregora16548e2009-08-11 05:31:07 +000010508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010509ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010510TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10511 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010512 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010513 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10514 TypeSourceInfo *From = E->getArg(I);
10515 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010516 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010517 TypeLocBuilder TLB;
10518 TLB.reserve(FromTL.getFullDataSize());
10519 QualType To = getDerived().TransformType(TLB, FromTL);
10520 if (To.isNull())
10521 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010522
Douglas Gregor29c42f22012-02-24 07:38:34 +000010523 if (To == From->getType())
10524 Args.push_back(From);
10525 else {
10526 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10527 ArgChanged = true;
10528 }
10529 continue;
10530 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010531
Douglas Gregor29c42f22012-02-24 07:38:34 +000010532 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010533
Douglas Gregor29c42f22012-02-24 07:38:34 +000010534 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010535 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010536 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10537 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10538 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010539
Douglas Gregor29c42f22012-02-24 07:38:34 +000010540 // Determine whether the set of unexpanded parameter packs can and should
10541 // be expanded.
10542 bool Expand = true;
10543 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010544 Optional<unsigned> OrigNumExpansions =
10545 ExpansionTL.getTypePtr()->getNumExpansions();
10546 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010547 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10548 PatternTL.getSourceRange(),
10549 Unexpanded,
10550 Expand, RetainExpansion,
10551 NumExpansions))
10552 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010553
Douglas Gregor29c42f22012-02-24 07:38:34 +000010554 if (!Expand) {
10555 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010556 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010557 // expansion.
10558 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010559
Douglas Gregor29c42f22012-02-24 07:38:34 +000010560 TypeLocBuilder TLB;
10561 TLB.reserve(From->getTypeLoc().getFullDataSize());
10562
10563 QualType To = getDerived().TransformType(TLB, PatternTL);
10564 if (To.isNull())
10565 return ExprError();
10566
Chad Rosier1dcde962012-08-08 18:46:20 +000010567 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010568 PatternTL.getSourceRange(),
10569 ExpansionTL.getEllipsisLoc(),
10570 NumExpansions);
10571 if (To.isNull())
10572 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010573
Douglas Gregor29c42f22012-02-24 07:38:34 +000010574 PackExpansionTypeLoc ToExpansionTL
10575 = TLB.push<PackExpansionTypeLoc>(To);
10576 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10577 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10578 continue;
10579 }
10580
10581 // Expand the pack expansion by substituting for each argument in the
10582 // pack(s).
10583 for (unsigned I = 0; I != *NumExpansions; ++I) {
10584 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10585 TypeLocBuilder TLB;
10586 TLB.reserve(PatternTL.getFullDataSize());
10587 QualType To = getDerived().TransformType(TLB, PatternTL);
10588 if (To.isNull())
10589 return ExprError();
10590
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010591 if (To->containsUnexpandedParameterPack()) {
10592 To = getDerived().RebuildPackExpansionType(To,
10593 PatternTL.getSourceRange(),
10594 ExpansionTL.getEllipsisLoc(),
10595 NumExpansions);
10596 if (To.isNull())
10597 return ExprError();
10598
10599 PackExpansionTypeLoc ToExpansionTL
10600 = TLB.push<PackExpansionTypeLoc>(To);
10601 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10602 }
10603
Douglas Gregor29c42f22012-02-24 07:38:34 +000010604 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10605 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010606
Douglas Gregor29c42f22012-02-24 07:38:34 +000010607 if (!RetainExpansion)
10608 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010609
Douglas Gregor29c42f22012-02-24 07:38:34 +000010610 // If we're supposed to retain a pack expansion, do so by temporarily
10611 // forgetting the partially-substituted parameter pack.
10612 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10613
10614 TypeLocBuilder TLB;
10615 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010616
Douglas Gregor29c42f22012-02-24 07:38:34 +000010617 QualType To = getDerived().TransformType(TLB, PatternTL);
10618 if (To.isNull())
10619 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010620
10621 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010622 PatternTL.getSourceRange(),
10623 ExpansionTL.getEllipsisLoc(),
10624 NumExpansions);
10625 if (To.isNull())
10626 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010627
Douglas Gregor29c42f22012-02-24 07:38:34 +000010628 PackExpansionTypeLoc ToExpansionTL
10629 = TLB.push<PackExpansionTypeLoc>(To);
10630 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10631 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10632 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010633
Douglas Gregor29c42f22012-02-24 07:38:34 +000010634 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010635 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010636
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010637 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010638 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000010639}
10640
10641template<typename Derived>
10642ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010643TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10644 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10645 if (!T)
10646 return ExprError();
10647
10648 if (!getDerived().AlwaysRebuild() &&
10649 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010650 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010651
10652 ExprResult SubExpr;
10653 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010654 EnterExpressionEvaluationContext Unevaluated(
10655 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010656 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10657 if (SubExpr.isInvalid())
10658 return ExprError();
10659
10660 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010661 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010662 }
10663
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010664 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010665 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000010666}
10667
10668template<typename Derived>
10669ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010670TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10671 ExprResult SubExpr;
10672 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010673 EnterExpressionEvaluationContext Unevaluated(
10674 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010675 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10676 if (SubExpr.isInvalid())
10677 return ExprError();
10678
10679 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010680 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010681 }
10682
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010683 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010684 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000010685}
10686
Reid Kleckner32506ed2014-06-12 23:03:48 +000010687template <typename Derived>
10688ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10689 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10690 TypeSourceInfo **RecoveryTSI) {
10691 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10692 DRE, AddrTaken, RecoveryTSI);
10693
10694 // Propagate both errors and recovered types, which return ExprEmpty.
10695 if (!NewDRE.isUsable())
10696 return NewDRE;
10697
10698 // We got an expr, wrap it up in parens.
10699 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10700 return PE;
10701 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10702 PE->getRParen());
10703}
10704
10705template <typename Derived>
10706ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10707 DependentScopeDeclRefExpr *E) {
10708 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10709 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010710}
10711
10712template<typename Derived>
10713ExprResult
10714TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10715 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010716 bool IsAddressOfOperand,
10717 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010718 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010719 NestedNameSpecifierLoc QualifierLoc
10720 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10721 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010722 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010723 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010724
John McCall31f82722010-11-12 08:19:04 +000010725 // TODO: If this is a conversion-function-id, verify that the
10726 // destination type name (if present) resolves the same way after
10727 // instantiation as it did in the local scope.
10728
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010729 DeclarationNameInfo NameInfo
10730 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10731 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010733
John McCalle66edc12009-11-24 19:00:30 +000010734 if (!E->hasExplicitTemplateArgs()) {
10735 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010736 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010737 // Note: it is sufficient to compare the Name component of NameInfo:
10738 // if name has not changed, DNLoc has not changed either.
10739 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010740 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010741
Reid Kleckner32506ed2014-06-12 23:03:48 +000010742 return getDerived().RebuildDependentScopeDeclRefExpr(
10743 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10744 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010745 }
John McCall6b51f282009-11-23 01:53:49 +000010746
10747 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010748 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10749 E->getNumTemplateArgs(),
10750 TransArgs))
10751 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010752
Reid Kleckner32506ed2014-06-12 23:03:48 +000010753 return getDerived().RebuildDependentScopeDeclRefExpr(
10754 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10755 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010756}
10757
10758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010760TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010761 // CXXConstructExprs other than for list-initialization and
10762 // CXXTemporaryObjectExpr are always implicit, so when we have
10763 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010764 if ((E->getNumArgs() == 1 ||
10765 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010766 (!getDerived().DropCallArgument(E->getArg(0))) &&
10767 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010768 return getDerived().TransformExpr(E->getArg(0));
10769
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010770 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000010771
10772 QualType T = getDerived().TransformType(E->getType());
10773 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010774 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010775
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010776 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10777 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010778 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010780
Douglas Gregora16548e2009-08-11 05:31:07 +000010781 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010782 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010783 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010784 &ArgumentChanged))
10785 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010786
Douglas Gregora16548e2009-08-11 05:31:07 +000010787 if (!getDerived().AlwaysRebuild() &&
10788 T == E->getType() &&
10789 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010790 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010791 // Mark the constructor as referenced.
10792 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010793 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010794 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010795 }
Mike Stump11289f42009-09-09 15:08:12 +000010796
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010797 return getDerived().RebuildCXXConstructExpr(
10798 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
10799 E->hadMultipleCandidates(), E->isListInitialization(),
10800 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
10801 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010802}
Mike Stump11289f42009-09-09 15:08:12 +000010803
Richard Smith5179eb72016-06-28 19:03:57 +000010804template<typename Derived>
10805ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10806 CXXInheritedCtorInitExpr *E) {
10807 QualType T = getDerived().TransformType(E->getType());
10808 if (T.isNull())
10809 return ExprError();
10810
10811 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010812 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000010813 if (!Constructor)
10814 return ExprError();
10815
10816 if (!getDerived().AlwaysRebuild() &&
10817 T == E->getType() &&
10818 Constructor == E->getConstructor()) {
10819 // Mark the constructor as referenced.
10820 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010821 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000010822 return E;
10823 }
10824
10825 return getDerived().RebuildCXXInheritedCtorInitExpr(
10826 T, E->getLocation(), Constructor,
10827 E->constructsVBase(), E->inheritedFromVBase());
10828}
10829
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010830/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010831///
Douglas Gregor363b1512009-12-24 18:51:59 +000010832/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10833/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010836TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010837 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010838}
Mike Stump11289f42009-09-09 15:08:12 +000010839
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010840/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000010841/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010842///
John McCall5d413782010-12-06 08:20:24 +000010843/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010844/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010846ExprResult
John McCall5d413782010-12-06 08:20:24 +000010847TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010848 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010849}
Mike Stump11289f42009-09-09 15:08:12 +000010850
Douglas Gregora16548e2009-08-11 05:31:07 +000010851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010852ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010853TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010854 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010855 TypeSourceInfo *T =
10856 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010857 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010859
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010860 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10861 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010862 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010864
Douglas Gregora16548e2009-08-11 05:31:07 +000010865 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010866 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010867 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010868 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010869 &ArgumentChanged))
10870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010871
Douglas Gregora16548e2009-08-11 05:31:07 +000010872 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010873 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010874 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010875 !ArgumentChanged) {
10876 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010877 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010878 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010879 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010880
Vedant Kumara14a1f92018-01-17 18:53:51 +000010881 // FIXME: We should just pass E->isListInitialization(), but we're not
10882 // prepared to handle list-initialization without a child InitListExpr.
10883 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
10884 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010885 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010886 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000010887}
Mike Stump11289f42009-09-09 15:08:12 +000010888
Douglas Gregora16548e2009-08-11 05:31:07 +000010889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010890ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010891TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010892 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010893 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010894 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010895 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10896 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010897 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010898 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010899 CEnd = E->capture_end();
10900 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010901 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010902 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010903 EnterExpressionEvaluationContext EEEC(
10904 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010905 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10906 C->getCapturedVar()->getInit(),
10907 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010908
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010909 if (NewExprInitResult.isInvalid())
10910 return ExprError();
10911 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010912
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010913 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010914 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010915 getSema().buildLambdaInitCaptureInitialization(
10916 C->getLocation(), OldVD->getType()->isReferenceType(),
10917 OldVD->getIdentifier(),
10918 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010919 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010920 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10921 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010922 }
10923
Faisal Vali2cba1332013-10-23 06:44:28 +000010924 // Transform the template parameters, and add them to the current
10925 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010926 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010927 E->getTemplateParameterList());
10928
Richard Smith01014ce2014-11-20 23:53:14 +000010929 // Transform the type of the original lambda's call operator.
10930 // The transformation MUST be done in the CurrentInstantiationScope since
10931 // it introduces a mapping of the original to the newly created
10932 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010933 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010934 {
10935 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000010936 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000010937 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010938
10939 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010940 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010941 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010942 QualType NewCallOpType = TransformFunctionProtoType(
10943 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010944 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10945 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10946 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010947 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010948 if (NewCallOpType.isNull())
10949 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010950 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10951 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010952 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010953
Richard Smithc38498f2015-04-27 21:27:54 +000010954 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10955 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10956 LSI->GLTemplateParameterList = TPL;
10957
Eli Friedmand564afb2012-09-19 01:18:11 +000010958 // Create the local class that will describe the lambda.
10959 CXXRecordDecl *Class
10960 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010961 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010962 /*KnownDependent=*/false,
10963 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010964 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10965
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010966 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010967 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10968 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010969 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000010970 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10971 E->getCallOperator()->isConstexpr());
10972
Faisal Vali2cba1332013-10-23 06:44:28 +000010973 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010974
Akira Hatanaka402818462016-12-16 21:16:57 +000010975 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10976 I != NumParams; ++I) {
10977 auto *P = NewCallOperator->getParamDecl(I);
10978 if (P->hasUninstantiatedDefaultArg()) {
10979 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000010980 getSema(),
10981 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000010982 ExprResult R = getDerived().TransformExpr(
10983 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10984 P->setDefaultArg(R.get());
10985 }
10986 }
10987
Faisal Vali2cba1332013-10-23 06:44:28 +000010988 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010989 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010990
Douglas Gregorb4328232012-02-14 00:00:48 +000010991 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010992 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010993 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010994
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010995 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010996 getSema().buildLambdaScope(LSI, NewCallOperator,
10997 E->getIntroducerRange(),
10998 E->getCaptureDefault(),
10999 E->getCaptureDefaultLoc(),
11000 E->hasExplicitParameters(),
11001 E->hasExplicitResultType(),
11002 E->isMutable());
11003
11004 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011005
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011006 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011007 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011008 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011009 CEnd = E->capture_end();
11010 C != CEnd; ++C) {
11011 // When we hit the first implicit capture, tell Sema that we've finished
11012 // the list of explicit captures.
11013 if (!FinishedExplicitCaptures && C->isImplicit()) {
11014 getSema().finishLambdaExplicitCaptures(LSI);
11015 FinishedExplicitCaptures = true;
11016 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011017
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011018 // Capturing 'this' is trivial.
11019 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011020 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11021 /*BuildAndDiagnose*/ true, nullptr,
11022 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011023 continue;
11024 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011025 // Captured expression will be recaptured during captured variables
11026 // rebuilding.
11027 if (C->capturesVLAType())
11028 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011029
Richard Smithba71c082013-05-16 06:20:58 +000011030 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011031 if (E->isInitCapture(C)) {
Fangrui Song6907ce22018-07-30 19:24:48 +000011032 InitCaptureInfoTy InitExprTypePair =
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011033 InitCaptureExprsAndTypes[C - E->capture_begin()];
11034 ExprResult Init = InitExprTypePair.first;
11035 QualType InitQualType = InitExprTypePair.second;
11036 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000011037 Invalid = true;
11038 continue;
11039 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011040 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011041 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000011042 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11043 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000011044 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000011045 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011046 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000011047 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011048 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011049 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000011050 continue;
11051 }
11052
11053 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11054
Douglas Gregor3e308b12012-02-14 19:27:52 +000011055 // Determine the capture kind for Sema.
11056 Sema::TryCaptureKind Kind
11057 = C->isImplicit()? Sema::TryCapture_Implicit
11058 : C->getCaptureKind() == LCK_ByCopy
11059 ? Sema::TryCapture_ExplicitByVal
11060 : Sema::TryCapture_ExplicitByRef;
11061 SourceLocation EllipsisLoc;
11062 if (C->isPackExpansion()) {
11063 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11064 bool ShouldExpand = false;
11065 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011066 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011067 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11068 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011069 Unexpanded,
11070 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011071 NumExpansions)) {
11072 Invalid = true;
11073 continue;
11074 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011075
Douglas Gregor3e308b12012-02-14 19:27:52 +000011076 if (ShouldExpand) {
11077 // The transform has determined that we should perform an expansion;
11078 // transform and capture each of the arguments.
11079 // expansion of the pattern. Do so.
11080 VarDecl *Pack = C->getCapturedVar();
11081 for (unsigned I = 0; I != *NumExpansions; ++I) {
11082 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11083 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011084 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011085 Pack));
11086 if (!CapturedVar) {
11087 Invalid = true;
11088 continue;
11089 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011090
Douglas Gregor3e308b12012-02-14 19:27:52 +000011091 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011092 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11093 }
Richard Smith9467be42014-06-06 17:33:35 +000011094
11095 // FIXME: Retain a pack expansion if RetainExpansion is true.
11096
Douglas Gregor3e308b12012-02-14 19:27:52 +000011097 continue;
11098 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011099
Douglas Gregor3e308b12012-02-14 19:27:52 +000011100 EllipsisLoc = C->getEllipsisLoc();
11101 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011102
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011103 // Transform the captured variable.
11104 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011105 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011106 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011107 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011108 Invalid = true;
11109 continue;
11110 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011111
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011112 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011113 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11114 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011115 }
11116 if (!FinishedExplicitCaptures)
11117 getSema().finishLambdaExplicitCaptures(LSI);
11118
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011119 // Enter a new evaluation context to insulate the lambda from any
11120 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011121 getSema().PushExpressionEvaluationContext(
11122 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011123
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011124 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011125 StmtResult Body =
11126 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11127
11128 // ActOnLambda* will pop the function scope for us.
11129 FuncScopeCleanup.disable();
11130
Douglas Gregorb4328232012-02-14 00:00:48 +000011131 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011132 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011133 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011134 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011135 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011136 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011137
Richard Smithc38498f2015-04-27 21:27:54 +000011138 // Copy the LSI before ActOnFinishFunctionBody removes it.
11139 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11140 // the call operator.
11141 auto LSICopy = *LSI;
11142 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11143 /*IsInstantiation*/ true);
11144 SavedContext.pop();
11145
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011146 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011147 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011148}
11149
11150template<typename Derived>
11151ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011152TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011153 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011154 TypeSourceInfo *T =
11155 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011156 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011157 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011158
Douglas Gregora16548e2009-08-11 05:31:07 +000011159 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011160 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011161 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000011162 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011163 &ArgumentChanged))
11164 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011165
Douglas Gregora16548e2009-08-11 05:31:07 +000011166 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011167 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011168 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011169 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011170
Douglas Gregora16548e2009-08-11 05:31:07 +000011171 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011172 return getDerived().RebuildCXXUnresolvedConstructExpr(
11173 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011174}
Mike Stump11289f42009-09-09 15:08:12 +000011175
Douglas Gregora16548e2009-08-11 05:31:07 +000011176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011177ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011178TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011179 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011180 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011181 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011182 Expr *OldBase;
11183 QualType BaseType;
11184 QualType ObjectType;
11185 if (!E->isImplicitAccess()) {
11186 OldBase = E->getBase();
11187 Base = getDerived().TransformExpr(OldBase);
11188 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011190
John McCall2d74de92009-12-01 22:10:20 +000011191 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011192 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011193 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011194 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011195 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011196 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011197 ObjectTy,
11198 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011199 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011200 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011201
John McCallba7bf592010-08-24 05:47:05 +000011202 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011203 BaseType = ((Expr*) Base.get())->getType();
11204 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011205 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011206 BaseType = getDerived().TransformType(E->getBaseType());
11207 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11208 }
Mike Stump11289f42009-09-09 15:08:12 +000011209
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011210 // Transform the first part of the nested-name-specifier that qualifies
11211 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011212 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011213 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011214 E->getFirstQualifierFoundInScope(),
11215 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011216
Douglas Gregore16af532011-02-28 18:50:33 +000011217 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011218 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011219 QualifierLoc
11220 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11221 ObjectType,
11222 FirstQualifierInScope);
11223 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011224 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011225 }
Mike Stump11289f42009-09-09 15:08:12 +000011226
Abramo Bagnara7945c982012-01-27 09:46:47 +000011227 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11228
John McCall31f82722010-11-12 08:19:04 +000011229 // TODO: If this is a conversion-function-id, verify that the
11230 // destination type name (if present) resolves the same way after
11231 // instantiation as it did in the local scope.
11232
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011233 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011234 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011235 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011236 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011237
John McCall2d74de92009-12-01 22:10:20 +000011238 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011239 // This is a reference to a member without an explicitly-specified
11240 // template argument list. Optimize for this common case.
11241 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011242 Base.get() == OldBase &&
11243 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011244 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011245 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011246 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011247 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011248
John McCallb268a282010-08-23 23:25:46 +000011249 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011250 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011251 E->isArrow(),
11252 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011253 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011254 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011255 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011256 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011257 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011258 }
11259
John McCall6b51f282009-11-23 01:53:49 +000011260 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011261 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11262 E->getNumTemplateArgs(),
11263 TransArgs))
11264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011265
John McCallb268a282010-08-23 23:25:46 +000011266 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011267 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011268 E->isArrow(),
11269 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011270 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011271 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011272 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011273 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011274 &TransArgs);
11275}
11276
11277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011279TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011280 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011281 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011282 QualType BaseType;
11283 if (!Old->isImplicitAccess()) {
11284 Base = getDerived().TransformExpr(Old->getBase());
11285 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011286 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011287 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011288 Old->isArrow());
11289 if (Base.isInvalid())
11290 return ExprError();
11291 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011292 } else {
11293 BaseType = getDerived().TransformType(Old->getBaseType());
11294 }
John McCall10eae182009-11-30 22:42:35 +000011295
Douglas Gregor0da1d432011-02-28 20:01:57 +000011296 NestedNameSpecifierLoc QualifierLoc;
11297 if (Old->getQualifierLoc()) {
11298 QualifierLoc
11299 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11300 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011301 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011302 }
11303
Abramo Bagnara7945c982012-01-27 09:46:47 +000011304 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11305
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011306 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011307 Sema::LookupOrdinaryName);
11308
Richard Smith151c4562016-12-20 21:35:28 +000011309 // Transform the declaration set.
11310 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11311 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011312
Douglas Gregor9262f472010-04-27 18:19:34 +000011313 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011314 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011315 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011316 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011317 Old->getMemberLoc(),
11318 Old->getNamingClass()));
11319 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011320 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011321
Douglas Gregorda7be082010-04-27 16:10:10 +000011322 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011323 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011324
John McCall10eae182009-11-30 22:42:35 +000011325 TemplateArgumentListInfo TransArgs;
11326 if (Old->hasExplicitTemplateArgs()) {
11327 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11328 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011329 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11330 Old->getNumTemplateArgs(),
11331 TransArgs))
11332 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011333 }
John McCall38836f02010-01-15 08:34:02 +000011334
11335 // FIXME: to do this check properly, we will need to preserve the
11336 // first-qualifier-in-scope here, just in case we had a dependent
11337 // base (and therefore couldn't do the check) and a
11338 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011339 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011340
John McCallb268a282010-08-23 23:25:46 +000011341 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011342 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011343 Old->getOperatorLoc(),
11344 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011345 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011346 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011347 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011348 R,
11349 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011350 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011351}
11352
11353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011354ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011355TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011356 EnterExpressionEvaluationContext Unevaluated(
11357 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011358 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11359 if (SubExpr.isInvalid())
11360 return ExprError();
11361
11362 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011363 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011364
11365 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11366}
11367
11368template<typename Derived>
11369ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011370TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011371 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11372 if (Pattern.isInvalid())
11373 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011374
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011375 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011376 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011377
Douglas Gregorb8840002011-01-14 21:20:45 +000011378 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11379 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011380}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011381
11382template<typename Derived>
11383ExprResult
11384TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11385 // If E is not value-dependent, then nothing will change when we transform it.
11386 // Note: This is an instantiation-centric view.
11387 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011388 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011389
Faisal Valid143a0c2017-04-01 21:30:49 +000011390 EnterExpressionEvaluationContext Unevaluated(
11391 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011392
Richard Smithd784e682015-09-23 21:41:42 +000011393 ArrayRef<TemplateArgument> PackArgs;
11394 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011395
Richard Smithd784e682015-09-23 21:41:42 +000011396 // Find the argument list to transform.
11397 if (E->isPartiallySubstituted()) {
11398 PackArgs = E->getPartialArguments();
11399 } else if (E->isValueDependent()) {
11400 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11401 bool ShouldExpand = false;
11402 bool RetainExpansion = false;
11403 Optional<unsigned> NumExpansions;
11404 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11405 Unexpanded,
11406 ShouldExpand, RetainExpansion,
11407 NumExpansions))
11408 return ExprError();
11409
11410 // If we need to expand the pack, build a template argument from it and
11411 // expand that.
11412 if (ShouldExpand) {
11413 auto *Pack = E->getPack();
11414 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11415 ArgStorage = getSema().Context.getPackExpansionType(
11416 getSema().Context.getTypeDeclType(TTPD), None);
11417 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11418 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11419 } else {
11420 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011421 ExprResult DRE = getSema().BuildDeclRefExpr(
11422 VD, VD->getType().getNonLValueExprType(getSema().Context),
11423 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11424 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011425 if (DRE.isInvalid())
11426 return ExprError();
11427 ArgStorage = new (getSema().Context) PackExpansionExpr(
11428 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11429 }
11430 PackArgs = ArgStorage;
11431 }
11432 }
11433
11434 // If we're not expanding the pack, just transform the decl.
11435 if (!PackArgs.size()) {
11436 auto *Pack = cast_or_null<NamedDecl>(
11437 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011438 if (!Pack)
11439 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011440 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11441 E->getPackLoc(),
11442 E->getRParenLoc(), None, None);
11443 }
11444
Richard Smithc5452ed2016-10-19 22:18:42 +000011445 // Try to compute the result without performing a partial substitution.
11446 Optional<unsigned> Result = 0;
11447 for (const TemplateArgument &Arg : PackArgs) {
11448 if (!Arg.isPackExpansion()) {
11449 Result = *Result + 1;
11450 continue;
11451 }
11452
11453 TemplateArgumentLoc ArgLoc;
11454 InventTemplateArgumentLoc(Arg, ArgLoc);
11455
11456 // Find the pattern of the pack expansion.
11457 SourceLocation Ellipsis;
11458 Optional<unsigned> OrigNumExpansions;
11459 TemplateArgumentLoc Pattern =
11460 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11461 OrigNumExpansions);
11462
11463 // Substitute under the pack expansion. Do not expand the pack (yet).
11464 TemplateArgumentLoc OutPattern;
11465 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11466 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11467 /*Uneval*/ true))
11468 return true;
11469
11470 // See if we can determine the number of arguments from the result.
11471 Optional<unsigned> NumExpansions =
11472 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11473 if (!NumExpansions) {
11474 // No: we must be in an alias template expansion, and we're going to need
11475 // to actually expand the packs.
11476 Result = None;
11477 break;
11478 }
11479
11480 Result = *Result + *NumExpansions;
11481 }
11482
11483 // Common case: we could determine the number of expansions without
11484 // substituting.
11485 if (Result)
11486 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11487 E->getPackLoc(),
11488 E->getRParenLoc(), *Result, None);
11489
Richard Smithd784e682015-09-23 21:41:42 +000011490 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11491 E->getPackLoc());
11492 {
11493 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11494 typedef TemplateArgumentLocInventIterator<
11495 Derived, const TemplateArgument*> PackLocIterator;
11496 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11497 PackLocIterator(*this, PackArgs.end()),
11498 TransformedPackArgs, /*Uneval*/true))
11499 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011500 }
11501
Richard Smithc5452ed2016-10-19 22:18:42 +000011502 // Check whether we managed to fully-expand the pack.
11503 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011504 SmallVector<TemplateArgument, 8> Args;
11505 bool PartialSubstitution = false;
11506 for (auto &Loc : TransformedPackArgs.arguments()) {
11507 Args.push_back(Loc.getArgument());
11508 if (Loc.getArgument().isPackExpansion())
11509 PartialSubstitution = true;
11510 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011511
Richard Smithd784e682015-09-23 21:41:42 +000011512 if (PartialSubstitution)
11513 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11514 E->getPackLoc(),
11515 E->getRParenLoc(), None, Args);
11516
11517 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011518 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011519 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011520}
11521
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011522template<typename Derived>
11523ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011524TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11525 SubstNonTypeTemplateParmPackExpr *E) {
11526 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011527 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011528}
11529
11530template<typename Derived>
11531ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011532TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11533 SubstNonTypeTemplateParmExpr *E) {
11534 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011535 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011536}
11537
11538template<typename Derived>
11539ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011540TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11541 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011542 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011543}
11544
11545template<typename Derived>
11546ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011547TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11548 MaterializeTemporaryExpr *E) {
11549 return getDerived().TransformExpr(E->GetTemporaryExpr());
11550}
Chad Rosier1dcde962012-08-08 18:46:20 +000011551
Douglas Gregorfe314812011-06-21 17:03:29 +000011552template<typename Derived>
11553ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011554TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11555 Expr *Pattern = E->getPattern();
11556
11557 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11558 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11559 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11560
11561 // Determine whether the set of unexpanded parameter packs can and should
11562 // be expanded.
11563 bool Expand = true;
11564 bool RetainExpansion = false;
11565 Optional<unsigned> NumExpansions;
11566 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11567 Pattern->getSourceRange(),
11568 Unexpanded,
11569 Expand, RetainExpansion,
11570 NumExpansions))
11571 return true;
11572
11573 if (!Expand) {
11574 // Do not expand any packs here, just transform and rebuild a fold
11575 // expression.
11576 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11577
11578 ExprResult LHS =
11579 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11580 if (LHS.isInvalid())
11581 return true;
11582
11583 ExprResult RHS =
11584 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11585 if (RHS.isInvalid())
11586 return true;
11587
11588 if (!getDerived().AlwaysRebuild() &&
11589 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11590 return E;
11591
11592 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011593 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011594 RHS.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011595 }
11596
11597 // The transform has determined that we should perform an elementwise
11598 // expansion of the pattern. Do so.
11599 ExprResult Result = getDerived().TransformExpr(E->getInit());
11600 if (Result.isInvalid())
11601 return true;
11602 bool LeftFold = E->isLeftFold();
11603
11604 // If we're retaining an expansion for a right fold, it is the innermost
11605 // component and takes the init (if any).
11606 if (!LeftFold && RetainExpansion) {
11607 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11608
11609 ExprResult Out = getDerived().TransformExpr(Pattern);
11610 if (Out.isInvalid())
11611 return true;
11612
11613 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011614 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011615 Result.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011616 if (Result.isInvalid())
11617 return true;
11618 }
11619
11620 for (unsigned I = 0; I != *NumExpansions; ++I) {
11621 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11622 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11623 ExprResult Out = getDerived().TransformExpr(Pattern);
11624 if (Out.isInvalid())
11625 return true;
11626
11627 if (Out.get()->containsUnexpandedParameterPack()) {
11628 // We still have a pack; retain a pack expansion for this slice.
11629 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011630 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000011631 E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011632 LeftFold ? Out.get() : Result.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011633 } else if (Result.isUsable()) {
11634 // We've got down to a single element; build a binary operator.
11635 Result = getDerived().RebuildBinaryOperator(
11636 E->getEllipsisLoc(), E->getOperator(),
11637 LeftFold ? Result.get() : Out.get(),
11638 LeftFold ? Out.get() : Result.get());
11639 } else
11640 Result = Out;
11641
11642 if (Result.isInvalid())
11643 return true;
11644 }
11645
11646 // If we're retaining an expansion for a left fold, it is the outermost
11647 // component and takes the complete expansion so far as its init (if any).
11648 if (LeftFold && RetainExpansion) {
11649 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11650
11651 ExprResult Out = getDerived().TransformExpr(Pattern);
11652 if (Out.isInvalid())
11653 return true;
11654
11655 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011656 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011657 Out.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011658 if (Result.isInvalid())
11659 return true;
11660 }
11661
11662 // If we had no init and an empty pack, and we're not retaining an expansion,
11663 // then produce a fallback value or error.
11664 if (Result.isUnset())
11665 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11666 E->getOperator());
11667
11668 return Result;
11669}
11670
11671template<typename Derived>
11672ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011673TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11674 CXXStdInitializerListExpr *E) {
11675 return getDerived().TransformExpr(E->getSubExpr());
11676}
11677
11678template<typename Derived>
11679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011680TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011681 return SemaRef.MaybeBindToTemporary(E);
11682}
11683
11684template<typename Derived>
11685ExprResult
11686TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011687 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011688}
11689
11690template<typename Derived>
11691ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011692TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11693 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11694 if (SubExpr.isInvalid())
11695 return ExprError();
11696
11697 if (!getDerived().AlwaysRebuild() &&
11698 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011699 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011700
11701 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011702}
11703
11704template<typename Derived>
11705ExprResult
11706TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11707 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011708 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011709 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011710 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011711 /*IsCall=*/false, Elements, &ArgChanged))
11712 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011713
Ted Kremeneke65b0862012-03-06 20:05:56 +000011714 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11715 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011716
Ted Kremeneke65b0862012-03-06 20:05:56 +000011717 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11718 Elements.data(),
11719 Elements.size());
11720}
11721
11722template<typename Derived>
11723ExprResult
11724TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011725 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011726 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011727 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011728 bool ArgChanged = false;
11729 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11730 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011731
Ted Kremeneke65b0862012-03-06 20:05:56 +000011732 if (OrigElement.isPackExpansion()) {
11733 // This key/value element is a pack expansion.
11734 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11735 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11736 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11737 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11738
11739 // Determine whether the set of unexpanded parameter packs can
11740 // and should be expanded.
11741 bool Expand = true;
11742 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011743 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11744 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011745 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011746 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011747 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11748 PatternRange, Unexpanded, Expand,
11749 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000011750 return ExprError();
11751
11752 if (!Expand) {
11753 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011754 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011755 // expansion.
11756 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11757 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11758 if (Key.isInvalid())
11759 return ExprError();
11760
11761 if (Key.get() != OrigElement.Key)
11762 ArgChanged = true;
11763
11764 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11765 if (Value.isInvalid())
11766 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011767
Ted Kremeneke65b0862012-03-06 20:05:56 +000011768 if (Value.get() != OrigElement.Value)
11769 ArgChanged = true;
11770
Chad Rosier1dcde962012-08-08 18:46:20 +000011771 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011772 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11773 };
11774 Elements.push_back(Expansion);
11775 continue;
11776 }
11777
11778 // Record right away that the argument was changed. This needs
11779 // to happen even if the array expands to nothing.
11780 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011781
Ted Kremeneke65b0862012-03-06 20:05:56 +000011782 // The transform has determined that we should perform an elementwise
11783 // expansion of the pattern. Do so.
11784 for (unsigned I = 0; I != *NumExpansions; ++I) {
11785 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11786 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11787 if (Key.isInvalid())
11788 return ExprError();
11789
11790 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11791 if (Value.isInvalid())
11792 return ExprError();
11793
Chad Rosier1dcde962012-08-08 18:46:20 +000011794 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011795 Key.get(), Value.get(), SourceLocation(), NumExpansions
11796 };
11797
11798 // If any unexpanded parameter packs remain, we still have a
11799 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011800 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011801 if (Key.get()->containsUnexpandedParameterPack() ||
11802 Value.get()->containsUnexpandedParameterPack())
11803 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011804
Ted Kremeneke65b0862012-03-06 20:05:56 +000011805 Elements.push_back(Element);
11806 }
11807
Richard Smith9467be42014-06-06 17:33:35 +000011808 // FIXME: Retain a pack expansion if RetainExpansion is true.
11809
Ted Kremeneke65b0862012-03-06 20:05:56 +000011810 // We've finished with this pack expansion.
11811 continue;
11812 }
11813
11814 // Transform and check key.
11815 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11816 if (Key.isInvalid())
11817 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011818
Ted Kremeneke65b0862012-03-06 20:05:56 +000011819 if (Key.get() != OrigElement.Key)
11820 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011821
Ted Kremeneke65b0862012-03-06 20:05:56 +000011822 // Transform and check value.
11823 ExprResult Value
11824 = getDerived().TransformExpr(OrigElement.Value);
11825 if (Value.isInvalid())
11826 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011827
Ted Kremeneke65b0862012-03-06 20:05:56 +000011828 if (Value.get() != OrigElement.Value)
11829 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011830
11831 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011832 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011833 };
11834 Elements.push_back(Element);
11835 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011836
Ted Kremeneke65b0862012-03-06 20:05:56 +000011837 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11838 return SemaRef.MaybeBindToTemporary(E);
11839
11840 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011841 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011842}
11843
Mike Stump11289f42009-09-09 15:08:12 +000011844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011846TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011847 TypeSourceInfo *EncodedTypeInfo
11848 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11849 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011851
Douglas Gregora16548e2009-08-11 05:31:07 +000011852 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011853 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011854 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011855
11856 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011857 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011858 E->getRParenLoc());
11859}
Mike Stump11289f42009-09-09 15:08:12 +000011860
Douglas Gregora16548e2009-08-11 05:31:07 +000011861template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011862ExprResult TreeTransform<Derived>::
11863TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011864 // This is a kind of implicit conversion, and it needs to get dropped
11865 // and recomputed for the same general reasons that ImplicitCastExprs
11866 // do, as well a more specific one: this expression is only valid when
11867 // it appears *immediately* as an argument expression.
11868 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011869}
11870
11871template<typename Derived>
11872ExprResult TreeTransform<Derived>::
11873TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011874 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011875 = getDerived().TransformType(E->getTypeInfoAsWritten());
11876 if (!TSInfo)
11877 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011878
John McCall31168b02011-06-15 23:02:42 +000011879 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011880 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011881 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011882
John McCall31168b02011-06-15 23:02:42 +000011883 if (!getDerived().AlwaysRebuild() &&
11884 TSInfo == E->getTypeInfoAsWritten() &&
11885 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011886 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011887
John McCall31168b02011-06-15 23:02:42 +000011888 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011889 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011890 Result.get());
11891}
11892
Erik Pilkington29099de2016-07-16 00:35:23 +000011893template <typename Derived>
11894ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11895 ObjCAvailabilityCheckExpr *E) {
11896 return E;
11897}
11898
John McCall31168b02011-06-15 23:02:42 +000011899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011900ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011901TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011902 // Transform arguments.
11903 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011904 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011905 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011906 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011907 &ArgChanged))
11908 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011909
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011910 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11911 // Class message: transform the receiver type.
11912 TypeSourceInfo *ReceiverTypeInfo
11913 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11914 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011915 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011916
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011917 // If nothing changed, just retain the existing message send.
11918 if (!getDerived().AlwaysRebuild() &&
11919 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011920 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011921
11922 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011923 SmallVector<SourceLocation, 16> SelLocs;
11924 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011925 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11926 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011927 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011928 E->getMethodDecl(),
11929 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011930 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011931 E->getRightLoc());
11932 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011933 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11934 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011935 if (!E->getMethodDecl())
11936 return ExprError();
11937
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011938 // Build a new class message send to 'super'.
11939 SmallVector<SourceLocation, 16> SelLocs;
11940 E->getSelectorLocs(SelLocs);
11941 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11942 E->getSelector(),
11943 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011944 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011945 E->getMethodDecl(),
11946 E->getLeftLoc(),
11947 Args,
11948 E->getRightLoc());
11949 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011950
11951 // Instance message: transform the receiver
11952 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11953 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011954 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011955 = getDerived().TransformExpr(E->getInstanceReceiver());
11956 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011957 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011958
11959 // If nothing changed, just retain the existing message send.
11960 if (!getDerived().AlwaysRebuild() &&
11961 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011962 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011963
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011964 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011965 SmallVector<SourceLocation, 16> SelLocs;
11966 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011967 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011968 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011969 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011970 E->getMethodDecl(),
11971 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011972 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011973 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011974}
11975
Mike Stump11289f42009-09-09 15:08:12 +000011976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011978TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011979 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011980}
11981
Mike Stump11289f42009-09-09 15:08:12 +000011982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011984TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011985 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011986}
11987
Mike Stump11289f42009-09-09 15:08:12 +000011988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011989ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011990TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011991 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011992 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011993 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011994 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011995
11996 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011997
Douglas Gregord51d90d2010-04-26 20:11:03 +000011998 // If nothing changed, just retain the existing expression.
11999 if (!getDerived().AlwaysRebuild() &&
12000 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012001 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012002
John McCallb268a282010-08-23 23:25:46 +000012003 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012004 E->getLocation(),
12005 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012006}
12007
Mike Stump11289f42009-09-09 15:08:12 +000012008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012010TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012011 // 'super' and types never change. Property never changes. Just
12012 // retain the existing expression.
12013 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012014 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012015
Douglas Gregor9faee212010-04-26 20:47:02 +000012016 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012017 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012018 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012019 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012020
Douglas Gregor9faee212010-04-26 20:47:02 +000012021 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012022
Douglas Gregor9faee212010-04-26 20:47:02 +000012023 // If nothing changed, just retain the existing expression.
12024 if (!getDerived().AlwaysRebuild() &&
12025 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012026 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012027
John McCallb7bd14f2010-12-02 01:19:52 +000012028 if (E->isExplicitProperty())
12029 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12030 E->getExplicitProperty(),
12031 E->getLocation());
12032
12033 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012034 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012035 E->getImplicitPropertyGetter(),
12036 E->getImplicitPropertySetter(),
12037 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012038}
12039
Mike Stump11289f42009-09-09 15:08:12 +000012040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012041ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012042TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12043 // Transform the base expression.
12044 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12045 if (Base.isInvalid())
12046 return ExprError();
12047
12048 // Transform the key expression.
12049 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12050 if (Key.isInvalid())
12051 return ExprError();
12052
12053 // If nothing changed, just retain the existing expression.
12054 if (!getDerived().AlwaysRebuild() &&
12055 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012056 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012057
Chad Rosier1dcde962012-08-08 18:46:20 +000012058 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012059 Base.get(), Key.get(),
12060 E->getAtIndexMethodDecl(),
12061 E->setAtIndexMethodDecl());
12062}
12063
12064template<typename Derived>
12065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012066TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012067 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012068 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012069 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012070 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012071
Douglas Gregord51d90d2010-04-26 20:11:03 +000012072 // If nothing changed, just retain the existing expression.
12073 if (!getDerived().AlwaysRebuild() &&
12074 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012075 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012076
John McCallb268a282010-08-23 23:25:46 +000012077 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012078 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012079 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012080}
12081
Mike Stump11289f42009-09-09 15:08:12 +000012082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012083ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012084TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012085 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012086 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012087 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012088 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012089 SubExprs, &ArgumentChanged))
12090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012091
Douglas Gregora16548e2009-08-11 05:31:07 +000012092 if (!getDerived().AlwaysRebuild() &&
12093 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012094 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012095
Douglas Gregora16548e2009-08-11 05:31:07 +000012096 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012097 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012098 E->getRParenLoc());
12099}
12100
Mike Stump11289f42009-09-09 15:08:12 +000012101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012102ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012103TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12104 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12105 if (SrcExpr.isInvalid())
12106 return ExprError();
12107
12108 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12109 if (!Type)
12110 return ExprError();
12111
12112 if (!getDerived().AlwaysRebuild() &&
12113 Type == E->getTypeSourceInfo() &&
12114 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012115 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012116
12117 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12118 SrcExpr.get(), Type,
12119 E->getRParenLoc());
12120}
12121
12122template<typename Derived>
12123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012124TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012125 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012126
Craig Topperc3ec1492014-05-26 06:22:03 +000012127 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012128 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12129
12130 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012131 blockScope->TheDecl->setBlockMissingReturnType(
12132 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012133
Chris Lattner01cf8db2011-07-20 06:58:45 +000012134 SmallVector<ParmVarDecl*, 4> params;
12135 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012136
John McCallc8e321d2016-03-01 02:09:25 +000012137 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12138
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012139 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012140 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012141 if (getDerived().TransformFunctionTypeParams(
12142 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12143 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12144 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012145 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012146 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012147 }
John McCall490112f2011-02-04 18:33:18 +000012148
Eli Friedman34b49062012-01-26 03:00:14 +000012149 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012150 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012151
John McCallc8e321d2016-03-01 02:09:25 +000012152 auto epi = exprFunctionType->getExtProtoInfo();
12153 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12154
Jordan Rose5c382722013-03-08 21:51:21 +000012155 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012156 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012157 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012158
12159 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012160 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012161 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012162
12163 if (!oldBlock->blockMissingReturnType()) {
12164 blockScope->HasImplicitReturnType = false;
12165 blockScope->ReturnType = exprResultType;
12166 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012167
John McCall3882ace2011-01-05 12:14:39 +000012168 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012169 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012170 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012171 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012172 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012173 }
John McCall3882ace2011-01-05 12:14:39 +000012174
John McCall490112f2011-02-04 18:33:18 +000012175#ifndef NDEBUG
12176 // In builds with assertions, make sure that we captured everything we
12177 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012178 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012179 for (const auto &I : oldBlock->captures()) {
12180 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012181
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012182 // Ignore parameter packs.
12183 if (isa<ParmVarDecl>(oldCapture) &&
12184 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12185 continue;
John McCall490112f2011-02-04 18:33:18 +000012186
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012187 VarDecl *newCapture =
12188 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12189 oldCapture));
12190 assert(blockScope->CaptureMap.count(newCapture));
12191 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012192 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012193 }
12194#endif
12195
12196 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012197 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012198}
12199
Mike Stump11289f42009-09-09 15:08:12 +000012200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012201ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012202TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012203 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012204}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012205
12206template<typename Derived>
12207ExprResult
12208TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012209 QualType RetTy = getDerived().TransformType(E->getType());
12210 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012211 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012212 SubExprs.reserve(E->getNumSubExprs());
12213 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12214 SubExprs, &ArgumentChanged))
12215 return ExprError();
12216
12217 if (!getDerived().AlwaysRebuild() &&
12218 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012219 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012220
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012221 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012222 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012223}
Chad Rosier1dcde962012-08-08 18:46:20 +000012224
Douglas Gregora16548e2009-08-11 05:31:07 +000012225//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012226// Type reconstruction
12227//===----------------------------------------------------------------------===//
12228
Mike Stump11289f42009-09-09 15:08:12 +000012229template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012230QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12231 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012232 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012233 getDerived().getBaseEntity());
12234}
12235
Mike Stump11289f42009-09-09 15:08:12 +000012236template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012237QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12238 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012239 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012240 getDerived().getBaseEntity());
12241}
12242
Mike Stump11289f42009-09-09 15:08:12 +000012243template<typename Derived>
12244QualType
John McCall70dd5f62009-10-30 00:06:24 +000012245TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12246 bool WrittenAsLValue,
12247 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012248 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012249 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012250}
12251
12252template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012253QualType
John McCall70dd5f62009-10-30 00:06:24 +000012254TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12255 QualType ClassType,
12256 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012257 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12258 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012259}
12260
12261template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012262QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12263 const ObjCTypeParamDecl *Decl,
12264 SourceLocation ProtocolLAngleLoc,
12265 ArrayRef<ObjCProtocolDecl *> Protocols,
12266 ArrayRef<SourceLocation> ProtocolLocs,
12267 SourceLocation ProtocolRAngleLoc) {
12268 return SemaRef.BuildObjCTypeParamType(Decl,
12269 ProtocolLAngleLoc, Protocols,
12270 ProtocolLocs, ProtocolRAngleLoc,
12271 /*FailOnError=*/true);
12272}
12273
12274template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012275QualType TreeTransform<Derived>::RebuildObjCObjectType(
12276 QualType BaseType,
12277 SourceLocation Loc,
12278 SourceLocation TypeArgsLAngleLoc,
12279 ArrayRef<TypeSourceInfo *> TypeArgs,
12280 SourceLocation TypeArgsRAngleLoc,
12281 SourceLocation ProtocolLAngleLoc,
12282 ArrayRef<ObjCProtocolDecl *> Protocols,
12283 ArrayRef<SourceLocation> ProtocolLocs,
12284 SourceLocation ProtocolRAngleLoc) {
12285 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12286 TypeArgs, TypeArgsRAngleLoc,
12287 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12288 ProtocolRAngleLoc,
12289 /*FailOnError=*/true);
12290}
12291
12292template<typename Derived>
12293QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12294 QualType PointeeType,
12295 SourceLocation Star) {
12296 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12297}
12298
12299template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012300QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012301TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12302 ArrayType::ArraySizeModifier SizeMod,
12303 const llvm::APInt *Size,
12304 Expr *SizeExpr,
12305 unsigned IndexTypeQuals,
12306 SourceRange BracketsRange) {
12307 if (SizeExpr || !Size)
12308 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12309 IndexTypeQuals, BracketsRange,
12310 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012311
12312 QualType Types[] = {
12313 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12314 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12315 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012316 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012317 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012318 QualType SizeType;
12319 for (unsigned I = 0; I != NumTypes; ++I)
12320 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12321 SizeType = Types[I];
12322 break;
12323 }
Mike Stump11289f42009-09-09 15:08:12 +000012324
Eli Friedman9562f392012-01-25 23:20:27 +000012325 // Note that we can return a VariableArrayType here in the case where
12326 // the element type was a dependent VariableArrayType.
12327 IntegerLiteral *ArraySize
12328 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12329 /*FIXME*/BracketsRange.getBegin());
12330 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012331 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012332 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012333}
Mike Stump11289f42009-09-09 15:08:12 +000012334
Douglas Gregord6ff3322009-08-04 16:50:30 +000012335template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012336QualType
12337TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012338 ArrayType::ArraySizeModifier SizeMod,
12339 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012340 unsigned IndexTypeQuals,
12341 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012342 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012343 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012344}
12345
12346template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012347QualType
Mike Stump11289f42009-09-09 15:08:12 +000012348TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012349 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012350 unsigned IndexTypeQuals,
12351 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012352 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012353 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012354}
Mike Stump11289f42009-09-09 15:08:12 +000012355
Douglas Gregord6ff3322009-08-04 16:50:30 +000012356template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012357QualType
12358TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012359 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012360 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012361 unsigned IndexTypeQuals,
12362 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012363 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012364 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012365 IndexTypeQuals, BracketsRange);
12366}
12367
12368template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012369QualType
12370TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012371 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012372 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012373 unsigned IndexTypeQuals,
12374 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012375 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012376 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012377 IndexTypeQuals, BracketsRange);
12378}
12379
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012380template <typename Derived>
12381QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12382 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12383 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12384 AttributeLoc);
12385}
12386
12387template <typename Derived>
12388QualType
12389TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12390 unsigned NumElements,
12391 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012392 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012393 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012394}
Mike Stump11289f42009-09-09 15:08:12 +000012395
Erich Keanef702b022018-07-13 19:46:04 +000012396template <typename Derived>
12397QualType TreeTransform<Derived>::RebuildDependentVectorType(
12398 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12399 VectorType::VectorKind VecKind) {
12400 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12401}
12402
Douglas Gregord6ff3322009-08-04 16:50:30 +000012403template<typename Derived>
12404QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12405 unsigned NumElements,
12406 SourceLocation AttributeLoc) {
12407 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12408 NumElements, true);
12409 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012410 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12411 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012412 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012413}
Mike Stump11289f42009-09-09 15:08:12 +000012414
Douglas Gregord6ff3322009-08-04 16:50:30 +000012415template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012416QualType
12417TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012418 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012419 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012420 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012421}
Mike Stump11289f42009-09-09 15:08:12 +000012422
Douglas Gregord6ff3322009-08-04 16:50:30 +000012423template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012424QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12425 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012426 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012427 const FunctionProtoType::ExtProtoInfo &EPI) {
12428 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012429 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012430 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012431 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012432}
Mike Stump11289f42009-09-09 15:08:12 +000012433
Douglas Gregord6ff3322009-08-04 16:50:30 +000012434template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012435QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12436 return SemaRef.Context.getFunctionNoProtoType(T);
12437}
12438
12439template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012440QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12441 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012442 assert(D && "no decl found");
12443 if (D->isInvalidDecl()) return QualType();
12444
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012445 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012446 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012447 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12448 // A valid resolved using typename pack expansion decl can have multiple
12449 // UsingDecls, but they must each have exactly one type, and it must be
12450 // the same type in every case. But we must have at least one expansion!
12451 if (UPD->expansions().empty()) {
12452 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12453 << UPD->isCXXClassMember() << UPD;
12454 return QualType();
12455 }
12456
12457 // We might still have some unresolved types. Try to pick a resolved type
12458 // if we can. The final instantiation will check that the remaining
12459 // unresolved types instantiate to the type we pick.
12460 QualType FallbackT;
12461 QualType T;
12462 for (auto *E : UPD->expansions()) {
12463 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12464 if (ThisT.isNull())
12465 continue;
12466 else if (ThisT->getAs<UnresolvedUsingType>())
12467 FallbackT = ThisT;
12468 else if (T.isNull())
12469 T = ThisT;
12470 else
12471 assert(getSema().Context.hasSameType(ThisT, T) &&
12472 "mismatched resolved types in using pack expansion");
12473 }
12474 return T.isNull() ? FallbackT : T;
12475 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012476 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012477 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12478
12479 // A valid resolved using typename decl points to exactly one type decl.
12480 assert(++Using->shadow_begin() == Using->shadow_end());
12481 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012482 } else {
12483 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12484 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12485 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12486 }
12487
12488 return SemaRef.Context.getTypeDeclType(Ty);
12489}
12490
12491template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012492QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12493 SourceLocation Loc) {
12494 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012495}
12496
12497template<typename Derived>
12498QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12499 return SemaRef.Context.getTypeOfType(Underlying);
12500}
12501
12502template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012503QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12504 SourceLocation Loc) {
12505 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012506}
12507
12508template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012509QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12510 UnaryTransformType::UTTKind UKind,
12511 SourceLocation Loc) {
12512 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12513}
12514
12515template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012516QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012517 TemplateName Template,
12518 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012519 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012520 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012521}
Mike Stump11289f42009-09-09 15:08:12 +000012522
Douglas Gregor1135c352009-08-06 05:28:30 +000012523template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012524QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12525 SourceLocation KWLoc) {
12526 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12527}
12528
12529template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012530QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012531 SourceLocation KWLoc,
12532 bool isReadPipe) {
12533 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12534 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012535}
12536
12537template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012538TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012539TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012540 bool TemplateKW,
12541 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012542 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012543 Template);
12544}
12545
12546template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012547TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012548TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012549 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000012550 const IdentifierInfo &Name,
12551 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012552 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012553 NamedDecl *FirstQualifierInScope,
12554 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012555 UnqualifiedId TemplateName;
12556 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012557 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012558 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012559 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012560 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012561 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012562 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012563 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012564}
Mike Stump11289f42009-09-09 15:08:12 +000012565
Douglas Gregora16548e2009-08-11 05:31:07 +000012566template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012567TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012568TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012569 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012570 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012571 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012572 QualType ObjectType,
12573 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012574 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012575 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012576 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012577 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000012578 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012579 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012580 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012581 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012582 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012583 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012584 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012585}
Chad Rosier1dcde962012-08-08 18:46:20 +000012586
Douglas Gregor71395fa2009-11-04 00:56:37 +000012587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012588ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012589TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12590 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012591 Expr *OrigCallee,
12592 Expr *First,
12593 Expr *Second) {
12594 Expr *Callee = OrigCallee->IgnoreParenCasts();
12595 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012596
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012597 if (First->getObjectKind() == OK_ObjCProperty) {
12598 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12599 if (BinaryOperator::isAssignmentOp(Opc))
12600 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12601 First, Second);
12602 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12603 if (Result.isInvalid())
12604 return ExprError();
12605 First = Result.get();
12606 }
12607
12608 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12609 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12610 if (Result.isInvalid())
12611 return ExprError();
12612 Second = Result.get();
12613 }
12614
Douglas Gregora16548e2009-08-11 05:31:07 +000012615 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012616 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012617 if (!First->getType()->isOverloadableType() &&
12618 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012619 return getSema().CreateBuiltinArraySubscriptExpr(
12620 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012621 } else if (Op == OO_Arrow) {
12622 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012623 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12624 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000012625 if (!First->getType()->isOverloadableType() ||
12626 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
12627 // The argument is not of overloadable type, or this is an expression
12628 // of the form &Class::member, so try to create a built-in unary
12629 // operation.
John McCalle3027922010-08-25 11:45:40 +000012630 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012631 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012632
John McCallb268a282010-08-23 23:25:46 +000012633 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012634 }
12635 } else {
John McCallb268a282010-08-23 23:25:46 +000012636 if (!First->getType()->isOverloadableType() &&
12637 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012638 // Neither of the arguments is an overloadable type, so try to
12639 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012640 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012641 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012642 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012643 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012645
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012646 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012647 }
12648 }
Mike Stump11289f42009-09-09 15:08:12 +000012649
12650 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012651 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012652 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000012653 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000012654
John McCallb268a282010-08-23 23:25:46 +000012655 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000012656 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000012657 // If the overload could not be resolved in the template definition
12658 // (because we had a dependent argument), ADL is performed as part of
12659 // template instantiation.
12660 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000012661 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012662 // If we've resolved this to a particular non-member function, just call
12663 // that function. If we resolved it to a member function,
12664 // CreateOverloaded* will find that function for us.
12665 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12666 if (!isa<CXXMethodDecl>(ND))
12667 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000012668 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000012669 }
Mike Stump11289f42009-09-09 15:08:12 +000012670
Douglas Gregora16548e2009-08-11 05:31:07 +000012671 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012672 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012673 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012674
Douglas Gregora16548e2009-08-11 05:31:07 +000012675 // Create the overloaded operator invocation for unary operators.
12676 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012677 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012678 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000012679 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12680 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012681 }
Mike Stump11289f42009-09-09 15:08:12 +000012682
Douglas Gregore9d62932011-07-15 16:25:15 +000012683 if (Op == OO_Subscript) {
12684 SourceLocation LBrace;
12685 SourceLocation RBrace;
12686
12687 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012688 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012689 LBrace = SourceLocation::getFromRawEncoding(
12690 NameLoc.CXXOperatorName.BeginOpNameLoc);
12691 RBrace = SourceLocation::getFromRawEncoding(
12692 NameLoc.CXXOperatorName.EndOpNameLoc);
12693 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012694 LBrace = Callee->getBeginLoc();
12695 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000012696 }
12697
12698 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12699 First, Second);
12700 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012701
Douglas Gregora16548e2009-08-11 05:31:07 +000012702 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012703 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000012704 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12705 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012706 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012708
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012709 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012710}
Mike Stump11289f42009-09-09 15:08:12 +000012711
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012712template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012713ExprResult
John McCallb268a282010-08-23 23:25:46 +000012714TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012715 SourceLocation OperatorLoc,
12716 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012717 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012718 TypeSourceInfo *ScopeType,
12719 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012720 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012721 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012722 QualType BaseType = Base->getType();
12723 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012724 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012725 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012726 !BaseType->getAs<PointerType>()->getPointeeType()
12727 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012728 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012729 return SemaRef.BuildPseudoDestructorExpr(
12730 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12731 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012732 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012733
Douglas Gregor678f90d2010-02-25 01:56:36 +000012734 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012735 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12736 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12737 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12738 NameInfo.setNamedTypeInfo(DestroyedType);
12739
Richard Smith8e4a3862012-05-15 06:15:11 +000012740 // The scope type is now known to be a valid nested name specifier
12741 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012742 if (ScopeType) {
12743 if (!ScopeType->getType()->getAs<TagType>()) {
12744 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12745 diag::err_expected_class_or_namespace)
12746 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12747 return ExprError();
12748 }
12749 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12750 CCLoc);
12751 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012752
Abramo Bagnara7945c982012-01-27 09:46:47 +000012753 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012754 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012755 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012756 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012757 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012758 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012759 /*TemplateArgs*/ nullptr,
12760 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012761}
12762
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012763template<typename Derived>
12764StmtResult
12765TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012766 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000012767 CapturedDecl *CD = S->getCapturedDecl();
12768 unsigned NumParams = CD->getNumParams();
12769 unsigned ContextParamPos = CD->getContextParamPosition();
12770 SmallVector<Sema::CapturedParamNameType, 4> Params;
12771 for (unsigned I = 0; I < NumParams; ++I) {
12772 if (I != ContextParamPos) {
12773 Params.push_back(
12774 std::make_pair(
12775 CD->getParam(I)->getName(),
12776 getDerived().TransformType(CD->getParam(I)->getType())));
12777 } else {
12778 Params.push_back(std::make_pair(StringRef(), QualType()));
12779 }
12780 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012781 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012782 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012783 StmtResult Body;
12784 {
12785 Sema::CompoundScopeRAII CompoundScope(getSema());
12786 Body = getDerived().TransformStmt(S->getCapturedStmt());
12787 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012788
12789 if (Body.isInvalid()) {
12790 getSema().ActOnCapturedRegionError();
12791 return StmtError();
12792 }
12793
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012794 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012795}
12796
Douglas Gregord6ff3322009-08-04 16:50:30 +000012797} // end namespace clang
12798
Hans Wennborg59dbe862015-09-29 20:56:43 +000012799#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H