blob: 3b39539910009b173881ed4e1a95a027aea3f16f [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) {
1818 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1819 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
3036
3037 }
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())
3397 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
Richard Smithd1036122018-01-12 22:21:33 +00003398 Construct->getLocEnd());
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.
4255 // C++ [dcl.ref]p1:
4256 // when the cv-qualifiers are introduced through the use of a typedef-name
4257 // or decltype-specifier [...] the cv-qualifiers are ignored.
4258 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4259 // applied to a reference type.
4260 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4261 if (T->isFunctionType() || T->isReferenceType())
4262 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004263
John McCall31168b02011-06-15 23:02:42 +00004264 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004265 // resulting type.
4266 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004267 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004268 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004269 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004270 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004271 // A lifetime qualifier applied to a substituted template parameter
4272 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004273 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004274 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004275 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004276 QualType Replacement = SubstTypeParam->getReplacementType();
4277 Qualifiers Qs = Replacement.getQualifiers();
4278 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004279 Replacement = SemaRef.Context.getQualifiedType(
4280 Replacement.getUnqualifiedType(), Qs);
4281 T = SemaRef.Context.getSubstTemplateTypeParmType(
4282 SubstTypeParam->getReplacedParameter(), Replacement);
4283 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004284 // 'auto' types behave the same way as template parameters.
4285 QualType Deduced = AutoTy->getDeducedType();
4286 Qualifiers Qs = Deduced.getQualifiers();
4287 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004288 Deduced =
4289 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4290 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4291 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004292 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004293 // Otherwise, complain about the addition of a qualifier to an
4294 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004295 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4296 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004297 Quals.removeObjCLifetime();
4298 }
4299 }
4300 }
John McCall550e0c22009-10-21 00:40:46 +00004301
Richard Smithee579842017-01-30 20:39:26 +00004302 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004303}
4304
Douglas Gregor14454802011-02-25 02:25:35 +00004305template<typename Derived>
4306TypeLoc
4307TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4308 QualType ObjectType,
4309 NamedDecl *UnqualLookup,
4310 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004311 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004312 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004313
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004314 TypeSourceInfo *TSI =
4315 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4316 if (TSI)
4317 return TSI->getTypeLoc();
4318 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004319}
4320
Douglas Gregor579c15f2011-03-02 18:32:08 +00004321template<typename Derived>
4322TypeSourceInfo *
4323TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4324 QualType ObjectType,
4325 NamedDecl *UnqualLookup,
4326 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004327 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004328 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004329
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004330 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4331 UnqualLookup, SS);
4332}
4333
4334template <typename Derived>
4335TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4336 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4337 CXXScopeSpec &SS) {
4338 QualType T = TL.getType();
4339 assert(!getDerived().AlreadyTransformed(T));
4340
Douglas Gregor579c15f2011-03-02 18:32:08 +00004341 TypeLocBuilder TLB;
4342 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004343
Douglas Gregor579c15f2011-03-02 18:32:08 +00004344 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004345 TemplateSpecializationTypeLoc SpecTL =
4346 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
Richard Smithfd3dae02017-01-20 00:20:39 +00004348 TemplateName Template = getDerived().TransformTemplateName(
4349 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4350 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004351 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004352 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004353
4354 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004355 Template);
4356 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004357 DependentTemplateSpecializationTypeLoc SpecTL =
4358 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004359
Douglas Gregor579c15f2011-03-02 18:32:08 +00004360 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004361 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004362 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004363 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004364 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004365 ObjectType, UnqualLookup,
4366 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004367 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004368 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004369
4370 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004371 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004372 Template,
4373 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004374 } else {
4375 // Nothing special needs to be done for these.
4376 Result = getDerived().TransformType(TLB, TL);
4377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004378
4379 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004380 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004381
Douglas Gregor579c15f2011-03-02 18:32:08 +00004382 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4383}
4384
John McCall550e0c22009-10-21 00:40:46 +00004385template <class TyLoc> static inline
4386QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4387 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4388 NewT.setNameLoc(T.getNameLoc());
4389 return T.getType();
4390}
4391
John McCall550e0c22009-10-21 00:40:46 +00004392template<typename Derived>
4393QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004394 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004395 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4396 NewT.setBuiltinLoc(T.getBuiltinLoc());
4397 if (T.needsExtraLocalData())
4398 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4399 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004400}
Mike Stump11289f42009-09-09 15:08:12 +00004401
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004403QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004404 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004405 // FIXME: recurse?
4406 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004407}
Mike Stump11289f42009-09-09 15:08:12 +00004408
Reid Kleckner0503a872013-12-05 01:23:43 +00004409template <typename Derived>
4410QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4411 AdjustedTypeLoc TL) {
4412 // Adjustments applied during transformation are handled elsewhere.
4413 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4414}
4415
Douglas Gregord6ff3322009-08-04 16:50:30 +00004416template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004417QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4418 DecayedTypeLoc TL) {
4419 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4420 if (OriginalType.isNull())
4421 return QualType();
4422
4423 QualType Result = TL.getType();
4424 if (getDerived().AlwaysRebuild() ||
4425 OriginalType != TL.getOriginalLoc().getType())
4426 Result = SemaRef.Context.getDecayedType(OriginalType);
4427 TLB.push<DecayedTypeLoc>(Result);
4428 // Nothing to set for DecayedTypeLoc.
4429 return Result;
4430}
4431
4432template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004433QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004434 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004435 QualType PointeeType
4436 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004437 if (PointeeType.isNull())
4438 return QualType();
4439
4440 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004441 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004442 // A dependent pointer type 'T *' has is being transformed such
4443 // that an Objective-C class type is being replaced for 'T'. The
4444 // resulting pointer type is an ObjCObjectPointerType, not a
4445 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004446 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004447
John McCall8b07ec22010-05-15 11:32:37 +00004448 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4449 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004450 return Result;
4451 }
John McCall31f82722010-11-12 08:19:04 +00004452
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004453 if (getDerived().AlwaysRebuild() ||
4454 PointeeType != TL.getPointeeLoc().getType()) {
4455 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4456 if (Result.isNull())
4457 return QualType();
4458 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004459
John McCall31168b02011-06-15 23:02:42 +00004460 // Objective-C ARC can add lifetime qualifiers to the type that we're
4461 // pointing to.
4462 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004463
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004464 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4465 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004466 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004467}
Mike Stump11289f42009-09-09 15:08:12 +00004468
4469template<typename Derived>
4470QualType
John McCall550e0c22009-10-21 00:40:46 +00004471TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004472 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004473 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004474 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4475 if (PointeeType.isNull())
4476 return QualType();
4477
4478 QualType Result = TL.getType();
4479 if (getDerived().AlwaysRebuild() ||
4480 PointeeType != TL.getPointeeLoc().getType()) {
4481 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004482 TL.getSigilLoc());
4483 if (Result.isNull())
4484 return QualType();
4485 }
4486
Douglas Gregor049211a2010-04-22 16:50:51 +00004487 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004488 NewT.setSigilLoc(TL.getSigilLoc());
4489 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004490}
4491
John McCall70dd5f62009-10-30 00:06:24 +00004492/// Transforms a reference type. Note that somewhat paradoxically we
4493/// don't care whether the type itself is an l-value type or an r-value
4494/// type; we only care if the type was *written* as an l-value type
4495/// or an r-value type.
4496template<typename Derived>
4497QualType
4498TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004499 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004500 const ReferenceType *T = TL.getTypePtr();
4501
4502 // Note that this works with the pointee-as-written.
4503 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4504 if (PointeeType.isNull())
4505 return QualType();
4506
4507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() ||
4509 PointeeType != T->getPointeeTypeAsWritten()) {
4510 Result = getDerived().RebuildReferenceType(PointeeType,
4511 T->isSpelledAsLValue(),
4512 TL.getSigilLoc());
4513 if (Result.isNull())
4514 return QualType();
4515 }
4516
John McCall31168b02011-06-15 23:02:42 +00004517 // Objective-C ARC can add lifetime qualifiers to the type that we're
4518 // referring to.
4519 TLB.TypeWasModifiedSafely(
4520 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4521
John McCall70dd5f62009-10-30 00:06:24 +00004522 // r-value references can be rebuilt as l-value references.
4523 ReferenceTypeLoc NewTL;
4524 if (isa<LValueReferenceType>(Result))
4525 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4526 else
4527 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4528 NewTL.setSigilLoc(TL.getSigilLoc());
4529
4530 return Result;
4531}
4532
Mike Stump11289f42009-09-09 15:08:12 +00004533template<typename Derived>
4534QualType
John McCall550e0c22009-10-21 00:40:46 +00004535TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004536 LValueReferenceTypeLoc TL) {
4537 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004538}
4539
Mike Stump11289f42009-09-09 15:08:12 +00004540template<typename Derived>
4541QualType
John McCall550e0c22009-10-21 00:40:46 +00004542TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004543 RValueReferenceTypeLoc TL) {
4544 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545}
Mike Stump11289f42009-09-09 15:08:12 +00004546
Douglas Gregord6ff3322009-08-04 16:50:30 +00004547template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004548QualType
John McCall550e0c22009-10-21 00:40:46 +00004549TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004550 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004551 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004552 if (PointeeType.isNull())
4553 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004554
Abramo Bagnara509357842011-03-05 14:42:21 +00004555 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004556 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004557 if (OldClsTInfo) {
4558 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4559 if (!NewClsTInfo)
4560 return QualType();
4561 }
4562
4563 const MemberPointerType *T = TL.getTypePtr();
4564 QualType OldClsType = QualType(T->getClass(), 0);
4565 QualType NewClsType;
4566 if (NewClsTInfo)
4567 NewClsType = NewClsTInfo->getType();
4568 else {
4569 NewClsType = getDerived().TransformType(OldClsType);
4570 if (NewClsType.isNull())
4571 return QualType();
4572 }
Mike Stump11289f42009-09-09 15:08:12 +00004573
John McCall550e0c22009-10-21 00:40:46 +00004574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() ||
4576 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004577 NewClsType != OldClsType) {
4578 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004579 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004580 if (Result.isNull())
4581 return QualType();
4582 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004583
Reid Kleckner0503a872013-12-05 01:23:43 +00004584 // If we had to adjust the pointee type when building a member pointer, make
4585 // sure to push TypeLoc info for it.
4586 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4587 if (MPT && PointeeType != MPT->getPointeeType()) {
4588 assert(isa<AdjustedType>(MPT->getPointeeType()));
4589 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4590 }
4591
John McCall550e0c22009-10-21 00:40:46 +00004592 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4593 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004594 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004595
4596 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004597}
4598
Mike Stump11289f42009-09-09 15:08:12 +00004599template<typename Derived>
4600QualType
John McCall550e0c22009-10-21 00:40:46 +00004601TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004602 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004603 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004604 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004605 if (ElementType.isNull())
4606 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004607
John McCall550e0c22009-10-21 00:40:46 +00004608 QualType Result = TL.getType();
4609 if (getDerived().AlwaysRebuild() ||
4610 ElementType != T->getElementType()) {
4611 Result = getDerived().RebuildConstantArrayType(ElementType,
4612 T->getSizeModifier(),
4613 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004614 T->getIndexTypeCVRQualifiers(),
4615 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004616 if (Result.isNull())
4617 return QualType();
4618 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004619
4620 // We might have either a ConstantArrayType or a VariableArrayType now:
4621 // a ConstantArrayType is allowed to have an element type which is a
4622 // VariableArrayType if the type is dependent. Fortunately, all array
4623 // types have the same location layout.
4624 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004625 NewTL.setLBracketLoc(TL.getLBracketLoc());
4626 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004627
John McCall550e0c22009-10-21 00:40:46 +00004628 Expr *Size = TL.getSizeExpr();
4629 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004630 EnterExpressionEvaluationContext Unevaluated(
4631 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004632 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4633 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004634 }
4635 NewTL.setSizeExpr(Size);
4636
4637 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004638}
Mike Stump11289f42009-09-09 15:08:12 +00004639
Douglas Gregord6ff3322009-08-04 16:50:30 +00004640template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004641QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004642 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004643 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004644 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004645 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004646 if (ElementType.isNull())
4647 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004648
John McCall550e0c22009-10-21 00:40:46 +00004649 QualType Result = TL.getType();
4650 if (getDerived().AlwaysRebuild() ||
4651 ElementType != T->getElementType()) {
4652 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004653 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004654 T->getIndexTypeCVRQualifiers(),
4655 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004656 if (Result.isNull())
4657 return QualType();
4658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004659
John McCall550e0c22009-10-21 00:40:46 +00004660 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4661 NewTL.setLBracketLoc(TL.getLBracketLoc());
4662 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004663 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004664
4665 return Result;
4666}
4667
4668template<typename Derived>
4669QualType
4670TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004671 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004672 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4674 if (ElementType.isNull())
4675 return QualType();
4676
Tim Shenb34d0ef2017-02-14 23:46:37 +00004677 ExprResult SizeResult;
4678 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004679 EnterExpressionEvaluationContext Context(
4680 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004681 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4682 }
4683 if (SizeResult.isInvalid())
4684 return QualType();
4685 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004686 if (SizeResult.isInvalid())
4687 return QualType();
4688
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004689 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004690
4691 QualType Result = TL.getType();
4692 if (getDerived().AlwaysRebuild() ||
4693 ElementType != T->getElementType() ||
4694 Size != T->getSizeExpr()) {
4695 Result = getDerived().RebuildVariableArrayType(ElementType,
4696 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004697 Size,
John McCall550e0c22009-10-21 00:40:46 +00004698 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004699 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004700 if (Result.isNull())
4701 return QualType();
4702 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004703
Serge Pavlov774c6d02014-02-06 03:49:11 +00004704 // We might have constant size array now, but fortunately it has the same
4705 // location layout.
4706 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004707 NewTL.setLBracketLoc(TL.getLBracketLoc());
4708 NewTL.setRBracketLoc(TL.getRBracketLoc());
4709 NewTL.setSizeExpr(Size);
4710
4711 return Result;
4712}
4713
4714template<typename Derived>
4715QualType
4716TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004717 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004718 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004719 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4720 if (ElementType.isNull())
4721 return QualType();
4722
Richard Smith764d2fe2011-12-20 02:08:33 +00004723 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004724 EnterExpressionEvaluationContext Unevaluated(
4725 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004726
John McCall33ddac02011-01-19 10:06:00 +00004727 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4728 Expr *origSize = TL.getSizeExpr();
4729 if (!origSize) origSize = T->getSizeExpr();
4730
4731 ExprResult sizeResult
4732 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004733 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004734 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004735 return QualType();
4736
John McCall33ddac02011-01-19 10:06:00 +00004737 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004738
4739 QualType Result = TL.getType();
4740 if (getDerived().AlwaysRebuild() ||
4741 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004742 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004743 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4744 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004745 size,
John McCall550e0c22009-10-21 00:40:46 +00004746 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004747 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004748 if (Result.isNull())
4749 return QualType();
4750 }
John McCall550e0c22009-10-21 00:40:46 +00004751
4752 // We might have any sort of array type now, but fortunately they
4753 // all have the same location layout.
4754 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4755 NewTL.setLBracketLoc(TL.getLBracketLoc());
4756 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004757 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004758
4759 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004760}
Mike Stump11289f42009-09-09 15:08:12 +00004761
Erich Keanef702b022018-07-13 19:46:04 +00004762template <typename Derived>
4763QualType TreeTransform<Derived>::TransformDependentVectorType(
4764 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4765 const DependentVectorType *T = TL.getTypePtr();
4766 QualType ElementType = getDerived().TransformType(T->getElementType());
4767 if (ElementType.isNull())
4768 return QualType();
4769
4770 EnterExpressionEvaluationContext Unevaluated(
4771 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4772
4773 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4774 Size = SemaRef.ActOnConstantExpression(Size);
4775 if (Size.isInvalid())
4776 return QualType();
4777
4778 QualType Result = TL.getType();
4779 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4780 Size.get() != T->getSizeExpr()) {
4781 Result = getDerived().RebuildDependentVectorType(
4782 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4783 if (Result.isNull())
4784 return QualType();
4785 }
4786
4787 // Result might be dependent or not.
4788 if (isa<DependentVectorType>(Result)) {
4789 DependentVectorTypeLoc NewTL =
4790 TLB.push<DependentVectorTypeLoc>(Result);
4791 NewTL.setNameLoc(TL.getNameLoc());
4792 } else {
4793 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4794 NewTL.setNameLoc(TL.getNameLoc());
4795 }
4796
4797 return Result;
4798}
4799
Mike Stump11289f42009-09-09 15:08:12 +00004800template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004801QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004802 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004803 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004804 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004805
4806 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004807 QualType ElementType = getDerived().TransformType(T->getElementType());
4808 if (ElementType.isNull())
4809 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004810
Richard Smith764d2fe2011-12-20 02:08:33 +00004811 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004812 EnterExpressionEvaluationContext Unevaluated(
4813 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004814
John McCalldadc5752010-08-24 06:29:42 +00004815 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004816 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004817 if (Size.isInvalid())
4818 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004819
John McCall550e0c22009-10-21 00:40:46 +00004820 QualType Result = TL.getType();
4821 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004822 ElementType != T->getElementType() ||
4823 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004824 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004825 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004826 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004827 if (Result.isNull())
4828 return QualType();
4829 }
John McCall550e0c22009-10-21 00:40:46 +00004830
4831 // Result might be dependent or not.
4832 if (isa<DependentSizedExtVectorType>(Result)) {
4833 DependentSizedExtVectorTypeLoc NewTL
4834 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4835 NewTL.setNameLoc(TL.getNameLoc());
4836 } else {
4837 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4838 NewTL.setNameLoc(TL.getNameLoc());
4839 }
4840
4841 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004842}
Mike Stump11289f42009-09-09 15:08:12 +00004843
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004844template <typename Derived>
4845QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4846 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4847 const DependentAddressSpaceType *T = TL.getTypePtr();
4848
4849 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4850
4851 if (pointeeType.isNull())
4852 return QualType();
4853
4854 // Address spaces are constant expressions.
4855 EnterExpressionEvaluationContext Unevaluated(
4856 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4857
4858 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4859 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4860 if (AddrSpace.isInvalid())
4861 return QualType();
4862
4863 QualType Result = TL.getType();
4864 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4865 AddrSpace.get() != T->getAddrSpaceExpr()) {
4866 Result = getDerived().RebuildDependentAddressSpaceType(
4867 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4868 if (Result.isNull())
4869 return QualType();
4870 }
4871
4872 // Result might be dependent or not.
4873 if (isa<DependentAddressSpaceType>(Result)) {
4874 DependentAddressSpaceTypeLoc NewTL =
4875 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4876
4877 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4878 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4879 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4880
4881 } else {
4882 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4883 Result, getDerived().getBaseLocation());
4884 TransformType(TLB, DI->getTypeLoc());
4885 }
4886
4887 return Result;
4888}
4889
4890template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004891QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004892 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004893 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004894 QualType ElementType = getDerived().TransformType(T->getElementType());
4895 if (ElementType.isNull())
4896 return QualType();
4897
John McCall550e0c22009-10-21 00:40:46 +00004898 QualType Result = TL.getType();
4899 if (getDerived().AlwaysRebuild() ||
4900 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004901 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004902 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004903 if (Result.isNull())
4904 return QualType();
4905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004906
John McCall550e0c22009-10-21 00:40:46 +00004907 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4908 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004909
John McCall550e0c22009-10-21 00:40:46 +00004910 return Result;
4911}
4912
4913template<typename Derived>
4914QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004915 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004916 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004917 QualType ElementType = getDerived().TransformType(T->getElementType());
4918 if (ElementType.isNull())
4919 return QualType();
4920
4921 QualType Result = TL.getType();
4922 if (getDerived().AlwaysRebuild() ||
4923 ElementType != T->getElementType()) {
4924 Result = getDerived().RebuildExtVectorType(ElementType,
4925 T->getNumElements(),
4926 /*FIXME*/ SourceLocation());
4927 if (Result.isNull())
4928 return QualType();
4929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004930
John McCall550e0c22009-10-21 00:40:46 +00004931 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4932 NewTL.setNameLoc(TL.getNameLoc());
4933
4934 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004935}
Mike Stump11289f42009-09-09 15:08:12 +00004936
David Blaikie05785d12013-02-20 22:23:23 +00004937template <typename Derived>
4938ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4939 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4940 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004941 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004942 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004943
Douglas Gregor715e4612011-01-14 22:40:04 +00004944 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004945 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004946 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004947 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004948 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
Douglas Gregor715e4612011-01-14 22:40:04 +00004950 TypeLocBuilder TLB;
4951 TypeLoc NewTL = OldDI->getTypeLoc();
4952 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004953
4954 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004955 OldExpansionTL.getPatternLoc());
4956 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004957 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004958
4959 Result = RebuildPackExpansionType(Result,
4960 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004961 OldExpansionTL.getEllipsisLoc(),
4962 NumExpansions);
4963 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004964 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004965
Douglas Gregor715e4612011-01-14 22:40:04 +00004966 PackExpansionTypeLoc NewExpansionTL
4967 = TLB.push<PackExpansionTypeLoc>(Result);
4968 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4969 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4970 } else
4971 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004972 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004973 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004974
John McCall8fb0d9d2011-05-01 22:35:37 +00004975 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004976 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004977
4978 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4979 OldParm->getDeclContext(),
4980 OldParm->getInnerLocStart(),
4981 OldParm->getLocation(),
4982 OldParm->getIdentifier(),
4983 NewDI->getType(),
4984 NewDI,
4985 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004986 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004987 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4988 OldParm->getFunctionScopeIndex() + indexAdjustment);
4989 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004990}
4991
David Majnemer59f77922016-06-24 04:05:48 +00004992template <typename Derived>
4993bool TreeTransform<Derived>::TransformFunctionTypeParams(
4994 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4995 const QualType *ParamTypes,
4996 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4997 SmallVectorImpl<QualType> &OutParamTypes,
4998 SmallVectorImpl<ParmVarDecl *> *PVars,
4999 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005000 int indexAdjustment = 0;
5001
David Majnemer59f77922016-06-24 04:05:48 +00005002 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005003 for (unsigned i = 0; i != NumParams; ++i) {
5004 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005005 assert(OldParm->getFunctionScopeIndex() == i);
5006
David Blaikie05785d12013-02-20 22:23:23 +00005007 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005008 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005009 if (OldParm->isParameterPack()) {
5010 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005011 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005012
Douglas Gregor5499af42011-01-05 23:12:31 +00005013 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005014 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005015 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005016 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5017 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005018 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5019
Douglas Gregor5499af42011-01-05 23:12:31 +00005020 // Determine whether we should expand the parameter packs.
5021 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005022 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005023 Optional<unsigned> OrigNumExpansions =
5024 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005025 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005026 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5027 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005028 Unexpanded,
5029 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005030 RetainExpansion,
5031 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005032 return true;
5033 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005034
Douglas Gregor5499af42011-01-05 23:12:31 +00005035 if (ShouldExpand) {
5036 // Expand the function parameter pack into multiple, separate
5037 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005038 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005039 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005040 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005041 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005042 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005043 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005044 OrigNumExpansions,
5045 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005046 if (!NewParm)
5047 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005048
John McCallc8e321d2016-03-01 02:09:25 +00005049 if (ParamInfos)
5050 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005051 OutParamTypes.push_back(NewParm->getType());
5052 if (PVars)
5053 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005054 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005055
5056 // If we're supposed to retain a pack expansion, do so by temporarily
5057 // forgetting the partially-substituted parameter pack.
5058 if (RetainExpansion) {
5059 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005060 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005061 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005062 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005063 OrigNumExpansions,
5064 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005065 if (!NewParm)
5066 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005067
John McCallc8e321d2016-03-01 02:09:25 +00005068 if (ParamInfos)
5069 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005070 OutParamTypes.push_back(NewParm->getType());
5071 if (PVars)
5072 PVars->push_back(NewParm);
5073 }
5074
John McCall8fb0d9d2011-05-01 22:35:37 +00005075 // The next parameter should have the same adjustment as the
5076 // last thing we pushed, but we post-incremented indexAdjustment
5077 // on every push. Also, if we push nothing, the adjustment should
5078 // go down by one.
5079 indexAdjustment--;
5080
Douglas Gregor5499af42011-01-05 23:12:31 +00005081 // We're done with the pack expansion.
5082 continue;
5083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005084
5085 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005086 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005087 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5088 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005089 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005090 NumExpansions,
5091 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005092 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005093 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005094 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005095 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005096
John McCall58f10c32010-03-11 09:03:00 +00005097 if (!NewParm)
5098 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005099
John McCallc8e321d2016-03-01 02:09:25 +00005100 if (ParamInfos)
5101 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005102 OutParamTypes.push_back(NewParm->getType());
5103 if (PVars)
5104 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005105 continue;
5106 }
John McCall58f10c32010-03-11 09:03:00 +00005107
5108 // Deal with the possibility that we don't have a parameter
5109 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005110 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005111 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005112 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005113 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005114 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005115 = dyn_cast<PackExpansionType>(OldType)) {
5116 // We have a function parameter pack that may need to be expanded.
5117 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005118 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005119 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005120
Douglas Gregor5499af42011-01-05 23:12:31 +00005121 // Determine whether we should expand the parameter packs.
5122 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005123 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005124 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005125 Unexpanded,
5126 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005127 RetainExpansion,
5128 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005129 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005130 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005131
Douglas Gregor5499af42011-01-05 23:12:31 +00005132 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005133 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005134 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005135 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005136 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5137 QualType NewType = getDerived().TransformType(Pattern);
5138 if (NewType.isNull())
5139 return true;
John McCall58f10c32010-03-11 09:03:00 +00005140
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005141 if (NewType->containsUnexpandedParameterPack()) {
5142 NewType =
5143 getSema().getASTContext().getPackExpansionType(NewType, None);
5144
5145 if (NewType.isNull())
5146 return true;
5147 }
5148
John McCallc8e321d2016-03-01 02:09:25 +00005149 if (ParamInfos)
5150 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005151 OutParamTypes.push_back(NewType);
5152 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005153 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005154 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005155
Douglas Gregor5499af42011-01-05 23:12:31 +00005156 // We're done with the pack expansion.
5157 continue;
5158 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregor48d24112011-01-10 20:53:55 +00005160 // If we're supposed to retain a pack expansion, do so by temporarily
5161 // forgetting the partially-substituted parameter pack.
5162 if (RetainExpansion) {
5163 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5164 QualType NewType = getDerived().TransformType(Pattern);
5165 if (NewType.isNull())
5166 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005167
John McCallc8e321d2016-03-01 02:09:25 +00005168 if (ParamInfos)
5169 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005170 OutParamTypes.push_back(NewType);
5171 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005172 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005173 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005174
Chad Rosier1dcde962012-08-08 18:46:20 +00005175 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005176 // expansion.
5177 OldType = Expansion->getPattern();
5178 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005179 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5180 NewType = getDerived().TransformType(OldType);
5181 } else {
5182 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005183 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005184
Douglas Gregor5499af42011-01-05 23:12:31 +00005185 if (NewType.isNull())
5186 return true;
5187
5188 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005189 NewType = getSema().Context.getPackExpansionType(NewType,
5190 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005191
John McCallc8e321d2016-03-01 02:09:25 +00005192 if (ParamInfos)
5193 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005194 OutParamTypes.push_back(NewType);
5195 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005196 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005197 }
5198
John McCall8fb0d9d2011-05-01 22:35:37 +00005199#ifndef NDEBUG
5200 if (PVars) {
5201 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5202 if (ParmVarDecl *parm = (*PVars)[i])
5203 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005204 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005205#endif
5206
5207 return false;
5208}
John McCall58f10c32010-03-11 09:03:00 +00005209
5210template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005211QualType
John McCall550e0c22009-10-21 00:40:46 +00005212TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005213 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005214 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005215 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005216 return getDerived().TransformFunctionProtoType(
5217 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005218 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5219 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5220 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005221 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005222}
5223
Richard Smith2e321552014-11-12 02:00:47 +00005224template<typename Derived> template<typename Fn>
5225QualType TreeTransform<Derived>::TransformFunctionProtoType(
5226 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5227 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005228
Douglas Gregor4afc2362010-08-31 00:26:14 +00005229 // Transform the parameters and return type.
5230 //
Richard Smithf623c962012-04-17 00:58:00 +00005231 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005232 // When the function has a trailing return type, we instantiate the
5233 // parameters before the return type, since the return type can then refer
5234 // to the parameters themselves (via decltype, sizeof, etc.).
5235 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005236 SmallVector<QualType, 4> ParamTypes;
5237 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005238 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005239 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005240
Douglas Gregor7fb25412010-10-01 18:44:50 +00005241 QualType ResultType;
5242
Richard Smith1226c602012-08-14 22:51:13 +00005243 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005244 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005245 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005246 TL.getTypePtr()->param_type_begin(),
5247 T->getExtParameterInfosOrNull(),
5248 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005249 return QualType();
5250
Douglas Gregor3024f072012-04-16 07:05:22 +00005251 {
5252 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005253 // If a declaration declares a member function or member function
5254 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005255 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005256 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005257 // declarator.
5258 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005259
Alp Toker42a16a62014-01-25 23:51:36 +00005260 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005261 if (ResultType.isNull())
5262 return QualType();
5263 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005264 }
5265 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005266 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005267 if (ResultType.isNull())
5268 return QualType();
5269
Alp Toker9cacbab2014-01-20 20:26:09 +00005270 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005271 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005272 TL.getTypePtr()->param_type_begin(),
5273 T->getExtParameterInfosOrNull(),
5274 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005275 return QualType();
5276 }
5277
Richard Smith2e321552014-11-12 02:00:47 +00005278 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5279
5280 bool EPIChanged = false;
5281 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5282 return QualType();
5283
John McCallc8e321d2016-03-01 02:09:25 +00005284 // Handle extended parameter information.
5285 if (auto NewExtParamInfos =
5286 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5287 if (!EPI.ExtParameterInfos ||
5288 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5289 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5290 EPIChanged = true;
5291 }
5292 EPI.ExtParameterInfos = NewExtParamInfos;
5293 } else if (EPI.ExtParameterInfos) {
5294 EPIChanged = true;
5295 EPI.ExtParameterInfos = nullptr;
5296 }
Richard Smithf623c962012-04-17 00:58:00 +00005297
John McCall550e0c22009-10-21 00:40:46 +00005298 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005299 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005300 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005301 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005302 if (Result.isNull())
5303 return QualType();
5304 }
Mike Stump11289f42009-09-09 15:08:12 +00005305
John McCall550e0c22009-10-21 00:40:46 +00005306 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005307 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005308 NewTL.setLParenLoc(TL.getLParenLoc());
5309 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005310 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005311 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005312 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5313 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005314
5315 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005316}
Mike Stump11289f42009-09-09 15:08:12 +00005317
Douglas Gregord6ff3322009-08-04 16:50:30 +00005318template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005319bool TreeTransform<Derived>::TransformExceptionSpec(
5320 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5321 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5322 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5323
5324 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005325 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005326 EnterExpressionEvaluationContext Unevaluated(
5327 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005328 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5329 if (NoexceptExpr.isInvalid())
5330 return true;
5331
Richard Smitheaf11ad2018-05-03 03:58:32 +00005332 ExceptionSpecificationType EST = ESI.Type;
5333 NoexceptExpr =
5334 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005335 if (NoexceptExpr.isInvalid())
5336 return true;
5337
Richard Smitheaf11ad2018-05-03 03:58:32 +00005338 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005339 Changed = true;
5340 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005341 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005342 }
5343
5344 if (ESI.Type != EST_Dynamic)
5345 return false;
5346
5347 // Instantiate a dynamic exception specification's type.
5348 for (QualType T : ESI.Exceptions) {
5349 if (const PackExpansionType *PackExpansion =
5350 T->getAs<PackExpansionType>()) {
5351 Changed = true;
5352
5353 // We have a pack expansion. Instantiate it.
5354 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5355 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5356 Unexpanded);
5357 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5358
5359 // Determine whether the set of unexpanded parameter packs can and
5360 // should
5361 // be expanded.
5362 bool Expand = false;
5363 bool RetainExpansion = false;
5364 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5365 // FIXME: Track the location of the ellipsis (and track source location
5366 // information for the types in the exception specification in general).
5367 if (getDerived().TryExpandParameterPacks(
5368 Loc, SourceRange(), Unexpanded, Expand,
5369 RetainExpansion, NumExpansions))
5370 return true;
5371
5372 if (!Expand) {
5373 // We can't expand this pack expansion into separate arguments yet;
5374 // just substitute into the pattern and create a new pack expansion
5375 // type.
5376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5377 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5378 if (U.isNull())
5379 return true;
5380
5381 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5382 Exceptions.push_back(U);
5383 continue;
5384 }
5385
5386 // Substitute into the pack expansion pattern for each slice of the
5387 // pack.
5388 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5389 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5390
5391 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5392 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5393 return true;
5394
5395 Exceptions.push_back(U);
5396 }
5397 } else {
5398 QualType U = getDerived().TransformType(T);
5399 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5400 return true;
5401 if (T != U)
5402 Changed = true;
5403
5404 Exceptions.push_back(U);
5405 }
5406 }
5407
5408 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005409 if (ESI.Exceptions.empty())
5410 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005411 return false;
5412}
5413
5414template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005415QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005416 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005417 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005418 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005419 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005420 if (ResultType.isNull())
5421 return QualType();
5422
5423 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005424 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005425 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5426
5427 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005428 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005429 NewTL.setLParenLoc(TL.getLParenLoc());
5430 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005431 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005432
5433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005434}
Mike Stump11289f42009-09-09 15:08:12 +00005435
John McCallb96ec562009-12-04 22:46:56 +00005436template<typename Derived> QualType
5437TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005438 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005439 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005440 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005441 if (!D)
5442 return QualType();
5443
5444 QualType Result = TL.getType();
5445 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005446 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005447 if (Result.isNull())
5448 return QualType();
5449 }
5450
5451 // We might get an arbitrary type spec type back. We should at
5452 // least always get a type spec type, though.
5453 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5454 NewTL.setNameLoc(TL.getNameLoc());
5455
5456 return Result;
5457}
5458
Douglas Gregord6ff3322009-08-04 16:50:30 +00005459template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005460QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005461 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005462 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005463 TypedefNameDecl *Typedef
5464 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5465 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005466 if (!Typedef)
5467 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005468
John McCall550e0c22009-10-21 00:40:46 +00005469 QualType Result = TL.getType();
5470 if (getDerived().AlwaysRebuild() ||
5471 Typedef != T->getDecl()) {
5472 Result = getDerived().RebuildTypedefType(Typedef);
5473 if (Result.isNull())
5474 return QualType();
5475 }
Mike Stump11289f42009-09-09 15:08:12 +00005476
John McCall550e0c22009-10-21 00:40:46 +00005477 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5478 NewTL.setNameLoc(TL.getNameLoc());
5479
5480 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005481}
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregord6ff3322009-08-04 16:50:30 +00005483template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005484QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005485 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005486 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005487 EnterExpressionEvaluationContext Unevaluated(
5488 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5489 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005490
John McCalldadc5752010-08-24 06:29:42 +00005491 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005492 if (E.isInvalid())
5493 return QualType();
5494
Eli Friedmane4f22df2012-02-29 04:03:55 +00005495 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5496 if (E.isInvalid())
5497 return QualType();
5498
John McCall550e0c22009-10-21 00:40:46 +00005499 QualType Result = TL.getType();
5500 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005501 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005502 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005503 if (Result.isNull())
5504 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005505 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005506 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005507
John McCall550e0c22009-10-21 00:40:46 +00005508 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005509 NewTL.setTypeofLoc(TL.getTypeofLoc());
5510 NewTL.setLParenLoc(TL.getLParenLoc());
5511 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005512
5513 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005514}
Mike Stump11289f42009-09-09 15:08:12 +00005515
5516template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005517QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005518 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005519 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5520 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5521 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005522 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005523
John McCall550e0c22009-10-21 00:40:46 +00005524 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005525 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5526 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005527 if (Result.isNull())
5528 return QualType();
5529 }
Mike Stump11289f42009-09-09 15:08:12 +00005530
John McCall550e0c22009-10-21 00:40:46 +00005531 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005532 NewTL.setTypeofLoc(TL.getTypeofLoc());
5533 NewTL.setLParenLoc(TL.getLParenLoc());
5534 NewTL.setRParenLoc(TL.getRParenLoc());
5535 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005536
5537 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005538}
Mike Stump11289f42009-09-09 15:08:12 +00005539
5540template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005541QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005542 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005543 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005544
Douglas Gregore922c772009-08-04 22:27:00 +00005545 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005546 EnterExpressionEvaluationContext Unevaluated(
5547 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005548 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005549
John McCalldadc5752010-08-24 06:29:42 +00005550 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005551 if (E.isInvalid())
5552 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005553
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005554 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005555 if (E.isInvalid())
5556 return QualType();
5557
John McCall550e0c22009-10-21 00:40:46 +00005558 QualType Result = TL.getType();
5559 if (getDerived().AlwaysRebuild() ||
5560 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005561 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005562 if (Result.isNull())
5563 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005564 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005565 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005566
John McCall550e0c22009-10-21 00:40:46 +00005567 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5568 NewTL.setNameLoc(TL.getNameLoc());
5569
5570 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005571}
5572
5573template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005574QualType TreeTransform<Derived>::TransformUnaryTransformType(
5575 TypeLocBuilder &TLB,
5576 UnaryTransformTypeLoc TL) {
5577 QualType Result = TL.getType();
5578 if (Result->isDependentType()) {
5579 const UnaryTransformType *T = TL.getTypePtr();
5580 QualType NewBase =
5581 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5582 Result = getDerived().RebuildUnaryTransformType(NewBase,
5583 T->getUTTKind(),
5584 TL.getKWLoc());
5585 if (Result.isNull())
5586 return QualType();
5587 }
5588
5589 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5590 NewTL.setKWLoc(TL.getKWLoc());
5591 NewTL.setParensRange(TL.getParensRange());
5592 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5593 return Result;
5594}
5595
5596template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005597QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5598 AutoTypeLoc TL) {
5599 const AutoType *T = TL.getTypePtr();
5600 QualType OldDeduced = T->getDeducedType();
5601 QualType NewDeduced;
5602 if (!OldDeduced.isNull()) {
5603 NewDeduced = getDerived().TransformType(OldDeduced);
5604 if (NewDeduced.isNull())
5605 return QualType();
5606 }
5607
5608 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005609 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5610 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005611 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005612 if (Result.isNull())
5613 return QualType();
5614 }
5615
5616 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5617 NewTL.setNameLoc(TL.getNameLoc());
5618
5619 return Result;
5620}
5621
5622template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005623QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5624 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5625 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5626
5627 CXXScopeSpec SS;
5628 TemplateName TemplateName = getDerived().TransformTemplateName(
5629 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5630 if (TemplateName.isNull())
5631 return QualType();
5632
5633 QualType OldDeduced = T->getDeducedType();
5634 QualType NewDeduced;
5635 if (!OldDeduced.isNull()) {
5636 NewDeduced = getDerived().TransformType(OldDeduced);
5637 if (NewDeduced.isNull())
5638 return QualType();
5639 }
5640
5641 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5642 TemplateName, NewDeduced);
5643 if (Result.isNull())
5644 return QualType();
5645
5646 DeducedTemplateSpecializationTypeLoc NewTL =
5647 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5648 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5649
5650 return Result;
5651}
5652
5653template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005654QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005655 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005656 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005657 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005658 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5659 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005660 if (!Record)
5661 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005662
John McCall550e0c22009-10-21 00:40:46 +00005663 QualType Result = TL.getType();
5664 if (getDerived().AlwaysRebuild() ||
5665 Record != T->getDecl()) {
5666 Result = getDerived().RebuildRecordType(Record);
5667 if (Result.isNull())
5668 return QualType();
5669 }
Mike Stump11289f42009-09-09 15:08:12 +00005670
John McCall550e0c22009-10-21 00:40:46 +00005671 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5672 NewTL.setNameLoc(TL.getNameLoc());
5673
5674 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005675}
Mike Stump11289f42009-09-09 15:08:12 +00005676
5677template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005678QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005679 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005680 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005681 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005682 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5683 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005684 if (!Enum)
5685 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005686
John McCall550e0c22009-10-21 00:40:46 +00005687 QualType Result = TL.getType();
5688 if (getDerived().AlwaysRebuild() ||
5689 Enum != T->getDecl()) {
5690 Result = getDerived().RebuildEnumType(Enum);
5691 if (Result.isNull())
5692 return QualType();
5693 }
Mike Stump11289f42009-09-09 15:08:12 +00005694
John McCall550e0c22009-10-21 00:40:46 +00005695 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5696 NewTL.setNameLoc(TL.getNameLoc());
5697
5698 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005699}
John McCallfcc33b02009-09-05 00:15:47 +00005700
John McCalle78aac42010-03-10 03:28:59 +00005701template<typename Derived>
5702QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5703 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005704 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005705 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5706 TL.getTypePtr()->getDecl());
5707 if (!D) return QualType();
5708
5709 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5710 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5711 return T;
5712}
5713
Douglas Gregord6ff3322009-08-04 16:50:30 +00005714template<typename Derived>
5715QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005716 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005717 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005718 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005719}
5720
Mike Stump11289f42009-09-09 15:08:12 +00005721template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005722QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005723 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005724 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005725 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005726
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005727 // Substitute into the replacement type, which itself might involve something
5728 // that needs to be transformed. This only tends to occur with default
5729 // template arguments of template template parameters.
5730 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5731 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5732 if (Replacement.isNull())
5733 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005735 // Always canonicalize the replacement type.
5736 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5737 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005738 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005739 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005740
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005741 // Propagate type-source information.
5742 SubstTemplateTypeParmTypeLoc NewTL
5743 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5744 NewTL.setNameLoc(TL.getNameLoc());
5745 return Result;
5746
John McCallcebee162009-10-18 09:09:24 +00005747}
5748
5749template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005750QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5751 TypeLocBuilder &TLB,
5752 SubstTemplateTypeParmPackTypeLoc TL) {
5753 return TransformTypeSpecType(TLB, TL);
5754}
5755
5756template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005757QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005758 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005759 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005760 const TemplateSpecializationType *T = TL.getTypePtr();
5761
Douglas Gregordf846d12011-03-02 18:46:51 +00005762 // The nested-name-specifier never matters in a TemplateSpecializationType,
5763 // because we can't have a dependent nested-name-specifier anyway.
5764 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005765 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005766 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5767 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005768 if (Template.isNull())
5769 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005770
John McCall31f82722010-11-12 08:19:04 +00005771 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5772}
5773
Eli Friedman0dfb8892011-10-06 23:00:33 +00005774template<typename Derived>
5775QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5776 AtomicTypeLoc TL) {
5777 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5778 if (ValueType.isNull())
5779 return QualType();
5780
5781 QualType Result = TL.getType();
5782 if (getDerived().AlwaysRebuild() ||
5783 ValueType != TL.getValueLoc().getType()) {
5784 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5785 if (Result.isNull())
5786 return QualType();
5787 }
5788
5789 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5790 NewTL.setKWLoc(TL.getKWLoc());
5791 NewTL.setLParenLoc(TL.getLParenLoc());
5792 NewTL.setRParenLoc(TL.getRParenLoc());
5793
5794 return Result;
5795}
5796
Xiuli Pan9c14e282016-01-09 12:53:17 +00005797template <typename Derived>
5798QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5799 PipeTypeLoc TL) {
5800 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5801 if (ValueType.isNull())
5802 return QualType();
5803
5804 QualType Result = TL.getType();
5805 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005806 const PipeType *PT = Result->getAs<PipeType>();
5807 bool isReadPipe = PT->isReadOnly();
5808 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005809 if (Result.isNull())
5810 return QualType();
5811 }
5812
5813 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5814 NewTL.setKWLoc(TL.getKWLoc());
5815
5816 return Result;
5817}
5818
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005819 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005820 /// container that provides a \c getArgLoc() member function.
5821 ///
5822 /// This iterator is intended to be used with the iterator form of
5823 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5824 template<typename ArgLocContainer>
5825 class TemplateArgumentLocContainerIterator {
5826 ArgLocContainer *Container;
5827 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005828
Douglas Gregorfe921a72010-12-20 23:36:19 +00005829 public:
5830 typedef TemplateArgumentLoc value_type;
5831 typedef TemplateArgumentLoc reference;
5832 typedef int difference_type;
5833 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005834
Douglas Gregorfe921a72010-12-20 23:36:19 +00005835 class pointer {
5836 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005837
Douglas Gregorfe921a72010-12-20 23:36:19 +00005838 public:
5839 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005840
Douglas Gregorfe921a72010-12-20 23:36:19 +00005841 const TemplateArgumentLoc *operator->() const {
5842 return &Arg;
5843 }
5844 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005845
5846
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005847 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005848
Douglas Gregorfe921a72010-12-20 23:36:19 +00005849 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5850 unsigned Index)
5851 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
Douglas Gregorfe921a72010-12-20 23:36:19 +00005853 TemplateArgumentLocContainerIterator &operator++() {
5854 ++Index;
5855 return *this;
5856 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005857
Douglas Gregorfe921a72010-12-20 23:36:19 +00005858 TemplateArgumentLocContainerIterator operator++(int) {
5859 TemplateArgumentLocContainerIterator Old(*this);
5860 ++(*this);
5861 return Old;
5862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Douglas Gregorfe921a72010-12-20 23:36:19 +00005864 TemplateArgumentLoc operator*() const {
5865 return Container->getArgLoc(Index);
5866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005867
Douglas Gregorfe921a72010-12-20 23:36:19 +00005868 pointer operator->() const {
5869 return pointer(Container->getArgLoc(Index));
5870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
Douglas Gregorfe921a72010-12-20 23:36:19 +00005872 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005873 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005874 return X.Container == Y.Container && X.Index == Y.Index;
5875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Douglas Gregorfe921a72010-12-20 23:36:19 +00005877 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005878 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005879 return !(X == Y);
5880 }
5881 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
5883
John McCall31f82722010-11-12 08:19:04 +00005884template <typename Derived>
5885QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5886 TypeLocBuilder &TLB,
5887 TemplateSpecializationTypeLoc TL,
5888 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005889 TemplateArgumentListInfo NewTemplateArgs;
5890 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5891 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005892 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5893 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005894 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005895 ArgIterator(TL, TL.getNumArgs()),
5896 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005897 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005898
John McCall0ad16662009-10-29 08:12:44 +00005899 // FIXME: maybe don't rebuild if all the template arguments are the same.
5900
5901 QualType Result =
5902 getDerived().RebuildTemplateSpecializationType(Template,
5903 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005904 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005905
5906 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005907 // Specializations of template template parameters are represented as
5908 // TemplateSpecializationTypes, and substitution of type alias templates
5909 // within a dependent context can transform them into
5910 // DependentTemplateSpecializationTypes.
5911 if (isa<DependentTemplateSpecializationType>(Result)) {
5912 DependentTemplateSpecializationTypeLoc NewTL
5913 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005914 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005915 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005916 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005917 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005918 NewTL.setLAngleLoc(TL.getLAngleLoc());
5919 NewTL.setRAngleLoc(TL.getRAngleLoc());
5920 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5921 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5922 return Result;
5923 }
5924
John McCall0ad16662009-10-29 08:12:44 +00005925 TemplateSpecializationTypeLoc NewTL
5926 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005927 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005928 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5929 NewTL.setLAngleLoc(TL.getLAngleLoc());
5930 NewTL.setRAngleLoc(TL.getRAngleLoc());
5931 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5932 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005933 }
Mike Stump11289f42009-09-09 15:08:12 +00005934
John McCall0ad16662009-10-29 08:12:44 +00005935 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005936}
Mike Stump11289f42009-09-09 15:08:12 +00005937
Douglas Gregor5a064722011-02-28 17:23:35 +00005938template <typename Derived>
5939QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5940 TypeLocBuilder &TLB,
5941 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005942 TemplateName Template,
5943 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005944 TemplateArgumentListInfo NewTemplateArgs;
5945 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5946 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5947 typedef TemplateArgumentLocContainerIterator<
5948 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005949 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005950 ArgIterator(TL, TL.getNumArgs()),
5951 NewTemplateArgs))
5952 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005953
Douglas Gregor5a064722011-02-28 17:23:35 +00005954 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005955
Douglas Gregor5a064722011-02-28 17:23:35 +00005956 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5957 QualType Result
5958 = getSema().Context.getDependentTemplateSpecializationType(
5959 TL.getTypePtr()->getKeyword(),
5960 DTN->getQualifier(),
5961 DTN->getIdentifier(),
5962 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005963
Douglas Gregor5a064722011-02-28 17:23:35 +00005964 DependentTemplateSpecializationTypeLoc NewTL
5965 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005966 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005967 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005968 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005969 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005970 NewTL.setLAngleLoc(TL.getLAngleLoc());
5971 NewTL.setRAngleLoc(TL.getRAngleLoc());
5972 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5973 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5974 return Result;
5975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005976
5977 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005978 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005979 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005980 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005981
Douglas Gregor5a064722011-02-28 17:23:35 +00005982 if (!Result.isNull()) {
5983 /// FIXME: Wrap this in an elaborated-type-specifier?
5984 TemplateSpecializationTypeLoc NewTL
5985 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005986 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005987 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005988 NewTL.setLAngleLoc(TL.getLAngleLoc());
5989 NewTL.setRAngleLoc(TL.getRAngleLoc());
5990 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5991 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005993
Douglas Gregor5a064722011-02-28 17:23:35 +00005994 return Result;
5995}
5996
Mike Stump11289f42009-09-09 15:08:12 +00005997template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005998QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005999TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006000 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006001 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006002
Douglas Gregor844cb502011-03-01 18:12:44 +00006003 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006004 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006005 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006006 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006007 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6008 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006009 return QualType();
6010 }
Mike Stump11289f42009-09-09 15:08:12 +00006011
John McCall31f82722010-11-12 08:19:04 +00006012 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6013 if (NamedT.isNull())
6014 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006015
Richard Smith3f1b5d02011-05-05 21:57:07 +00006016 // C++0x [dcl.type.elab]p2:
6017 // If the identifier resolves to a typedef-name or the simple-template-id
6018 // resolves to an alias template specialization, the
6019 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006020 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6021 if (const TemplateSpecializationType *TST =
6022 NamedT->getAs<TemplateSpecializationType>()) {
6023 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006024 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6025 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006026 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006027 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006028 << TAT << Sema::NTK_TypeAliasTemplate
6029 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006030 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6031 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006032 }
6033 }
6034
John McCall550e0c22009-10-21 00:40:46 +00006035 QualType Result = TL.getType();
6036 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006037 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006038 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006039 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006040 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006041 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006042 if (Result.isNull())
6043 return QualType();
6044 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006045
Abramo Bagnara6150c882010-05-11 21:36:43 +00006046 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006047 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006048 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006049 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006050}
Mike Stump11289f42009-09-09 15:08:12 +00006051
6052template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006053QualType TreeTransform<Derived>::TransformAttributedType(
6054 TypeLocBuilder &TLB,
6055 AttributedTypeLoc TL) {
6056 const AttributedType *oldType = TL.getTypePtr();
6057 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6058 if (modifiedType.isNull())
6059 return QualType();
6060
6061 QualType result = TL.getType();
6062
6063 // FIXME: dependent operand expressions?
6064 if (getDerived().AlwaysRebuild() ||
6065 modifiedType != oldType->getModifiedType()) {
6066 // TODO: this is really lame; we should really be rebuilding the
6067 // equivalent type from first principles.
6068 QualType equivalentType
6069 = getDerived().TransformType(oldType->getEquivalentType());
6070 if (equivalentType.isNull())
6071 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006072
6073 // Check whether we can add nullability; it is only represented as
6074 // type sugar, and therefore cannot be diagnosed in any other way.
6075 if (auto nullability = oldType->getImmediateNullability()) {
6076 if (!modifiedType->canHaveNullability()) {
6077 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00006078 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006079 return QualType();
6080 }
6081 }
6082
John McCall81904512011-01-06 01:58:22 +00006083 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
6084 modifiedType,
6085 equivalentType);
6086 }
6087
6088 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
6089 newTL.setAttrNameLoc(TL.getAttrNameLoc());
6090 if (TL.hasAttrOperand())
6091 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6092 if (TL.hasAttrExprOperand())
6093 newTL.setAttrExprOperand(TL.getAttrExprOperand());
6094 else if (TL.hasAttrEnumOperand())
6095 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
6096
6097 return result;
6098}
6099
6100template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006101QualType
6102TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6103 ParenTypeLoc TL) {
6104 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6105 if (Inner.isNull())
6106 return QualType();
6107
6108 QualType Result = TL.getType();
6109 if (getDerived().AlwaysRebuild() ||
6110 Inner != TL.getInnerLoc().getType()) {
6111 Result = getDerived().RebuildParenType(Inner);
6112 if (Result.isNull())
6113 return QualType();
6114 }
6115
6116 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6117 NewTL.setLParenLoc(TL.getLParenLoc());
6118 NewTL.setRParenLoc(TL.getRParenLoc());
6119 return Result;
6120}
6121
6122template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006123QualType TreeTransform<Derived>::TransformDependentNameType(
6124 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6125 return TransformDependentNameType(TLB, TL, false);
6126}
6127
6128template<typename Derived>
6129QualType TreeTransform<Derived>::TransformDependentNameType(
6130 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006131 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006132
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006133 NestedNameSpecifierLoc QualifierLoc
6134 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6135 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006136 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006137
John McCallc392f372010-06-11 00:33:02 +00006138 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006139 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006140 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006141 QualifierLoc,
6142 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006143 TL.getNameLoc(),
6144 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006145 if (Result.isNull())
6146 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006147
Abramo Bagnarad7548482010-05-19 21:37:53 +00006148 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6149 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006150 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6151
Abramo Bagnarad7548482010-05-19 21:37:53 +00006152 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006153 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006154 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006155 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006156 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006157 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006158 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006159 NewTL.setNameLoc(TL.getNameLoc());
6160 }
John McCall550e0c22009-10-21 00:40:46 +00006161 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006162}
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregord6ff3322009-08-04 16:50:30 +00006164template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006165QualType TreeTransform<Derived>::
6166 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006167 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006168 NestedNameSpecifierLoc QualifierLoc;
6169 if (TL.getQualifierLoc()) {
6170 QualifierLoc
6171 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6172 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006173 return QualType();
6174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006175
John McCall31f82722010-11-12 08:19:04 +00006176 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006177 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006178}
6179
6180template<typename Derived>
6181QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006182TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6183 DependentTemplateSpecializationTypeLoc TL,
6184 NestedNameSpecifierLoc QualifierLoc) {
6185 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006186
Douglas Gregora7a795b2011-03-01 20:11:18 +00006187 TemplateArgumentListInfo NewTemplateArgs;
6188 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6189 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006190
Douglas Gregora7a795b2011-03-01 20:11:18 +00006191 typedef TemplateArgumentLocContainerIterator<
6192 DependentTemplateSpecializationTypeLoc> ArgIterator;
6193 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6194 ArgIterator(TL, TL.getNumArgs()),
6195 NewTemplateArgs))
6196 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006197
Richard Smithfd3dae02017-01-20 00:20:39 +00006198 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006199 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6200 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006201 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006202 if (Result.isNull())
6203 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006204
Douglas Gregora7a795b2011-03-01 20:11:18 +00006205 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6206 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006207
Douglas Gregora7a795b2011-03-01 20:11:18 +00006208 // Copy information relevant to the template specialization.
6209 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006210 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006211 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006212 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006213 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6214 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006215 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006216 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006217
Douglas Gregora7a795b2011-03-01 20:11:18 +00006218 // Copy information relevant to the elaborated type.
6219 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006220 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006221 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006222 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6223 DependentTemplateSpecializationTypeLoc SpecTL
6224 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006225 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006226 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006227 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006228 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006229 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6230 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006231 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006232 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006233 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006234 TemplateSpecializationTypeLoc SpecTL
6235 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006236 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006237 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006238 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6239 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006240 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006241 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006242 }
6243 return Result;
6244}
6245
6246template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006247QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6248 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006249 QualType Pattern
6250 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006251 if (Pattern.isNull())
6252 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006253
6254 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006255 if (getDerived().AlwaysRebuild() ||
6256 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006257 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006258 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006259 TL.getEllipsisLoc(),
6260 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006261 if (Result.isNull())
6262 return QualType();
6263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006264
Douglas Gregor822d0302011-01-12 17:07:58 +00006265 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6266 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6267 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006268}
6269
6270template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006271QualType
6272TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006273 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006274 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006275 TLB.pushFullCopy(TL);
6276 return TL.getType();
6277}
6278
6279template<typename Derived>
6280QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006281TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6282 ObjCTypeParamTypeLoc TL) {
6283 const ObjCTypeParamType *T = TL.getTypePtr();
6284 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6285 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6286 if (!OTP)
6287 return QualType();
6288
6289 QualType Result = TL.getType();
6290 if (getDerived().AlwaysRebuild() ||
6291 OTP != T->getDecl()) {
6292 Result = getDerived().RebuildObjCTypeParamType(OTP,
6293 TL.getProtocolLAngleLoc(),
6294 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6295 TL.getNumProtocols()),
6296 TL.getProtocolLocs(),
6297 TL.getProtocolRAngleLoc());
6298 if (Result.isNull())
6299 return QualType();
6300 }
6301
6302 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6303 if (TL.getNumProtocols()) {
6304 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6305 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6306 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6307 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6308 }
6309 return Result;
6310}
6311
6312template<typename Derived>
6313QualType
John McCall8b07ec22010-05-15 11:32:37 +00006314TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006315 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006316 // Transform base type.
6317 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6318 if (BaseType.isNull())
6319 return QualType();
6320
6321 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6322
6323 // Transform type arguments.
6324 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6325 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6326 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6327 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6328 QualType TypeArg = TypeArgInfo->getType();
6329 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6330 AnyChanged = true;
6331
6332 // We have a pack expansion. Instantiate it.
6333 const auto *PackExpansion = PackExpansionLoc.getType()
6334 ->castAs<PackExpansionType>();
6335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6336 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6337 Unexpanded);
6338 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6339
6340 // Determine whether the set of unexpanded parameter packs can
6341 // and should be expanded.
6342 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6343 bool Expand = false;
6344 bool RetainExpansion = false;
6345 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6346 if (getDerived().TryExpandParameterPacks(
6347 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6348 Unexpanded, Expand, RetainExpansion, NumExpansions))
6349 return QualType();
6350
6351 if (!Expand) {
6352 // We can't expand this pack expansion into separate arguments yet;
6353 // just substitute into the pattern and create a new pack expansion
6354 // type.
6355 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6356
6357 TypeLocBuilder TypeArgBuilder;
6358 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6359 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6360 PatternLoc);
6361 if (NewPatternType.isNull())
6362 return QualType();
6363
6364 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6365 NewPatternType, NumExpansions);
6366 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6367 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6368 NewTypeArgInfos.push_back(
6369 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6370 continue;
6371 }
6372
6373 // Substitute into the pack expansion pattern for each slice of the
6374 // pack.
6375 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6377
6378 TypeLocBuilder TypeArgBuilder;
6379 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6380
6381 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6382 PatternLoc);
6383 if (NewTypeArg.isNull())
6384 return QualType();
6385
6386 NewTypeArgInfos.push_back(
6387 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6388 }
6389
6390 continue;
6391 }
6392
6393 TypeLocBuilder TypeArgBuilder;
6394 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6395 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6396 if (NewTypeArg.isNull())
6397 return QualType();
6398
6399 // If nothing changed, just keep the old TypeSourceInfo.
6400 if (NewTypeArg == TypeArg) {
6401 NewTypeArgInfos.push_back(TypeArgInfo);
6402 continue;
6403 }
6404
6405 NewTypeArgInfos.push_back(
6406 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6407 AnyChanged = true;
6408 }
6409
6410 QualType Result = TL.getType();
6411 if (getDerived().AlwaysRebuild() || AnyChanged) {
6412 // Rebuild the type.
6413 Result = getDerived().RebuildObjCObjectType(
6414 BaseType,
6415 TL.getLocStart(),
6416 TL.getTypeArgsLAngleLoc(),
6417 NewTypeArgInfos,
6418 TL.getTypeArgsRAngleLoc(),
6419 TL.getProtocolLAngleLoc(),
6420 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6421 TL.getNumProtocols()),
6422 TL.getProtocolLocs(),
6423 TL.getProtocolRAngleLoc());
6424
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 {
6659 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6660 }
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
Rafael Espindolaab417692013-07-09 12:05:01 +00006878 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), 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,
7711 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
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,
7719 D->getLocStart());
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,
7730 D->getLocStart());
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,
7741 D->getLocStart());
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,
7752 D->getLocStart());
7753 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,
7763 D->getLocStart());
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,
7774 D->getLocStart());
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,
7785 D->getLocStart());
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,
7796 D->getLocStart());
7797 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(
7806 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7807 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,
7817 nullptr, D->getLocStart());
7818 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,
7828 nullptr, D->getLocStart());
7829 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,
7839 nullptr, D->getLocStart());
7840 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,
7850 D->getLocStart());
7851 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,
7861 D->getLocStart());
7862 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,
7872 D->getLocStart());
7873 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,
7883 D->getLocStart());
7884 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,
7894 D->getLocStart());
7895 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,
7905 D->getLocStart());
7906 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,
7916 D->getLocStart());
7917 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,
7927 D->getLocStart());
7928 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,
7938 D->getLocStart());
7939 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,
7949 D->getLocStart());
7950 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,
7960 nullptr, D->getLocStart());
7961 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,
7971 nullptr, D->getLocStart());
7972 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,
7982 nullptr, D->getLocStart());
7983 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,
7993 nullptr, D->getLocStart());
7994 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,
8004 nullptr, D->getLocStart());
8005 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,
8015 D->getLocStart());
8016 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,
8026 nullptr, D->getLocStart());
8027 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,
8037 D->getLocStart());
8038 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,
8048 D->getLocStart());
8049 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,
8059 nullptr, D->getLocStart());
8060 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,
8070 D->getLocStart());
8071 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(
8081 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
8082 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(
8093 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8094 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,
8104 nullptr, D->getLocStart());
8105 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;
8114 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8115 DirName, nullptr,
8116 D->getLocStart());
8117 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8118 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8119 return Res;
8120}
8121
Kelvin Li986330c2016-07-20 22:57:10 +00008122template <typename Derived>
8123StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8124 OMPTargetSimdDirective *D) {
8125 DeclarationNameInfo DirName;
8126 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8127 D->getLocStart());
8128 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8129 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8130 return Res;
8131}
8132
Kelvin Li02532872016-08-05 14:37:37 +00008133template <typename Derived>
8134StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8135 OMPTeamsDistributeDirective *D) {
8136 DeclarationNameInfo DirName;
8137 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8138 nullptr, D->getLocStart());
8139 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8140 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8141 return Res;
8142}
8143
Kelvin Li4e325f72016-10-25 12:50:55 +00008144template <typename Derived>
8145StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8146 OMPTeamsDistributeSimdDirective *D) {
8147 DeclarationNameInfo DirName;
8148 getDerived().getSema().StartOpenMPDSABlock(
8149 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8150 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8151 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8152 return Res;
8153}
8154
Kelvin Li579e41c2016-11-30 23:51:03 +00008155template <typename Derived>
8156StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8157 OMPTeamsDistributeParallelForSimdDirective *D) {
8158 DeclarationNameInfo DirName;
8159 getDerived().getSema().StartOpenMPDSABlock(
8160 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8161 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;
8170 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8171 DirName, nullptr, D->getLocStart());
8172 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,
8182 nullptr, D->getLocStart());
8183 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;
8192 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8193 DirName, nullptr, D->getLocStart());
8194 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,
8206 D->getLocStart());
8207 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,
8219 D->getLocStart());
8220 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(
8231 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8232 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(
8247 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8248 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
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;
8256 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8257 C->getLParenLoc(), C->getLocEnd());
8258}
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(
8267 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
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(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008277 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
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(
8287 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8288}
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(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008297 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
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(
8304 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8305 C->getLParenLoc(), C->getLocEnd());
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(
8312 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8313 C->getLParenLoc(), C->getLocEnd());
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(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008324 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008325 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008326 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8327}
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 }
8338 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8339 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>
8417OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008418TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008419 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008420 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008421 for (auto *VE : C->varlists()) {
8422 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008423 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008424 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008425 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008426 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008427 return getDerived().RebuildOMPPrivateClause(
8428 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008429}
8430
Alexander Musman64d33f12014-06-04 07:53:32 +00008431template <typename Derived>
8432OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8433 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008434 llvm::SmallVector<Expr *, 16> Vars;
8435 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008436 for (auto *VE : C->varlists()) {
8437 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008438 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008439 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008440 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008441 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008442 return getDerived().RebuildOMPFirstprivateClause(
8443 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008444}
8445
Alexander Musman64d33f12014-06-04 07:53:32 +00008446template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008447OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008448TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8449 llvm::SmallVector<Expr *, 16> Vars;
8450 Vars.reserve(C->varlist_size());
8451 for (auto *VE : C->varlists()) {
8452 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8453 if (EVar.isInvalid())
8454 return nullptr;
8455 Vars.push_back(EVar.get());
8456 }
8457 return getDerived().RebuildOMPLastprivateClause(
8458 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8459}
8460
8461template <typename Derived>
8462OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008463TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8464 llvm::SmallVector<Expr *, 16> Vars;
8465 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008466 for (auto *VE : C->varlists()) {
8467 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008468 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008469 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008470 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008471 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008472 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8473 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008474}
8475
Alexander Musman64d33f12014-06-04 07:53:32 +00008476template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008477OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008478TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8479 llvm::SmallVector<Expr *, 16> Vars;
8480 Vars.reserve(C->varlist_size());
8481 for (auto *VE : C->varlists()) {
8482 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8483 if (EVar.isInvalid())
8484 return nullptr;
8485 Vars.push_back(EVar.get());
8486 }
8487 CXXScopeSpec ReductionIdScopeSpec;
8488 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8489
8490 DeclarationNameInfo NameInfo = C->getNameInfo();
8491 if (NameInfo.getName()) {
8492 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8493 if (!NameInfo.getName())
8494 return nullptr;
8495 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008496 // Build a list of all UDR decls with the same names ranged by the Scopes.
8497 // The Scope boundary is a duplication of the previous decl.
8498 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8499 for (auto *E : C->reduction_ops()) {
8500 // Transform all the decls.
8501 if (E) {
8502 auto *ULE = cast<UnresolvedLookupExpr>(E);
8503 UnresolvedSet<8> Decls;
8504 for (auto *D : ULE->decls()) {
8505 NamedDecl *InstD =
8506 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8507 Decls.addDecl(InstD, InstD->getAccess());
8508 }
8509 UnresolvedReductions.push_back(
8510 UnresolvedLookupExpr::Create(
8511 SemaRef.Context, /*NamingClass=*/nullptr,
8512 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8513 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8514 Decls.begin(), Decls.end()));
8515 } else
8516 UnresolvedReductions.push_back(nullptr);
8517 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008518 return getDerived().RebuildOMPReductionClause(
8519 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008520 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008521}
8522
8523template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008524OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8525 OMPTaskReductionClause *C) {
8526 llvm::SmallVector<Expr *, 16> Vars;
8527 Vars.reserve(C->varlist_size());
8528 for (auto *VE : C->varlists()) {
8529 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8530 if (EVar.isInvalid())
8531 return nullptr;
8532 Vars.push_back(EVar.get());
8533 }
8534 CXXScopeSpec ReductionIdScopeSpec;
8535 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8536
8537 DeclarationNameInfo NameInfo = C->getNameInfo();
8538 if (NameInfo.getName()) {
8539 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8540 if (!NameInfo.getName())
8541 return nullptr;
8542 }
8543 // Build a list of all UDR decls with the same names ranged by the Scopes.
8544 // The Scope boundary is a duplication of the previous decl.
8545 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8546 for (auto *E : C->reduction_ops()) {
8547 // Transform all the decls.
8548 if (E) {
8549 auto *ULE = cast<UnresolvedLookupExpr>(E);
8550 UnresolvedSet<8> Decls;
8551 for (auto *D : ULE->decls()) {
8552 NamedDecl *InstD =
8553 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8554 Decls.addDecl(InstD, InstD->getAccess());
8555 }
8556 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8557 SemaRef.Context, /*NamingClass=*/nullptr,
8558 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8559 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8560 } else
8561 UnresolvedReductions.push_back(nullptr);
8562 }
8563 return getDerived().RebuildOMPTaskReductionClause(
8564 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8565 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8566}
8567
8568template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008569OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008570TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8571 llvm::SmallVector<Expr *, 16> Vars;
8572 Vars.reserve(C->varlist_size());
8573 for (auto *VE : C->varlists()) {
8574 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8575 if (EVar.isInvalid())
8576 return nullptr;
8577 Vars.push_back(EVar.get());
8578 }
8579 CXXScopeSpec ReductionIdScopeSpec;
8580 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8581
8582 DeclarationNameInfo NameInfo = C->getNameInfo();
8583 if (NameInfo.getName()) {
8584 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8585 if (!NameInfo.getName())
8586 return nullptr;
8587 }
8588 // Build a list of all UDR decls with the same names ranged by the Scopes.
8589 // The Scope boundary is a duplication of the previous decl.
8590 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8591 for (auto *E : C->reduction_ops()) {
8592 // Transform all the decls.
8593 if (E) {
8594 auto *ULE = cast<UnresolvedLookupExpr>(E);
8595 UnresolvedSet<8> Decls;
8596 for (auto *D : ULE->decls()) {
8597 NamedDecl *InstD =
8598 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8599 Decls.addDecl(InstD, InstD->getAccess());
8600 }
8601 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8602 SemaRef.Context, /*NamingClass=*/nullptr,
8603 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8604 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8605 } else
8606 UnresolvedReductions.push_back(nullptr);
8607 }
8608 return getDerived().RebuildOMPInReductionClause(
8609 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8610 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8611}
8612
8613template <typename Derived>
8614OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008615TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8616 llvm::SmallVector<Expr *, 16> Vars;
8617 Vars.reserve(C->varlist_size());
8618 for (auto *VE : C->varlists()) {
8619 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8620 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008621 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008622 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008623 }
8624 ExprResult Step = getDerived().TransformExpr(C->getStep());
8625 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008626 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008627 return getDerived().RebuildOMPLinearClause(
8628 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8629 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008630}
8631
Alexander Musman64d33f12014-06-04 07:53:32 +00008632template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008633OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008634TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8635 llvm::SmallVector<Expr *, 16> Vars;
8636 Vars.reserve(C->varlist_size());
8637 for (auto *VE : C->varlists()) {
8638 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8639 if (EVar.isInvalid())
8640 return nullptr;
8641 Vars.push_back(EVar.get());
8642 }
8643 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8644 if (Alignment.isInvalid())
8645 return nullptr;
8646 return getDerived().RebuildOMPAlignedClause(
8647 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8648 C->getColonLoc(), C->getLocEnd());
8649}
8650
Alexander Musman64d33f12014-06-04 07:53:32 +00008651template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008652OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008653TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8654 llvm::SmallVector<Expr *, 16> Vars;
8655 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008656 for (auto *VE : C->varlists()) {
8657 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008658 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008659 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008660 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008661 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008662 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8663 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008664}
8665
Alexey Bataevbae9a792014-06-27 10:37:06 +00008666template <typename Derived>
8667OMPClause *
8668TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8669 llvm::SmallVector<Expr *, 16> Vars;
8670 Vars.reserve(C->varlist_size());
8671 for (auto *VE : C->varlists()) {
8672 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8673 if (EVar.isInvalid())
8674 return nullptr;
8675 Vars.push_back(EVar.get());
8676 }
8677 return getDerived().RebuildOMPCopyprivateClause(
8678 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8679}
8680
Alexey Bataev6125da92014-07-21 11:26:11 +00008681template <typename Derived>
8682OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8683 llvm::SmallVector<Expr *, 16> Vars;
8684 Vars.reserve(C->varlist_size());
8685 for (auto *VE : C->varlists()) {
8686 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8687 if (EVar.isInvalid())
8688 return nullptr;
8689 Vars.push_back(EVar.get());
8690 }
8691 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8692 C->getLParenLoc(), C->getLocEnd());
8693}
8694
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008695template <typename Derived>
8696OMPClause *
8697TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8698 llvm::SmallVector<Expr *, 16> Vars;
8699 Vars.reserve(C->varlist_size());
8700 for (auto *VE : C->varlists()) {
8701 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8702 if (EVar.isInvalid())
8703 return nullptr;
8704 Vars.push_back(EVar.get());
8705 }
8706 return getDerived().RebuildOMPDependClause(
8707 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8708 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8709}
8710
Michael Wonge710d542015-08-07 16:16:36 +00008711template <typename Derived>
8712OMPClause *
8713TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8714 ExprResult E = getDerived().TransformExpr(C->getDevice());
8715 if (E.isInvalid())
8716 return nullptr;
8717 return getDerived().RebuildOMPDeviceClause(
8718 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8719}
8720
Kelvin Li0bff7af2015-11-23 05:32:03 +00008721template <typename Derived>
8722OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8723 llvm::SmallVector<Expr *, 16> Vars;
8724 Vars.reserve(C->varlist_size());
8725 for (auto *VE : C->varlists()) {
8726 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8727 if (EVar.isInvalid())
8728 return nullptr;
8729 Vars.push_back(EVar.get());
8730 }
8731 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008732 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8733 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8734 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008735}
8736
Kelvin Li099bb8c2015-11-24 20:50:12 +00008737template <typename Derived>
8738OMPClause *
8739TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8740 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8741 if (E.isInvalid())
8742 return nullptr;
8743 return getDerived().RebuildOMPNumTeamsClause(
8744 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8745}
8746
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008747template <typename Derived>
8748OMPClause *
8749TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8750 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8751 if (E.isInvalid())
8752 return nullptr;
8753 return getDerived().RebuildOMPThreadLimitClause(
8754 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8755}
8756
Alexey Bataeva0569352015-12-01 10:17:31 +00008757template <typename Derived>
8758OMPClause *
8759TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8760 ExprResult E = getDerived().TransformExpr(C->getPriority());
8761 if (E.isInvalid())
8762 return nullptr;
8763 return getDerived().RebuildOMPPriorityClause(
8764 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8765}
8766
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008767template <typename Derived>
8768OMPClause *
8769TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8770 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8771 if (E.isInvalid())
8772 return nullptr;
8773 return getDerived().RebuildOMPGrainsizeClause(
8774 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8775}
8776
Alexey Bataev382967a2015-12-08 12:06:20 +00008777template <typename Derived>
8778OMPClause *
8779TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8780 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8781 if (E.isInvalid())
8782 return nullptr;
8783 return getDerived().RebuildOMPNumTasksClause(
8784 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8785}
8786
Alexey Bataev28c75412015-12-15 08:19:24 +00008787template <typename Derived>
8788OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8789 ExprResult E = getDerived().TransformExpr(C->getHint());
8790 if (E.isInvalid())
8791 return nullptr;
8792 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8793 C->getLParenLoc(), C->getLocEnd());
8794}
8795
Carlo Bertollib4adf552016-01-15 18:50:31 +00008796template <typename Derived>
8797OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8798 OMPDistScheduleClause *C) {
8799 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8800 if (E.isInvalid())
8801 return nullptr;
8802 return getDerived().RebuildOMPDistScheduleClause(
8803 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8804 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8805}
8806
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008807template <typename Derived>
8808OMPClause *
8809TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8810 return C;
8811}
8812
Samuel Antao661c0902016-05-26 17:39:58 +00008813template <typename Derived>
8814OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8815 llvm::SmallVector<Expr *, 16> Vars;
8816 Vars.reserve(C->varlist_size());
8817 for (auto *VE : C->varlists()) {
8818 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8819 if (EVar.isInvalid())
8820 return 0;
8821 Vars.push_back(EVar.get());
8822 }
8823 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8824 C->getLParenLoc(), C->getLocEnd());
8825}
8826
Samuel Antaoec172c62016-05-26 17:49:04 +00008827template <typename Derived>
8828OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8829 llvm::SmallVector<Expr *, 16> Vars;
8830 Vars.reserve(C->varlist_size());
8831 for (auto *VE : C->varlists()) {
8832 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8833 if (EVar.isInvalid())
8834 return 0;
8835 Vars.push_back(EVar.get());
8836 }
8837 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8838 C->getLParenLoc(), C->getLocEnd());
8839}
8840
Carlo Bertolli2404b172016-07-13 15:37:16 +00008841template <typename Derived>
8842OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8843 OMPUseDevicePtrClause *C) {
8844 llvm::SmallVector<Expr *, 16> Vars;
8845 Vars.reserve(C->varlist_size());
8846 for (auto *VE : C->varlists()) {
8847 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8848 if (EVar.isInvalid())
8849 return nullptr;
8850 Vars.push_back(EVar.get());
8851 }
8852 return getDerived().RebuildOMPUseDevicePtrClause(
8853 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8854}
8855
Carlo Bertolli70594e92016-07-13 17:16:49 +00008856template <typename Derived>
8857OMPClause *
8858TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8859 llvm::SmallVector<Expr *, 16> Vars;
8860 Vars.reserve(C->varlist_size());
8861 for (auto *VE : C->varlists()) {
8862 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8863 if (EVar.isInvalid())
8864 return nullptr;
8865 Vars.push_back(EVar.get());
8866 }
8867 return getDerived().RebuildOMPIsDevicePtrClause(
8868 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8869}
8870
Douglas Gregorebe10102009-08-20 07:17:43 +00008871//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008872// Expression transformation
8873//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008875ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008876TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008877 if (!E->isTypeDependent())
8878 return E;
8879
8880 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8881 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008882}
Mike Stump11289f42009-09-09 15:08:12 +00008883
8884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008886TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008887 NestedNameSpecifierLoc QualifierLoc;
8888 if (E->getQualifierLoc()) {
8889 QualifierLoc
8890 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8891 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008892 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008893 }
John McCallce546572009-12-08 09:08:17 +00008894
8895 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008896 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8897 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008898 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008899 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008900
John McCall815039a2010-08-17 21:27:17 +00008901 DeclarationNameInfo NameInfo = E->getNameInfo();
8902 if (NameInfo.getName()) {
8903 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8904 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008905 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008906 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008907
8908 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008909 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008910 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008911 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008912 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008913
8914 // Mark it referenced in the new context regardless.
8915 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008916 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008917
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008918 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008919 }
John McCallce546572009-12-08 09:08:17 +00008920
Craig Topperc3ec1492014-05-26 06:22:03 +00008921 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008922 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008923 TemplateArgs = &TransArgs;
8924 TransArgs.setLAngleLoc(E->getLAngleLoc());
8925 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008926 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8927 E->getNumTemplateArgs(),
8928 TransArgs))
8929 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008930 }
8931
Chad Rosier1dcde962012-08-08 18:46:20 +00008932 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008933 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008934}
Mike Stump11289f42009-09-09 15:08:12 +00008935
Douglas Gregora16548e2009-08-11 05:31:07 +00008936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008937ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008938TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008939 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008940}
Mike Stump11289f42009-09-09 15:08:12 +00008941
Leonard Chandb01c3a2018-06-20 17:19:40 +00008942template <typename Derived>
8943ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
8944 FixedPointLiteral *E) {
8945 return E;
8946}
8947
Douglas Gregora16548e2009-08-11 05:31:07 +00008948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008950TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008951 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008952}
Mike Stump11289f42009-09-09 15:08:12 +00008953
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>::TransformImaginaryLiteral(ImaginaryLiteral *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>::TransformStringLiteral(StringLiteral *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>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008969 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008970}
8971
8972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008973ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008974TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008975 if (FunctionDecl *FD = E->getDirectCallee())
8976 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008977 return SemaRef.MaybeBindToTemporary(E);
8978}
8979
8980template<typename Derived>
8981ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008982TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8983 ExprResult ControllingExpr =
8984 getDerived().TransformExpr(E->getControllingExpr());
8985 if (ControllingExpr.isInvalid())
8986 return ExprError();
8987
Chris Lattner01cf8db2011-07-20 06:58:45 +00008988 SmallVector<Expr *, 4> AssocExprs;
8989 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008990 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8991 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8992 if (TS) {
8993 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8994 if (!AssocType)
8995 return ExprError();
8996 AssocTypes.push_back(AssocType);
8997 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008998 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008999 }
9000
9001 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
9002 if (AssocExpr.isInvalid())
9003 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009004 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009005 }
9006
9007 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9008 E->getDefaultLoc(),
9009 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009010 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009011 AssocTypes,
9012 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009013}
9014
9015template<typename Derived>
9016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009017TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009018 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009019 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009020 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009021
Douglas Gregora16548e2009-08-11 05:31:07 +00009022 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009023 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009024
John McCallb268a282010-08-23 23:25:46 +00009025 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009026 E->getRParen());
9027}
9028
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009029/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009030/// allowed to refer to a non-static member of a class even if there's no 'this'
9031/// object available.
9032template<typename Derived>
9033ExprResult
9034TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9035 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009036 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009037 else
9038 return getDerived().TransformExpr(E);
9039}
9040
Mike Stump11289f42009-09-09 15:08:12 +00009041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009043TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009044 ExprResult SubExpr;
9045 if (E->getOpcode() == UO_AddrOf)
9046 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9047 else
9048 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009049 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009051
Douglas Gregora16548e2009-08-11 05:31:07 +00009052 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009053 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9056 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009057 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009058}
Mike Stump11289f42009-09-09 15:08:12 +00009059
Douglas Gregora16548e2009-08-11 05:31:07 +00009060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009061ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009062TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9063 // Transform the type.
9064 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9065 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009066 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009067
Douglas Gregor882211c2010-04-28 22:16:22 +00009068 // Transform all of the components into components similar to what the
9069 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009070 // FIXME: It would be slightly more efficient in the non-dependent case to
9071 // just map FieldDecls, rather than requiring the rebuilder to look for
9072 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009073 // template code that we don't care.
9074 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009075 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009076 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009077 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009078 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009079 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009080 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009081 Comp.LocStart = ON.getSourceRange().getBegin();
9082 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009083 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009084 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009085 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009086 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009087 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009088 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009089
Douglas Gregor882211c2010-04-28 22:16:22 +00009090 ExprChanged = ExprChanged || Index.get() != FromIndex;
9091 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009092 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009093 break;
9094 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
James Y Knight7281c352015-12-29 22:31:18 +00009096 case OffsetOfNode::Field:
9097 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009098 Comp.isBrackets = false;
9099 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009100 if (!Comp.U.IdentInfo)
9101 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009102
Douglas Gregor882211c2010-04-28 22:16:22 +00009103 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009104
James Y Knight7281c352015-12-29 22:31:18 +00009105 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009106 // Will be recomputed during the rebuild.
9107 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009108 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009109
Douglas Gregor882211c2010-04-28 22:16:22 +00009110 Components.push_back(Comp);
9111 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Douglas Gregor882211c2010-04-28 22:16:22 +00009113 // If nothing changed, retain the existing expression.
9114 if (!getDerived().AlwaysRebuild() &&
9115 Type == E->getTypeSourceInfo() &&
9116 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009117 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009118
Douglas Gregor882211c2010-04-28 22:16:22 +00009119 // Build a new offsetof expression.
9120 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009121 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009122}
9123
9124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009125ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009126TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009127 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009128 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009129 return E;
John McCall8d69a212010-11-15 23:31:06 +00009130}
9131
9132template<typename Derived>
9133ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009134TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9135 return E;
9136}
9137
9138template<typename Derived>
9139ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009140TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009141 // Rebuild the syntactic form. The original syntactic form has
9142 // opaque-value expressions in it, so strip those away and rebuild
9143 // the result. This is a really awful way of doing this, but the
9144 // better solution (rebuilding the semantic expressions and
9145 // rebinding OVEs as necessary) doesn't work; we'd need
9146 // TreeTransform to not strip away implicit conversions.
9147 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9148 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009149 if (result.isInvalid()) return ExprError();
9150
9151 // If that gives us a pseudo-object result back, the pseudo-object
9152 // expression must have been an lvalue-to-rvalue conversion which we
9153 // should reapply.
9154 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009155 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009156
9157 return result;
9158}
9159
9160template<typename Derived>
9161ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009162TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9163 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009164 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009165 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009166
John McCallbcd03502009-12-07 02:54:59 +00009167 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009168 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009170
John McCall4c98fd82009-11-04 07:28:41 +00009171 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009172 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009173
Peter Collingbournee190dee2011-03-11 19:24:49 +00009174 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9175 E->getKind(),
9176 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009177 }
Mike Stump11289f42009-09-09 15:08:12 +00009178
Eli Friedmane4f22df2012-02-29 04:03:55 +00009179 // C++0x [expr.sizeof]p1:
9180 // The operand is either an expression, which is an unevaluated operand
9181 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009182 EnterExpressionEvaluationContext Unevaluated(
9183 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9184 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009185
Reid Kleckner32506ed2014-06-12 23:03:48 +00009186 // Try to recover if we have something like sizeof(T::X) where X is a type.
9187 // Notably, there must be *exactly* one set of parens if X is a type.
9188 TypeSourceInfo *RecoveryTSI = nullptr;
9189 ExprResult SubExpr;
9190 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9191 if (auto *DRE =
9192 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9193 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9194 PE, DRE, false, &RecoveryTSI);
9195 else
9196 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9197
9198 if (RecoveryTSI) {
9199 return getDerived().RebuildUnaryExprOrTypeTrait(
9200 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9201 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009203
Eli Friedmane4f22df2012-02-29 04:03:55 +00009204 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009205 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009206
Peter Collingbournee190dee2011-03-11 19:24:49 +00009207 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9208 E->getOperatorLoc(),
9209 E->getKind(),
9210 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009211}
Mike Stump11289f42009-09-09 15:08:12 +00009212
Douglas Gregora16548e2009-08-11 05:31:07 +00009213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009214ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009215TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009216 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009217 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009218 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009219
John McCalldadc5752010-08-24 06:29:42 +00009220 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009221 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009223
9224
Douglas Gregora16548e2009-08-11 05:31:07 +00009225 if (!getDerived().AlwaysRebuild() &&
9226 LHS.get() == E->getLHS() &&
9227 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009228 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009229
John McCallb268a282010-08-23 23:25:46 +00009230 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009231 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009232 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009233 E->getRBracketLoc());
9234}
Mike Stump11289f42009-09-09 15:08:12 +00009235
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009236template <typename Derived>
9237ExprResult
9238TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9239 ExprResult Base = getDerived().TransformExpr(E->getBase());
9240 if (Base.isInvalid())
9241 return ExprError();
9242
9243 ExprResult LowerBound;
9244 if (E->getLowerBound()) {
9245 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9246 if (LowerBound.isInvalid())
9247 return ExprError();
9248 }
9249
9250 ExprResult Length;
9251 if (E->getLength()) {
9252 Length = getDerived().TransformExpr(E->getLength());
9253 if (Length.isInvalid())
9254 return ExprError();
9255 }
9256
9257 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9258 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9259 return E;
9260
9261 return getDerived().RebuildOMPArraySectionExpr(
9262 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9263 Length.get(), E->getRBracketLoc());
9264}
9265
Mike Stump11289f42009-09-09 15:08:12 +00009266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009268TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009269 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009270 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009272 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009273
9274 // Transform arguments.
9275 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009276 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009277 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009278 &ArgChanged))
9279 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009280
Douglas Gregora16548e2009-08-11 05:31:07 +00009281 if (!getDerived().AlwaysRebuild() &&
9282 Callee.get() == E->getCallee() &&
9283 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009284 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009285
Douglas Gregora16548e2009-08-11 05:31:07 +00009286 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009287 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009288 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009289 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009290 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009291 E->getRParenLoc());
9292}
Mike Stump11289f42009-09-09 15:08:12 +00009293
9294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009295ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009296TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009297 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009298 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009300
Douglas Gregorea972d32011-02-28 21:54:11 +00009301 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009302 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009303 QualifierLoc
9304 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009305
Douglas Gregorea972d32011-02-28 21:54:11 +00009306 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009307 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009308 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009309 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009310
Eli Friedman2cfcef62009-12-04 06:40:45 +00009311 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009312 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9313 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009314 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009316
John McCall16df1e52010-03-30 21:47:33 +00009317 NamedDecl *FoundDecl = E->getFoundDecl();
9318 if (FoundDecl == E->getMemberDecl()) {
9319 FoundDecl = Member;
9320 } else {
9321 FoundDecl = cast_or_null<NamedDecl>(
9322 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9323 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009324 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009325 }
9326
Douglas Gregora16548e2009-08-11 05:31:07 +00009327 if (!getDerived().AlwaysRebuild() &&
9328 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009329 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009330 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009331 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009332 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009333
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009334 // Mark it referenced in the new context regardless.
9335 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009336 SemaRef.MarkMemberReferenced(E);
9337
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009338 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009339 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009340
John McCall6b51f282009-11-23 01:53:49 +00009341 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009342 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009343 TransArgs.setLAngleLoc(E->getLAngleLoc());
9344 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009345 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9346 E->getNumTemplateArgs(),
9347 TransArgs))
9348 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009350
Douglas Gregora16548e2009-08-11 05:31:07 +00009351 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009352 SourceLocation FakeOperatorLoc =
9353 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009354
John McCall38836f02010-01-15 08:34:02 +00009355 // FIXME: to do this check properly, we will need to preserve the
9356 // first-qualifier-in-scope here, just in case we had a dependent
9357 // base (and therefore couldn't do the check) and a
9358 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009359 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009360 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9361 if (MemberNameInfo.getName()) {
9362 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9363 if (!MemberNameInfo.getName())
9364 return ExprError();
9365 }
John McCall38836f02010-01-15 08:34:02 +00009366
John McCallb268a282010-08-23 23:25:46 +00009367 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009368 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009369 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009370 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009371 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009372 Member,
John McCall16df1e52010-03-30 21:47:33 +00009373 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009374 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009375 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009376 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009377}
Mike Stump11289f42009-09-09 15:08:12 +00009378
Douglas Gregora16548e2009-08-11 05:31:07 +00009379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009381TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009382 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009383 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009384 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009385
John McCalldadc5752010-08-24 06:29:42 +00009386 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009387 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009389
Douglas Gregora16548e2009-08-11 05:31:07 +00009390 if (!getDerived().AlwaysRebuild() &&
9391 LHS.get() == E->getLHS() &&
9392 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009393 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009394
Lang Hames5de91cc2012-10-02 04:45:10 +00009395 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009396 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009397
Douglas Gregora16548e2009-08-11 05:31:07 +00009398 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009399 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009400}
9401
Mike Stump11289f42009-09-09 15:08:12 +00009402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009403ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009404TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009405 CompoundAssignOperator *E) {
9406 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009407}
Mike Stump11289f42009-09-09 15:08:12 +00009408
Douglas Gregora16548e2009-08-11 05:31:07 +00009409template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009410ExprResult TreeTransform<Derived>::
9411TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9412 // Just rebuild the common and RHS expressions and see whether we
9413 // get any changes.
9414
9415 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9416 if (commonExpr.isInvalid())
9417 return ExprError();
9418
9419 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9420 if (rhs.isInvalid())
9421 return ExprError();
9422
9423 if (!getDerived().AlwaysRebuild() &&
9424 commonExpr.get() == e->getCommon() &&
9425 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009426 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009427
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009428 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009429 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009430 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009431 e->getColonLoc(),
9432 rhs.get());
9433}
9434
9435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009437TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009438 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009439 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009440 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009441
John McCalldadc5752010-08-24 06:29:42 +00009442 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009443 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009445
John McCalldadc5752010-08-24 06:29:42 +00009446 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009447 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009449
Douglas Gregora16548e2009-08-11 05:31:07 +00009450 if (!getDerived().AlwaysRebuild() &&
9451 Cond.get() == E->getCond() &&
9452 LHS.get() == E->getLHS() &&
9453 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009454 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009455
John McCallb268a282010-08-23 23:25:46 +00009456 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009457 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009458 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009459 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009460 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009461}
Mike Stump11289f42009-09-09 15:08:12 +00009462
9463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009464ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009465TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009466 // Implicit casts are eliminated during transformation, since they
9467 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009468 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009469}
Mike Stump11289f42009-09-09 15:08:12 +00009470
Douglas Gregora16548e2009-08-11 05:31:07 +00009471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009472ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009473TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009474 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9475 if (!Type)
9476 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009477
John McCalldadc5752010-08-24 06:29:42 +00009478 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009479 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009480 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009482
Douglas Gregora16548e2009-08-11 05:31:07 +00009483 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009484 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009485 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009486 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009487
John McCall97513962010-01-15 18:39:57 +00009488 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009489 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009490 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009491 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009492}
Mike Stump11289f42009-09-09 15:08:12 +00009493
Douglas Gregora16548e2009-08-11 05:31:07 +00009494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009496TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009497 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9498 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9499 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009500 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009501
John McCalldadc5752010-08-24 06:29:42 +00009502 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009503 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009504 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009505
Douglas Gregora16548e2009-08-11 05:31:07 +00009506 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009507 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009508 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009509 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009510
John McCall5d7aa7f2010-01-19 22:33:45 +00009511 // Note: the expression type doesn't necessarily match the
9512 // type-as-written, but that's okay, because it should always be
9513 // derivable from the initializer.
9514
John McCalle15bbff2010-01-18 19:35:47 +00009515 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00009516 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00009517 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009518}
Mike Stump11289f42009-09-09 15:08:12 +00009519
Douglas Gregora16548e2009-08-11 05:31:07 +00009520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009521ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009522TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009523 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009524 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009526
Douglas Gregora16548e2009-08-11 05:31:07 +00009527 if (!getDerived().AlwaysRebuild() &&
9528 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009529 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009530
Douglas Gregora16548e2009-08-11 05:31:07 +00009531 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009532 SourceLocation FakeOperatorLoc =
9533 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00009534 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009535 E->getAccessorLoc(),
9536 E->getAccessor());
9537}
Mike Stump11289f42009-09-09 15:08:12 +00009538
Douglas Gregora16548e2009-08-11 05:31:07 +00009539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009541TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009542 if (InitListExpr *Syntactic = E->getSyntacticForm())
9543 E = Syntactic;
9544
Douglas Gregora16548e2009-08-11 05:31:07 +00009545 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009546
Benjamin Kramerf0623432012-08-23 22:51:59 +00009547 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009548 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009549 Inits, &InitChanged))
9550 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009551
Richard Smith520449d2015-02-05 06:15:50 +00009552 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9553 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9554 // in some cases. We can't reuse it in general, because the syntactic and
9555 // semantic forms are linked, and we can't know that semantic form will
9556 // match even if the syntactic form does.
9557 }
Mike Stump11289f42009-09-09 15:08:12 +00009558
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009559 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009560 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009561}
Mike Stump11289f42009-09-09 15:08:12 +00009562
Douglas Gregora16548e2009-08-11 05:31:07 +00009563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009565TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009566 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009567
Douglas Gregorebe10102009-08-20 07:17:43 +00009568 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009569 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009570 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009572
Douglas Gregorebe10102009-08-20 07:17:43 +00009573 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009574 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009575 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009576 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9577 if (D.isFieldDesignator()) {
9578 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9579 D.getDotLoc(),
9580 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009581 if (D.getField()) {
9582 FieldDecl *Field = cast_or_null<FieldDecl>(
9583 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9584 if (Field != D.getField())
9585 // Rebuild the expression when the transformed FieldDecl is
9586 // different to the already assigned FieldDecl.
9587 ExprChanged = true;
9588 } else {
9589 // Ensure that the designator expression is rebuilt when there isn't
9590 // a resolved FieldDecl in the designator as we don't want to assign
9591 // a FieldDecl to a pattern designator that will be instantiated again.
9592 ExprChanged = true;
9593 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009594 continue;
9595 }
Mike Stump11289f42009-09-09 15:08:12 +00009596
David Majnemerf7e36092016-06-23 00:15:04 +00009597 if (D.isArrayDesignator()) {
9598 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009599 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009601
David Majnemerf7e36092016-06-23 00:15:04 +00009602 Desig.AddDesignator(
9603 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009604
David Majnemerf7e36092016-06-23 00:15:04 +00009605 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009606 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009607 continue;
9608 }
Mike Stump11289f42009-09-09 15:08:12 +00009609
David Majnemerf7e36092016-06-23 00:15:04 +00009610 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009611 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009612 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009613 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009615
David Majnemerf7e36092016-06-23 00:15:04 +00009616 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009617 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009619
9620 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009621 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009622 D.getLBracketLoc(),
9623 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009624
David Majnemerf7e36092016-06-23 00:15:04 +00009625 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9626 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009627
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009628 ArrayExprs.push_back(Start.get());
9629 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009630 }
Mike Stump11289f42009-09-09 15:08:12 +00009631
Douglas Gregora16548e2009-08-11 05:31:07 +00009632 if (!getDerived().AlwaysRebuild() &&
9633 Init.get() == E->getInit() &&
9634 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009635 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009636
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009637 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009638 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009639 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009640}
Mike Stump11289f42009-09-09 15:08:12 +00009641
Yunzhong Gaocb779302015-06-10 00:27:52 +00009642// Seems that if TransformInitListExpr() only works on the syntactic form of an
9643// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9644template<typename Derived>
9645ExprResult
9646TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9647 DesignatedInitUpdateExpr *E) {
9648 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9649 "initializer");
9650 return ExprError();
9651}
9652
9653template<typename Derived>
9654ExprResult
9655TreeTransform<Derived>::TransformNoInitExpr(
9656 NoInitExpr *E) {
9657 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9658 return ExprError();
9659}
9660
Douglas Gregora16548e2009-08-11 05:31:07 +00009661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009662ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009663TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9664 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9665 return ExprError();
9666}
9667
9668template<typename Derived>
9669ExprResult
9670TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9671 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9672 return ExprError();
9673}
9674
9675template<typename Derived>
9676ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009677TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009678 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009679 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009680
Douglas Gregor3da3c062009-10-28 00:29:27 +00009681 // FIXME: Will we ever have proper type location here? Will we actually
9682 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 QualType T = getDerived().TransformType(E->getType());
9684 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009686
Douglas Gregora16548e2009-08-11 05:31:07 +00009687 if (!getDerived().AlwaysRebuild() &&
9688 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009689 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009690
Douglas Gregora16548e2009-08-11 05:31:07 +00009691 return getDerived().RebuildImplicitValueInitExpr(T);
9692}
Mike Stump11289f42009-09-09 15:08:12 +00009693
Douglas Gregora16548e2009-08-11 05:31:07 +00009694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009695ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009696TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009697 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9698 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009700
John McCalldadc5752010-08-24 06:29:42 +00009701 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009702 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009704
Douglas Gregora16548e2009-08-11 05:31:07 +00009705 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009706 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009707 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009708 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009709
John McCallb268a282010-08-23 23:25:46 +00009710 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009711 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009712}
9713
9714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009715ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009716TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009717 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009718 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009719 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9720 &ArgumentChanged))
9721 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009722
Douglas Gregora16548e2009-08-11 05:31:07 +00009723 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009724 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009725 E->getRParenLoc());
9726}
Mike Stump11289f42009-09-09 15:08:12 +00009727
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009728/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00009729///
9730/// By default, the transformation of an address-of-label expression always
9731/// rebuilds the expression, so that the label identifier can be resolved to
9732/// the corresponding label statement by semantic analysis.
9733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009735TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009736 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9737 E->getLabel());
9738 if (!LD)
9739 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009740
Douglas Gregora16548e2009-08-11 05:31:07 +00009741 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009742 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009743}
Mike Stump11289f42009-09-09 15:08:12 +00009744
9745template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009747TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009748 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009749 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009750 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009751 if (SubStmt.isInvalid()) {
9752 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009753 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009754 }
Mike Stump11289f42009-09-09 15:08:12 +00009755
Douglas Gregora16548e2009-08-11 05:31:07 +00009756 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009757 SubStmt.get() == E->getSubStmt()) {
9758 // Calling this an 'error' is unintuitive, but it does the right thing.
9759 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009760 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009761 }
Mike Stump11289f42009-09-09 15:08:12 +00009762
9763 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009764 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009765 E->getRParenLoc());
9766}
Mike Stump11289f42009-09-09 15:08:12 +00009767
Douglas Gregora16548e2009-08-11 05:31:07 +00009768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009769ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009770TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009771 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009774
John McCalldadc5752010-08-24 06:29:42 +00009775 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009778
John McCalldadc5752010-08-24 06:29:42 +00009779 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009780 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009781 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009782
Douglas Gregora16548e2009-08-11 05:31:07 +00009783 if (!getDerived().AlwaysRebuild() &&
9784 Cond.get() == E->getCond() &&
9785 LHS.get() == E->getLHS() &&
9786 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009787 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009788
Douglas Gregora16548e2009-08-11 05:31:07 +00009789 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009790 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009791 E->getRParenLoc());
9792}
Mike Stump11289f42009-09-09 15:08:12 +00009793
Douglas Gregora16548e2009-08-11 05:31:07 +00009794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009795ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009796TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009797 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009798}
9799
9800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009802TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009803 switch (E->getOperator()) {
9804 case OO_New:
9805 case OO_Delete:
9806 case OO_Array_New:
9807 case OO_Array_Delete:
9808 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009809
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009810 case OO_Call: {
9811 // This is a call to an object's operator().
9812 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9813
9814 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009815 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009816 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009817 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009818
9819 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009820 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9821 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009822
9823 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009824 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009825 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009826 Args))
9827 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009828
John McCallb268a282010-08-23 23:25:46 +00009829 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009830 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009831 E->getLocEnd());
9832 }
9833
9834#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9835 case OO_##Name:
9836#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9837#include "clang/Basic/OperatorKinds.def"
9838 case OO_Subscript:
9839 // Handled below.
9840 break;
9841
9842 case OO_Conditional:
9843 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009844
9845 case OO_None:
9846 case NUM_OVERLOADED_OPERATORS:
9847 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009848 }
9849
John McCalldadc5752010-08-24 06:29:42 +00009850 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009851 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009853
Richard Smithdb2630f2012-10-21 03:28:35 +00009854 ExprResult First;
9855 if (E->getOperator() == OO_Amp)
9856 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9857 else
9858 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009859 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009860 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009861
John McCalldadc5752010-08-24 06:29:42 +00009862 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009863 if (E->getNumArgs() == 2) {
9864 Second = getDerived().TransformExpr(E->getArg(1));
9865 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009866 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009867 }
Mike Stump11289f42009-09-09 15:08:12 +00009868
Douglas Gregora16548e2009-08-11 05:31:07 +00009869 if (!getDerived().AlwaysRebuild() &&
9870 Callee.get() == E->getCallee() &&
9871 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009872 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009873 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009874
Lang Hames5de91cc2012-10-02 04:45:10 +00009875 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009876 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009877
Douglas Gregora16548e2009-08-11 05:31:07 +00009878 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9879 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009880 Callee.get(),
9881 First.get(),
9882 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009883}
Mike Stump11289f42009-09-09 15:08:12 +00009884
Douglas Gregora16548e2009-08-11 05:31:07 +00009885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009887TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9888 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009889}
Mike Stump11289f42009-09-09 15:08:12 +00009890
Douglas Gregora16548e2009-08-11 05:31:07 +00009891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009892ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009893TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9894 // Transform the callee.
9895 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9896 if (Callee.isInvalid())
9897 return ExprError();
9898
9899 // Transform exec config.
9900 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9901 if (EC.isInvalid())
9902 return ExprError();
9903
9904 // Transform arguments.
9905 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009906 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009907 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009908 &ArgChanged))
9909 return ExprError();
9910
9911 if (!getDerived().AlwaysRebuild() &&
9912 Callee.get() == E->getCallee() &&
9913 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009914 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009915
9916 // FIXME: Wrong source location information for the '('.
9917 SourceLocation FakeLParenLoc
9918 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9919 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009920 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009921 E->getRParenLoc(), EC.get());
9922}
9923
9924template<typename Derived>
9925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009926TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009927 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9928 if (!Type)
9929 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009930
John McCalldadc5752010-08-24 06:29:42 +00009931 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009932 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009933 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009935
Douglas Gregora16548e2009-08-11 05:31:07 +00009936 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009937 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009938 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009939 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009940 return getDerived().RebuildCXXNamedCastExpr(
9941 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9942 Type, E->getAngleBrackets().getEnd(),
9943 // FIXME. this should be '(' location
9944 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009945}
Mike Stump11289f42009-09-09 15:08:12 +00009946
Douglas Gregora16548e2009-08-11 05:31:07 +00009947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009949TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9950 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009951}
Mike Stump11289f42009-09-09 15:08:12 +00009952
9953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009955TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9956 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009957}
9958
Douglas Gregora16548e2009-08-11 05:31:07 +00009959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009960ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009961TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009962 CXXReinterpretCastExpr *E) {
9963 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009964}
Mike Stump11289f42009-09-09 15:08:12 +00009965
Douglas Gregora16548e2009-08-11 05:31:07 +00009966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009967ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009968TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9969 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009970}
Mike Stump11289f42009-09-09 15:08:12 +00009971
Douglas Gregora16548e2009-08-11 05:31:07 +00009972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009973ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009974TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009975 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009976 TypeSourceInfo *Type =
9977 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009978 if (!Type)
9979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009980
John McCalldadc5752010-08-24 06:29:42 +00009981 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009982 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009983 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009984 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009985
Douglas Gregora16548e2009-08-11 05:31:07 +00009986 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009987 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009988 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009989 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009990
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009991 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009992 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009993 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +00009994 E->getRParenLoc(),
9995 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +00009996}
Mike Stump11289f42009-09-09 15:08:12 +00009997
Douglas Gregora16548e2009-08-11 05:31:07 +00009998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010000TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010001 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010002 TypeSourceInfo *TInfo
10003 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10004 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010006
Douglas Gregora16548e2009-08-11 05:31:07 +000010007 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010008 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010009 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010010
Douglas Gregor9da64192010-04-26 22:37:10 +000010011 return getDerived().RebuildCXXTypeidExpr(E->getType(),
10012 E->getLocStart(),
10013 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010014 E->getLocEnd());
10015 }
Mike Stump11289f42009-09-09 15:08:12 +000010016
Eli Friedman456f0182012-01-20 01:26:23 +000010017 // We don't know whether the subexpression is potentially evaluated until
10018 // after we perform semantic analysis. We speculatively assume it is
10019 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010020 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010021 EnterExpressionEvaluationContext Unevaluated(
10022 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10023 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010024
John McCalldadc5752010-08-24 06:29:42 +000010025 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010026 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010028
Douglas Gregora16548e2009-08-11 05:31:07 +000010029 if (!getDerived().AlwaysRebuild() &&
10030 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010031 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010032
Douglas Gregor9da64192010-04-26 22:37:10 +000010033 return getDerived().RebuildCXXTypeidExpr(E->getType(),
10034 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +000010035 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010036 E->getLocEnd());
10037}
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
Douglas Gregor69735112011-03-06 17:40:41 +000010052 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +000010053 E->getLocStart(),
10054 TInfo,
10055 E->getLocEnd());
10056 }
10057
Faisal Valid143a0c2017-04-01 21:30:49 +000010058 EnterExpressionEvaluationContext Unevaluated(
10059 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010060
10061 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10062 if (SubExpr.isInvalid())
10063 return ExprError();
10064
10065 if (!getDerived().AlwaysRebuild() &&
10066 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010067 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010068
10069 return getDerived().RebuildCXXUuidofExpr(E->getType(),
10070 E->getLocStart(),
10071 SubExpr.get(),
10072 E->getLocEnd());
10073}
10074
10075template<typename Derived>
10076ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010077TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010078 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010079}
Mike Stump11289f42009-09-09 15:08:12 +000010080
Douglas Gregora16548e2009-08-11 05:31:07 +000010081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010082ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010083TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010084 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010085 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010086}
Mike Stump11289f42009-09-09 15:08:12 +000010087
Douglas Gregora16548e2009-08-11 05:31:07 +000010088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010089ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010090TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010091 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010092
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010093 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10094 // Make sure that we capture 'this'.
10095 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010096 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010097 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010098
Douglas Gregorb15af892010-01-07 23:12:05 +000010099 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010100}
Mike Stump11289f42009-09-09 15:08:12 +000010101
Douglas Gregora16548e2009-08-11 05:31:07 +000010102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010103ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010104TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010105 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010106 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010108
Douglas Gregora16548e2009-08-11 05:31:07 +000010109 if (!getDerived().AlwaysRebuild() &&
10110 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010111 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010112
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010113 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10114 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010115}
Mike Stump11289f42009-09-09 15:08:12 +000010116
Douglas Gregora16548e2009-08-11 05:31:07 +000010117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010119TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +000010120 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010121 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
10122 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010123 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010125
Chandler Carruth794da4c2010-02-08 06:42:49 +000010126 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010127 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010128 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010129
Douglas Gregor033f6752009-12-23 23:03:06 +000010130 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010131}
Mike Stump11289f42009-09-09 15:08:12 +000010132
Douglas Gregora16548e2009-08-11 05:31:07 +000010133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010134ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010135TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
10136 FieldDecl *Field
10137 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
10138 E->getField()));
10139 if (!Field)
10140 return ExprError();
10141
10142 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010143 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010144
10145 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10146}
10147
10148template<typename Derived>
10149ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010150TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10151 CXXScalarValueInitExpr *E) {
10152 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10153 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010154 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010155
Douglas Gregora16548e2009-08-11 05:31:07 +000010156 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010157 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010158 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010159
Chad Rosier1dcde962012-08-08 18:46:20 +000010160 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010161 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010162 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010163}
Mike Stump11289f42009-09-09 15:08:12 +000010164
Douglas Gregora16548e2009-08-11 05:31:07 +000010165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010167TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010168 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010169 TypeSourceInfo *AllocTypeInfo =
10170 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010171 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010173
Douglas Gregora16548e2009-08-11 05:31:07 +000010174 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010175 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010176 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010178
Douglas Gregora16548e2009-08-11 05:31:07 +000010179 // Transform the placement arguments (if any).
10180 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010181 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010182 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010183 E->getNumPlacementArgs(), true,
10184 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010186
Sebastian Redl6047f072012-02-16 12:22:20 +000010187 // Transform the initializer (if any).
10188 Expr *OldInit = E->getInitializer();
10189 ExprResult NewInit;
10190 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010191 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010192 if (NewInit.isInvalid())
10193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010194
Sebastian Redl6047f072012-02-16 12:22:20 +000010195 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010196 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010197 if (E->getOperatorNew()) {
10198 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010199 getDerived().TransformDecl(E->getLocStart(),
10200 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010201 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010202 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010203 }
10204
Craig Topperc3ec1492014-05-26 06:22:03 +000010205 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010206 if (E->getOperatorDelete()) {
10207 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010208 getDerived().TransformDecl(E->getLocStart(),
10209 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010210 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010211 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010212 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010213
Douglas Gregora16548e2009-08-11 05:31:07 +000010214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010215 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010216 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010217 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010218 OperatorNew == E->getOperatorNew() &&
10219 OperatorDelete == E->getOperatorDelete() &&
10220 !ArgumentChanged) {
10221 // Mark any declarations we need as referenced.
10222 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010223 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010224 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010225 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010226 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010227
Sebastian Redl6047f072012-02-16 12:22:20 +000010228 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010229 QualType ElementType
10230 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10231 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10232 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10233 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +000010234 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010235 }
10236 }
10237 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010238
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010239 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010240 }
Mike Stump11289f42009-09-09 15:08:12 +000010241
Douglas Gregor0744ef62010-09-07 21:49:58 +000010242 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010243 if (!ArraySize.get()) {
10244 // If no array size was specified, but the new expression was
10245 // instantiated with an array type (e.g., "new T" where T is
10246 // instantiated with "int[4]"), extract the outer bound from the
10247 // array type as our array size. We do this with constant and
10248 // dependently-sized array types.
10249 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10250 if (!ArrayT) {
10251 // Do nothing
10252 } else if (const ConstantArrayType *ConsArrayT
10253 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010254 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10255 SemaRef.Context.getSizeType(),
10256 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010257 AllocType = ConsArrayT->getElementType();
10258 } else if (const DependentSizedArrayType *DepArrayT
10259 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10260 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010261 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010262 AllocType = DepArrayT->getElementType();
10263 }
10264 }
10265 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010266
Douglas Gregora16548e2009-08-11 05:31:07 +000010267 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10268 E->isGlobalNew(),
10269 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010270 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010271 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +000010272 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010273 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +000010274 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +000010275 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +000010276 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010277 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010278}
Mike Stump11289f42009-09-09 15:08:12 +000010279
Douglas Gregora16548e2009-08-11 05:31:07 +000010280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010281ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010282TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010283 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010284 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010286
Douglas Gregord2d9da02010-02-26 00:38:10 +000010287 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010288 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010289 if (E->getOperatorDelete()) {
10290 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010291 getDerived().TransformDecl(E->getLocStart(),
10292 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010293 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010294 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010295 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010296
Douglas Gregora16548e2009-08-11 05:31:07 +000010297 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010298 Operand.get() == E->getArgument() &&
10299 OperatorDelete == E->getOperatorDelete()) {
10300 // Mark any declarations we need as referenced.
10301 // FIXME: instantiation-specific.
10302 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010303 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010304
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010305 if (!E->getArgument()->isTypeDependent()) {
10306 QualType Destroyed = SemaRef.Context.getBaseElementType(
10307 E->getDestroyedType());
10308 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10309 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010310 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010311 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010312 }
10313 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010314
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010315 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010316 }
Mike Stump11289f42009-09-09 15:08:12 +000010317
Douglas Gregora16548e2009-08-11 05:31:07 +000010318 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10319 E->isGlobalDelete(),
10320 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +000010321 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010322}
Mike Stump11289f42009-09-09 15:08:12 +000010323
Douglas Gregora16548e2009-08-11 05:31:07 +000010324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010325ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010326TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010327 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010328 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010329 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010330 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010331
John McCallba7bf592010-08-24 05:47:05 +000010332 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010333 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010334 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010335 E->getOperatorLoc(),
10336 E->isArrow()? tok::arrow : tok::period,
10337 ObjectTypePtr,
10338 MayBePseudoDestructor);
10339 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010340 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010341
John McCallba7bf592010-08-24 05:47:05 +000010342 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010343 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10344 if (QualifierLoc) {
10345 QualifierLoc
10346 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10347 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010348 return ExprError();
10349 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010350 CXXScopeSpec SS;
10351 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010352
Douglas Gregor678f90d2010-02-25 01:56:36 +000010353 PseudoDestructorTypeStorage Destroyed;
10354 if (E->getDestroyedTypeInfo()) {
10355 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010356 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010357 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010358 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010359 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010360 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010361 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010362 // We aren't likely to be able to resolve the identifier down to a type
10363 // now anyway, so just retain the identifier.
10364 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10365 E->getDestroyedTypeLoc());
10366 } else {
10367 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010368 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010369 *E->getDestroyedTypeIdentifier(),
10370 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010371 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010372 SS, ObjectTypePtr,
10373 false);
10374 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010375 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010376
Douglas Gregor678f90d2010-02-25 01:56:36 +000010377 Destroyed
10378 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10379 E->getDestroyedTypeLoc());
10380 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010381
Craig Topperc3ec1492014-05-26 06:22:03 +000010382 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010383 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010384 CXXScopeSpec EmptySS;
10385 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010386 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010387 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010388 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010389 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010390
John McCallb268a282010-08-23 23:25:46 +000010391 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010392 E->getOperatorLoc(),
10393 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010394 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010395 ScopeTypeInfo,
10396 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010397 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010398 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010399}
Mike Stump11289f42009-09-09 15:08:12 +000010400
Richard Smith151c4562016-12-20 21:35:28 +000010401template <typename Derived>
10402bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10403 bool RequiresADL,
10404 LookupResult &R) {
10405 // Transform all the decls.
10406 bool AllEmptyPacks = true;
10407 for (auto *OldD : Old->decls()) {
10408 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10409 if (!InstD) {
10410 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10411 // This can happen because of dependent hiding.
10412 if (isa<UsingShadowDecl>(OldD))
10413 continue;
10414 else {
10415 R.clear();
10416 return true;
10417 }
10418 }
10419
10420 // Expand using pack declarations.
10421 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10422 ArrayRef<NamedDecl*> Decls = SingleDecl;
10423 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10424 Decls = UPD->expansions();
10425
10426 // Expand using declarations.
10427 for (auto *D : Decls) {
10428 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10429 for (auto *SD : UD->shadows())
10430 R.addDecl(SD);
10431 } else {
10432 R.addDecl(D);
10433 }
10434 }
10435
10436 AllEmptyPacks &= Decls.empty();
10437 };
10438
10439 // C++ [temp.res]/8.4.2:
10440 // The program is ill-formed, no diagnostic required, if [...] lookup for
10441 // a name in the template definition found a using-declaration, but the
10442 // lookup in the corresponding scope in the instantiation odoes not find
10443 // any declarations because the using-declaration was a pack expansion and
10444 // the corresponding pack is empty
10445 if (AllEmptyPacks && !RequiresADL) {
10446 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010447 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010448 return true;
10449 }
10450
10451 // Resolve a kind, but don't do any further analysis. If it's
10452 // ambiguous, the callee needs to deal with it.
10453 R.resolveKind();
10454 return false;
10455}
10456
Douglas Gregorad8a3362009-09-04 17:36:40 +000010457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010458ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010459TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010460 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010461 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10462 Sema::LookupOrdinaryName);
10463
Richard Smith151c4562016-12-20 21:35:28 +000010464 // Transform the declaration set.
10465 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10466 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010467
10468 // Rebuild the nested-name qualifier, if present.
10469 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010470 if (Old->getQualifierLoc()) {
10471 NestedNameSpecifierLoc QualifierLoc
10472 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10473 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010474 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010475
Douglas Gregor0da1d432011-02-28 20:01:57 +000010476 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010477 }
10478
Douglas Gregor9262f472010-04-27 18:19:34 +000010479 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010480 CXXRecordDecl *NamingClass
10481 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10482 Old->getNameLoc(),
10483 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010484 if (!NamingClass) {
10485 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010486 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010487 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010488
Douglas Gregorda7be082010-04-27 16:10:10 +000010489 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010490 }
10491
Abramo Bagnara7945c982012-01-27 09:46:47 +000010492 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10493
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010494 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010495 // it's a normal declaration name or member reference.
10496 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10497 NamedDecl *D = R.getAsSingle<NamedDecl>();
10498 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10499 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10500 // give a good diagnostic.
10501 if (D && D->isCXXInstanceMember()) {
10502 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10503 /*TemplateArgs=*/nullptr,
10504 /*Scope=*/nullptr);
10505 }
10506
John McCalle66edc12009-11-24 19:00:30 +000010507 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010508 }
John McCalle66edc12009-11-24 19:00:30 +000010509
10510 // If we have template arguments, rebuild them, then rebuild the
10511 // templateid expression.
10512 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010513 if (Old->hasExplicitTemplateArgs() &&
10514 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010515 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010516 TransArgs)) {
10517 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010518 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010519 }
John McCalle66edc12009-11-24 19:00:30 +000010520
Abramo Bagnara7945c982012-01-27 09:46:47 +000010521 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010522 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010523}
Mike Stump11289f42009-09-09 15:08:12 +000010524
Douglas Gregora16548e2009-08-11 05:31:07 +000010525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010526ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010527TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10528 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010529 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010530 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10531 TypeSourceInfo *From = E->getArg(I);
10532 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010533 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010534 TypeLocBuilder TLB;
10535 TLB.reserve(FromTL.getFullDataSize());
10536 QualType To = getDerived().TransformType(TLB, FromTL);
10537 if (To.isNull())
10538 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010539
Douglas Gregor29c42f22012-02-24 07:38:34 +000010540 if (To == From->getType())
10541 Args.push_back(From);
10542 else {
10543 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10544 ArgChanged = true;
10545 }
10546 continue;
10547 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010548
Douglas Gregor29c42f22012-02-24 07:38:34 +000010549 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010550
Douglas Gregor29c42f22012-02-24 07:38:34 +000010551 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010552 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010553 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10554 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10555 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010556
Douglas Gregor29c42f22012-02-24 07:38:34 +000010557 // Determine whether the set of unexpanded parameter packs can and should
10558 // be expanded.
10559 bool Expand = true;
10560 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010561 Optional<unsigned> OrigNumExpansions =
10562 ExpansionTL.getTypePtr()->getNumExpansions();
10563 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010564 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10565 PatternTL.getSourceRange(),
10566 Unexpanded,
10567 Expand, RetainExpansion,
10568 NumExpansions))
10569 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010570
Douglas Gregor29c42f22012-02-24 07:38:34 +000010571 if (!Expand) {
10572 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010573 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010574 // expansion.
10575 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010576
Douglas Gregor29c42f22012-02-24 07:38:34 +000010577 TypeLocBuilder TLB;
10578 TLB.reserve(From->getTypeLoc().getFullDataSize());
10579
10580 QualType To = getDerived().TransformType(TLB, PatternTL);
10581 if (To.isNull())
10582 return ExprError();
10583
Chad Rosier1dcde962012-08-08 18:46:20 +000010584 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010585 PatternTL.getSourceRange(),
10586 ExpansionTL.getEllipsisLoc(),
10587 NumExpansions);
10588 if (To.isNull())
10589 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010590
Douglas Gregor29c42f22012-02-24 07:38:34 +000010591 PackExpansionTypeLoc ToExpansionTL
10592 = TLB.push<PackExpansionTypeLoc>(To);
10593 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10594 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10595 continue;
10596 }
10597
10598 // Expand the pack expansion by substituting for each argument in the
10599 // pack(s).
10600 for (unsigned I = 0; I != *NumExpansions; ++I) {
10601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10602 TypeLocBuilder TLB;
10603 TLB.reserve(PatternTL.getFullDataSize());
10604 QualType To = getDerived().TransformType(TLB, PatternTL);
10605 if (To.isNull())
10606 return ExprError();
10607
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010608 if (To->containsUnexpandedParameterPack()) {
10609 To = getDerived().RebuildPackExpansionType(To,
10610 PatternTL.getSourceRange(),
10611 ExpansionTL.getEllipsisLoc(),
10612 NumExpansions);
10613 if (To.isNull())
10614 return ExprError();
10615
10616 PackExpansionTypeLoc ToExpansionTL
10617 = TLB.push<PackExpansionTypeLoc>(To);
10618 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10619 }
10620
Douglas Gregor29c42f22012-02-24 07:38:34 +000010621 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10622 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010623
Douglas Gregor29c42f22012-02-24 07:38:34 +000010624 if (!RetainExpansion)
10625 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010626
Douglas Gregor29c42f22012-02-24 07:38:34 +000010627 // If we're supposed to retain a pack expansion, do so by temporarily
10628 // forgetting the partially-substituted parameter pack.
10629 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10630
10631 TypeLocBuilder TLB;
10632 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010633
Douglas Gregor29c42f22012-02-24 07:38:34 +000010634 QualType To = getDerived().TransformType(TLB, PatternTL);
10635 if (To.isNull())
10636 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010637
10638 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010639 PatternTL.getSourceRange(),
10640 ExpansionTL.getEllipsisLoc(),
10641 NumExpansions);
10642 if (To.isNull())
10643 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010644
Douglas Gregor29c42f22012-02-24 07:38:34 +000010645 PackExpansionTypeLoc ToExpansionTL
10646 = TLB.push<PackExpansionTypeLoc>(To);
10647 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10648 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10649 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010650
Douglas Gregor29c42f22012-02-24 07:38:34 +000010651 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010652 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010653
10654 return getDerived().RebuildTypeTrait(E->getTrait(),
10655 E->getLocStart(),
10656 Args,
10657 E->getLocEnd());
10658}
10659
10660template<typename Derived>
10661ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010662TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10663 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10664 if (!T)
10665 return ExprError();
10666
10667 if (!getDerived().AlwaysRebuild() &&
10668 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010669 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010670
10671 ExprResult SubExpr;
10672 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010673 EnterExpressionEvaluationContext Unevaluated(
10674 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010675 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10676 if (SubExpr.isInvalid())
10677 return ExprError();
10678
10679 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010680 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010681 }
10682
10683 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10684 E->getLocStart(),
10685 T,
10686 SubExpr.get(),
10687 E->getLocEnd());
10688}
10689
10690template<typename Derived>
10691ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010692TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10693 ExprResult SubExpr;
10694 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010695 EnterExpressionEvaluationContext Unevaluated(
10696 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010697 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10698 if (SubExpr.isInvalid())
10699 return ExprError();
10700
10701 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010702 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010703 }
10704
10705 return getDerived().RebuildExpressionTrait(
10706 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10707}
10708
Reid Kleckner32506ed2014-06-12 23:03:48 +000010709template <typename Derived>
10710ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10711 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10712 TypeSourceInfo **RecoveryTSI) {
10713 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10714 DRE, AddrTaken, RecoveryTSI);
10715
10716 // Propagate both errors and recovered types, which return ExprEmpty.
10717 if (!NewDRE.isUsable())
10718 return NewDRE;
10719
10720 // We got an expr, wrap it up in parens.
10721 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10722 return PE;
10723 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10724 PE->getRParen());
10725}
10726
10727template <typename Derived>
10728ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10729 DependentScopeDeclRefExpr *E) {
10730 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10731 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010732}
10733
10734template<typename Derived>
10735ExprResult
10736TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10737 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010738 bool IsAddressOfOperand,
10739 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010740 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010741 NestedNameSpecifierLoc QualifierLoc
10742 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10743 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010744 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010745 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010746
John McCall31f82722010-11-12 08:19:04 +000010747 // TODO: If this is a conversion-function-id, verify that the
10748 // destination type name (if present) resolves the same way after
10749 // instantiation as it did in the local scope.
10750
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010751 DeclarationNameInfo NameInfo
10752 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10753 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010755
John McCalle66edc12009-11-24 19:00:30 +000010756 if (!E->hasExplicitTemplateArgs()) {
10757 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010758 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010759 // Note: it is sufficient to compare the Name component of NameInfo:
10760 // if name has not changed, DNLoc has not changed either.
10761 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010762 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010763
Reid Kleckner32506ed2014-06-12 23:03:48 +000010764 return getDerived().RebuildDependentScopeDeclRefExpr(
10765 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10766 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010767 }
John McCall6b51f282009-11-23 01:53:49 +000010768
10769 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010770 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10771 E->getNumTemplateArgs(),
10772 TransArgs))
10773 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010774
Reid Kleckner32506ed2014-06-12 23:03:48 +000010775 return getDerived().RebuildDependentScopeDeclRefExpr(
10776 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10777 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010778}
10779
10780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010782TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010783 // CXXConstructExprs other than for list-initialization and
10784 // CXXTemporaryObjectExpr are always implicit, so when we have
10785 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010786 if ((E->getNumArgs() == 1 ||
10787 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010788 (!getDerived().DropCallArgument(E->getArg(0))) &&
10789 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010790 return getDerived().TransformExpr(E->getArg(0));
10791
Douglas Gregora16548e2009-08-11 05:31:07 +000010792 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10793
10794 QualType T = getDerived().TransformType(E->getType());
10795 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010796 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010797
10798 CXXConstructorDecl *Constructor
10799 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010800 getDerived().TransformDecl(E->getLocStart(),
10801 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010802 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010804
Douglas Gregora16548e2009-08-11 05:31:07 +000010805 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010806 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010807 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010808 &ArgumentChanged))
10809 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010810
Douglas Gregora16548e2009-08-11 05:31:07 +000010811 if (!getDerived().AlwaysRebuild() &&
10812 T == E->getType() &&
10813 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010814 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010815 // Mark the constructor as referenced.
10816 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010817 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010818 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010819 }
Mike Stump11289f42009-09-09 15:08:12 +000010820
Douglas Gregordb121ba2009-12-14 16:27:04 +000010821 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010822 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010823 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010824 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010825 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010826 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010827 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010828 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010829 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010830}
Mike Stump11289f42009-09-09 15:08:12 +000010831
Richard Smith5179eb72016-06-28 19:03:57 +000010832template<typename Derived>
10833ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10834 CXXInheritedCtorInitExpr *E) {
10835 QualType T = getDerived().TransformType(E->getType());
10836 if (T.isNull())
10837 return ExprError();
10838
10839 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10840 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10841 if (!Constructor)
10842 return ExprError();
10843
10844 if (!getDerived().AlwaysRebuild() &&
10845 T == E->getType() &&
10846 Constructor == E->getConstructor()) {
10847 // Mark the constructor as referenced.
10848 // FIXME: Instantiation-specific
10849 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10850 return E;
10851 }
10852
10853 return getDerived().RebuildCXXInheritedCtorInitExpr(
10854 T, E->getLocation(), Constructor,
10855 E->constructsVBase(), E->inheritedFromVBase());
10856}
10857
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010858/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010859///
Douglas Gregor363b1512009-12-24 18:51:59 +000010860/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10861/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010864TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010865 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010866}
Mike Stump11289f42009-09-09 15:08:12 +000010867
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010868/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000010869/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010870///
John McCall5d413782010-12-06 08:20:24 +000010871/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010872/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010874ExprResult
John McCall5d413782010-12-06 08:20:24 +000010875TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010876 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010877}
Mike Stump11289f42009-09-09 15:08:12 +000010878
Douglas Gregora16548e2009-08-11 05:31:07 +000010879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010880ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010881TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010882 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010883 TypeSourceInfo *T =
10884 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010885 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010887
Douglas Gregora16548e2009-08-11 05:31:07 +000010888 CXXConstructorDecl *Constructor
10889 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010890 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010891 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010892 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010894
Douglas Gregora16548e2009-08-11 05:31:07 +000010895 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010896 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010897 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010898 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010899 &ArgumentChanged))
10900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010901
Douglas Gregora16548e2009-08-11 05:31:07 +000010902 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010903 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010904 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010905 !ArgumentChanged) {
10906 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010907 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010908 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010909 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010910
Vedant Kumara14a1f92018-01-17 18:53:51 +000010911 // FIXME: We should just pass E->isListInitialization(), but we're not
10912 // prepared to handle list-initialization without a child InitListExpr.
10913 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
10914 return getDerived().RebuildCXXTemporaryObjectExpr(
10915 T, LParenLoc, Args, E->getLocEnd(),
10916 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000010917}
Mike Stump11289f42009-09-09 15:08:12 +000010918
Douglas Gregora16548e2009-08-11 05:31:07 +000010919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010920ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010921TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010922 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010923 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010924 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010925 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10926 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010927 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010928 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010929 CEnd = E->capture_end();
10930 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010931 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010932 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010933 EnterExpressionEvaluationContext EEEC(
10934 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010935 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10936 C->getCapturedVar()->getInit(),
10937 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010938
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010939 if (NewExprInitResult.isInvalid())
10940 return ExprError();
10941 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010942
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010943 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010944 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010945 getSema().buildLambdaInitCaptureInitialization(
10946 C->getLocation(), OldVD->getType()->isReferenceType(),
10947 OldVD->getIdentifier(),
10948 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010949 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010950 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10951 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010952 }
10953
Faisal Vali2cba1332013-10-23 06:44:28 +000010954 // Transform the template parameters, and add them to the current
10955 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010956 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010957 E->getTemplateParameterList());
10958
Richard Smith01014ce2014-11-20 23:53:14 +000010959 // Transform the type of the original lambda's call operator.
10960 // The transformation MUST be done in the CurrentInstantiationScope since
10961 // it introduces a mapping of the original to the newly created
10962 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010963 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010964 {
10965 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10966 FunctionProtoTypeLoc OldCallOpFPTL =
10967 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010968
10969 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010970 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010971 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010972 QualType NewCallOpType = TransformFunctionProtoType(
10973 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010974 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10975 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10976 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010977 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010978 if (NewCallOpType.isNull())
10979 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010980 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10981 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010982 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010983
Richard Smithc38498f2015-04-27 21:27:54 +000010984 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10985 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10986 LSI->GLTemplateParameterList = TPL;
10987
Eli Friedmand564afb2012-09-19 01:18:11 +000010988 // Create the local class that will describe the lambda.
10989 CXXRecordDecl *Class
10990 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010991 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010992 /*KnownDependent=*/false,
10993 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010994 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10995
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010996 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010997 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10998 Class, E->getIntroducerRange(), NewCallOpTSI,
10999 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000011000 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
11001 E->getCallOperator()->isConstexpr());
11002
Faisal Vali2cba1332013-10-23 06:44:28 +000011003 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011004
Akira Hatanaka402818462016-12-16 21:16:57 +000011005 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11006 I != NumParams; ++I) {
11007 auto *P = NewCallOperator->getParamDecl(I);
11008 if (P->hasUninstantiatedDefaultArg()) {
11009 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011010 getSema(),
11011 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011012 ExprResult R = getDerived().TransformExpr(
11013 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11014 P->setDefaultArg(R.get());
11015 }
11016 }
11017
Faisal Vali2cba1332013-10-23 06:44:28 +000011018 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000011019 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000011020
Douglas Gregorb4328232012-02-14 00:00:48 +000011021 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011022 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011023 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011024
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011025 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011026 getSema().buildLambdaScope(LSI, NewCallOperator,
11027 E->getIntroducerRange(),
11028 E->getCaptureDefault(),
11029 E->getCaptureDefaultLoc(),
11030 E->hasExplicitParameters(),
11031 E->hasExplicitResultType(),
11032 E->isMutable());
11033
11034 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011035
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011036 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011037 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011038 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011039 CEnd = E->capture_end();
11040 C != CEnd; ++C) {
11041 // When we hit the first implicit capture, tell Sema that we've finished
11042 // the list of explicit captures.
11043 if (!FinishedExplicitCaptures && C->isImplicit()) {
11044 getSema().finishLambdaExplicitCaptures(LSI);
11045 FinishedExplicitCaptures = true;
11046 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011047
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011048 // Capturing 'this' is trivial.
11049 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011050 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11051 /*BuildAndDiagnose*/ true, nullptr,
11052 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011053 continue;
11054 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011055 // Captured expression will be recaptured during captured variables
11056 // rebuilding.
11057 if (C->capturesVLAType())
11058 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011059
Richard Smithba71c082013-05-16 06:20:58 +000011060 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011061 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011062 InitCaptureInfoTy InitExprTypePair =
11063 InitCaptureExprsAndTypes[C - E->capture_begin()];
11064 ExprResult Init = InitExprTypePair.first;
11065 QualType InitQualType = InitExprTypePair.second;
11066 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000011067 Invalid = true;
11068 continue;
11069 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011070 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011071 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000011072 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11073 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000011074 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000011075 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011076 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000011077 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011078 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011079 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000011080 continue;
11081 }
11082
11083 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11084
Douglas Gregor3e308b12012-02-14 19:27:52 +000011085 // Determine the capture kind for Sema.
11086 Sema::TryCaptureKind Kind
11087 = C->isImplicit()? Sema::TryCapture_Implicit
11088 : C->getCaptureKind() == LCK_ByCopy
11089 ? Sema::TryCapture_ExplicitByVal
11090 : Sema::TryCapture_ExplicitByRef;
11091 SourceLocation EllipsisLoc;
11092 if (C->isPackExpansion()) {
11093 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11094 bool ShouldExpand = false;
11095 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011096 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011097 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11098 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011099 Unexpanded,
11100 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011101 NumExpansions)) {
11102 Invalid = true;
11103 continue;
11104 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011105
Douglas Gregor3e308b12012-02-14 19:27:52 +000011106 if (ShouldExpand) {
11107 // The transform has determined that we should perform an expansion;
11108 // transform and capture each of the arguments.
11109 // expansion of the pattern. Do so.
11110 VarDecl *Pack = C->getCapturedVar();
11111 for (unsigned I = 0; I != *NumExpansions; ++I) {
11112 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11113 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011114 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011115 Pack));
11116 if (!CapturedVar) {
11117 Invalid = true;
11118 continue;
11119 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011120
Douglas Gregor3e308b12012-02-14 19:27:52 +000011121 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011122 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11123 }
Richard Smith9467be42014-06-06 17:33:35 +000011124
11125 // FIXME: Retain a pack expansion if RetainExpansion is true.
11126
Douglas Gregor3e308b12012-02-14 19:27:52 +000011127 continue;
11128 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011129
Douglas Gregor3e308b12012-02-14 19:27:52 +000011130 EllipsisLoc = C->getEllipsisLoc();
11131 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011132
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011133 // Transform the captured variable.
11134 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011135 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011136 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011137 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011138 Invalid = true;
11139 continue;
11140 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011141
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011142 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011143 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11144 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011145 }
11146 if (!FinishedExplicitCaptures)
11147 getSema().finishLambdaExplicitCaptures(LSI);
11148
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011149 // Enter a new evaluation context to insulate the lambda from any
11150 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011151 getSema().PushExpressionEvaluationContext(
11152 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011153
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011154 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011155 StmtResult Body =
11156 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11157
11158 // ActOnLambda* will pop the function scope for us.
11159 FuncScopeCleanup.disable();
11160
Douglas Gregorb4328232012-02-14 00:00:48 +000011161 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011162 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000011163 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011164 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011165 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011166 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011167
Richard Smithc38498f2015-04-27 21:27:54 +000011168 // Copy the LSI before ActOnFinishFunctionBody removes it.
11169 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11170 // the call operator.
11171 auto LSICopy = *LSI;
11172 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11173 /*IsInstantiation*/ true);
11174 SavedContext.pop();
11175
11176 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11177 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011178}
11179
11180template<typename Derived>
11181ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011182TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011183 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011184 TypeSourceInfo *T =
11185 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011186 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011188
Douglas Gregora16548e2009-08-11 05:31:07 +000011189 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011190 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011191 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000011192 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011193 &ArgumentChanged))
11194 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011195
Douglas Gregora16548e2009-08-11 05:31:07 +000011196 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011197 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011198 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011199 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011200
Douglas Gregora16548e2009-08-11 05:31:07 +000011201 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011202 return getDerived().RebuildCXXUnresolvedConstructExpr(
11203 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011204}
Mike Stump11289f42009-09-09 15:08:12 +000011205
Douglas Gregora16548e2009-08-11 05:31:07 +000011206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011207ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011208TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011209 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011210 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011211 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011212 Expr *OldBase;
11213 QualType BaseType;
11214 QualType ObjectType;
11215 if (!E->isImplicitAccess()) {
11216 OldBase = E->getBase();
11217 Base = getDerived().TransformExpr(OldBase);
11218 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011220
John McCall2d74de92009-12-01 22:10:20 +000011221 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011222 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011223 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011224 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011225 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011226 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011227 ObjectTy,
11228 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011229 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011230 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011231
John McCallba7bf592010-08-24 05:47:05 +000011232 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011233 BaseType = ((Expr*) Base.get())->getType();
11234 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011235 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011236 BaseType = getDerived().TransformType(E->getBaseType());
11237 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11238 }
Mike Stump11289f42009-09-09 15:08:12 +000011239
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011240 // Transform the first part of the nested-name-specifier that qualifies
11241 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011242 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011243 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011244 E->getFirstQualifierFoundInScope(),
11245 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011246
Douglas Gregore16af532011-02-28 18:50:33 +000011247 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011248 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011249 QualifierLoc
11250 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11251 ObjectType,
11252 FirstQualifierInScope);
11253 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011254 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011255 }
Mike Stump11289f42009-09-09 15:08:12 +000011256
Abramo Bagnara7945c982012-01-27 09:46:47 +000011257 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11258
John McCall31f82722010-11-12 08:19:04 +000011259 // TODO: If this is a conversion-function-id, verify that the
11260 // destination type name (if present) resolves the same way after
11261 // instantiation as it did in the local scope.
11262
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011263 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011264 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011265 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011267
John McCall2d74de92009-12-01 22:10:20 +000011268 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011269 // This is a reference to a member without an explicitly-specified
11270 // template argument list. Optimize for this common case.
11271 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011272 Base.get() == OldBase &&
11273 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011274 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011275 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011276 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011277 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011278
John McCallb268a282010-08-23 23:25:46 +000011279 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011280 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011281 E->isArrow(),
11282 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011283 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011284 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011285 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011286 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011287 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011288 }
11289
John McCall6b51f282009-11-23 01:53:49 +000011290 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011291 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11292 E->getNumTemplateArgs(),
11293 TransArgs))
11294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011295
John McCallb268a282010-08-23 23:25:46 +000011296 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011297 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011298 E->isArrow(),
11299 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011300 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011301 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011302 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011303 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011304 &TransArgs);
11305}
11306
11307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011309TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011310 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011311 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011312 QualType BaseType;
11313 if (!Old->isImplicitAccess()) {
11314 Base = getDerived().TransformExpr(Old->getBase());
11315 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011316 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011317 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011318 Old->isArrow());
11319 if (Base.isInvalid())
11320 return ExprError();
11321 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011322 } else {
11323 BaseType = getDerived().TransformType(Old->getBaseType());
11324 }
John McCall10eae182009-11-30 22:42:35 +000011325
Douglas Gregor0da1d432011-02-28 20:01:57 +000011326 NestedNameSpecifierLoc QualifierLoc;
11327 if (Old->getQualifierLoc()) {
11328 QualifierLoc
11329 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11330 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011331 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011332 }
11333
Abramo Bagnara7945c982012-01-27 09:46:47 +000011334 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11335
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011336 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011337 Sema::LookupOrdinaryName);
11338
Richard Smith151c4562016-12-20 21:35:28 +000011339 // Transform the declaration set.
11340 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11341 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011342
Douglas Gregor9262f472010-04-27 18:19:34 +000011343 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011344 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011345 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011346 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011347 Old->getMemberLoc(),
11348 Old->getNamingClass()));
11349 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011350 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011351
Douglas Gregorda7be082010-04-27 16:10:10 +000011352 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011353 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011354
John McCall10eae182009-11-30 22:42:35 +000011355 TemplateArgumentListInfo TransArgs;
11356 if (Old->hasExplicitTemplateArgs()) {
11357 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11358 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011359 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11360 Old->getNumTemplateArgs(),
11361 TransArgs))
11362 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011363 }
John McCall38836f02010-01-15 08:34:02 +000011364
11365 // FIXME: to do this check properly, we will need to preserve the
11366 // first-qualifier-in-scope here, just in case we had a dependent
11367 // base (and therefore couldn't do the check) and a
11368 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011369 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011370
John McCallb268a282010-08-23 23:25:46 +000011371 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011372 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011373 Old->getOperatorLoc(),
11374 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011375 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011376 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011377 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011378 R,
11379 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011380 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011381}
11382
11383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011384ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011385TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011386 EnterExpressionEvaluationContext Unevaluated(
11387 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011388 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11389 if (SubExpr.isInvalid())
11390 return ExprError();
11391
11392 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011393 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011394
11395 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11396}
11397
11398template<typename Derived>
11399ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011400TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011401 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11402 if (Pattern.isInvalid())
11403 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011404
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011405 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011406 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011407
Douglas Gregorb8840002011-01-14 21:20:45 +000011408 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11409 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011410}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011411
11412template<typename Derived>
11413ExprResult
11414TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11415 // If E is not value-dependent, then nothing will change when we transform it.
11416 // Note: This is an instantiation-centric view.
11417 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011418 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011419
Faisal Valid143a0c2017-04-01 21:30:49 +000011420 EnterExpressionEvaluationContext Unevaluated(
11421 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011422
Richard Smithd784e682015-09-23 21:41:42 +000011423 ArrayRef<TemplateArgument> PackArgs;
11424 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011425
Richard Smithd784e682015-09-23 21:41:42 +000011426 // Find the argument list to transform.
11427 if (E->isPartiallySubstituted()) {
11428 PackArgs = E->getPartialArguments();
11429 } else if (E->isValueDependent()) {
11430 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11431 bool ShouldExpand = false;
11432 bool RetainExpansion = false;
11433 Optional<unsigned> NumExpansions;
11434 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11435 Unexpanded,
11436 ShouldExpand, RetainExpansion,
11437 NumExpansions))
11438 return ExprError();
11439
11440 // If we need to expand the pack, build a template argument from it and
11441 // expand that.
11442 if (ShouldExpand) {
11443 auto *Pack = E->getPack();
11444 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11445 ArgStorage = getSema().Context.getPackExpansionType(
11446 getSema().Context.getTypeDeclType(TTPD), None);
11447 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11448 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11449 } else {
11450 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011451 ExprResult DRE = getSema().BuildDeclRefExpr(
11452 VD, VD->getType().getNonLValueExprType(getSema().Context),
11453 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11454 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011455 if (DRE.isInvalid())
11456 return ExprError();
11457 ArgStorage = new (getSema().Context) PackExpansionExpr(
11458 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11459 }
11460 PackArgs = ArgStorage;
11461 }
11462 }
11463
11464 // If we're not expanding the pack, just transform the decl.
11465 if (!PackArgs.size()) {
11466 auto *Pack = cast_or_null<NamedDecl>(
11467 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011468 if (!Pack)
11469 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011470 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11471 E->getPackLoc(),
11472 E->getRParenLoc(), None, None);
11473 }
11474
Richard Smithc5452ed2016-10-19 22:18:42 +000011475 // Try to compute the result without performing a partial substitution.
11476 Optional<unsigned> Result = 0;
11477 for (const TemplateArgument &Arg : PackArgs) {
11478 if (!Arg.isPackExpansion()) {
11479 Result = *Result + 1;
11480 continue;
11481 }
11482
11483 TemplateArgumentLoc ArgLoc;
11484 InventTemplateArgumentLoc(Arg, ArgLoc);
11485
11486 // Find the pattern of the pack expansion.
11487 SourceLocation Ellipsis;
11488 Optional<unsigned> OrigNumExpansions;
11489 TemplateArgumentLoc Pattern =
11490 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11491 OrigNumExpansions);
11492
11493 // Substitute under the pack expansion. Do not expand the pack (yet).
11494 TemplateArgumentLoc OutPattern;
11495 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11496 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11497 /*Uneval*/ true))
11498 return true;
11499
11500 // See if we can determine the number of arguments from the result.
11501 Optional<unsigned> NumExpansions =
11502 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11503 if (!NumExpansions) {
11504 // No: we must be in an alias template expansion, and we're going to need
11505 // to actually expand the packs.
11506 Result = None;
11507 break;
11508 }
11509
11510 Result = *Result + *NumExpansions;
11511 }
11512
11513 // Common case: we could determine the number of expansions without
11514 // substituting.
11515 if (Result)
11516 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11517 E->getPackLoc(),
11518 E->getRParenLoc(), *Result, None);
11519
Richard Smithd784e682015-09-23 21:41:42 +000011520 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11521 E->getPackLoc());
11522 {
11523 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11524 typedef TemplateArgumentLocInventIterator<
11525 Derived, const TemplateArgument*> PackLocIterator;
11526 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11527 PackLocIterator(*this, PackArgs.end()),
11528 TransformedPackArgs, /*Uneval*/true))
11529 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011530 }
11531
Richard Smithc5452ed2016-10-19 22:18:42 +000011532 // Check whether we managed to fully-expand the pack.
11533 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011534 SmallVector<TemplateArgument, 8> Args;
11535 bool PartialSubstitution = false;
11536 for (auto &Loc : TransformedPackArgs.arguments()) {
11537 Args.push_back(Loc.getArgument());
11538 if (Loc.getArgument().isPackExpansion())
11539 PartialSubstitution = true;
11540 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011541
Richard Smithd784e682015-09-23 21:41:42 +000011542 if (PartialSubstitution)
11543 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11544 E->getPackLoc(),
11545 E->getRParenLoc(), None, Args);
11546
11547 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011548 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011549 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011550}
11551
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011552template<typename Derived>
11553ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011554TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11555 SubstNonTypeTemplateParmPackExpr *E) {
11556 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011557 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011558}
11559
11560template<typename Derived>
11561ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011562TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11563 SubstNonTypeTemplateParmExpr *E) {
11564 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011565 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011566}
11567
11568template<typename Derived>
11569ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011570TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11571 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011572 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011573}
11574
11575template<typename Derived>
11576ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011577TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11578 MaterializeTemporaryExpr *E) {
11579 return getDerived().TransformExpr(E->GetTemporaryExpr());
11580}
Chad Rosier1dcde962012-08-08 18:46:20 +000011581
Douglas Gregorfe314812011-06-21 17:03:29 +000011582template<typename Derived>
11583ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011584TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11585 Expr *Pattern = E->getPattern();
11586
11587 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11588 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11589 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11590
11591 // Determine whether the set of unexpanded parameter packs can and should
11592 // be expanded.
11593 bool Expand = true;
11594 bool RetainExpansion = false;
11595 Optional<unsigned> NumExpansions;
11596 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11597 Pattern->getSourceRange(),
11598 Unexpanded,
11599 Expand, RetainExpansion,
11600 NumExpansions))
11601 return true;
11602
11603 if (!Expand) {
11604 // Do not expand any packs here, just transform and rebuild a fold
11605 // expression.
11606 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11607
11608 ExprResult LHS =
11609 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11610 if (LHS.isInvalid())
11611 return true;
11612
11613 ExprResult RHS =
11614 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11615 if (RHS.isInvalid())
11616 return true;
11617
11618 if (!getDerived().AlwaysRebuild() &&
11619 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11620 return E;
11621
11622 return getDerived().RebuildCXXFoldExpr(
11623 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11624 RHS.get(), E->getLocEnd());
11625 }
11626
11627 // The transform has determined that we should perform an elementwise
11628 // expansion of the pattern. Do so.
11629 ExprResult Result = getDerived().TransformExpr(E->getInit());
11630 if (Result.isInvalid())
11631 return true;
11632 bool LeftFold = E->isLeftFold();
11633
11634 // If we're retaining an expansion for a right fold, it is the innermost
11635 // component and takes the init (if any).
11636 if (!LeftFold && RetainExpansion) {
11637 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11638
11639 ExprResult Out = getDerived().TransformExpr(Pattern);
11640 if (Out.isInvalid())
11641 return true;
11642
11643 Result = getDerived().RebuildCXXFoldExpr(
11644 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11645 Result.get(), E->getLocEnd());
11646 if (Result.isInvalid())
11647 return true;
11648 }
11649
11650 for (unsigned I = 0; I != *NumExpansions; ++I) {
11651 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11652 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11653 ExprResult Out = getDerived().TransformExpr(Pattern);
11654 if (Out.isInvalid())
11655 return true;
11656
11657 if (Out.get()->containsUnexpandedParameterPack()) {
11658 // We still have a pack; retain a pack expansion for this slice.
11659 Result = getDerived().RebuildCXXFoldExpr(
11660 E->getLocStart(),
11661 LeftFold ? Result.get() : Out.get(),
11662 E->getOperator(), E->getEllipsisLoc(),
11663 LeftFold ? Out.get() : Result.get(),
11664 E->getLocEnd());
11665 } else if (Result.isUsable()) {
11666 // We've got down to a single element; build a binary operator.
11667 Result = getDerived().RebuildBinaryOperator(
11668 E->getEllipsisLoc(), E->getOperator(),
11669 LeftFold ? Result.get() : Out.get(),
11670 LeftFold ? Out.get() : Result.get());
11671 } else
11672 Result = Out;
11673
11674 if (Result.isInvalid())
11675 return true;
11676 }
11677
11678 // If we're retaining an expansion for a left fold, it is the outermost
11679 // component and takes the complete expansion so far as its init (if any).
11680 if (LeftFold && RetainExpansion) {
11681 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11682
11683 ExprResult Out = getDerived().TransformExpr(Pattern);
11684 if (Out.isInvalid())
11685 return true;
11686
11687 Result = getDerived().RebuildCXXFoldExpr(
11688 E->getLocStart(), Result.get(),
11689 E->getOperator(), E->getEllipsisLoc(),
11690 Out.get(), E->getLocEnd());
11691 if (Result.isInvalid())
11692 return true;
11693 }
11694
11695 // If we had no init and an empty pack, and we're not retaining an expansion,
11696 // then produce a fallback value or error.
11697 if (Result.isUnset())
11698 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11699 E->getOperator());
11700
11701 return Result;
11702}
11703
11704template<typename Derived>
11705ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011706TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11707 CXXStdInitializerListExpr *E) {
11708 return getDerived().TransformExpr(E->getSubExpr());
11709}
11710
11711template<typename Derived>
11712ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011713TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011714 return SemaRef.MaybeBindToTemporary(E);
11715}
11716
11717template<typename Derived>
11718ExprResult
11719TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011720 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011721}
11722
11723template<typename Derived>
11724ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011725TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11726 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11727 if (SubExpr.isInvalid())
11728 return ExprError();
11729
11730 if (!getDerived().AlwaysRebuild() &&
11731 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011732 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011733
11734 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011735}
11736
11737template<typename Derived>
11738ExprResult
11739TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11740 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011741 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011742 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011743 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011744 /*IsCall=*/false, Elements, &ArgChanged))
11745 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011746
Ted Kremeneke65b0862012-03-06 20:05:56 +000011747 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11748 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011749
Ted Kremeneke65b0862012-03-06 20:05:56 +000011750 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11751 Elements.data(),
11752 Elements.size());
11753}
11754
11755template<typename Derived>
11756ExprResult
11757TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011758 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011759 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011760 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011761 bool ArgChanged = false;
11762 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11763 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011764
Ted Kremeneke65b0862012-03-06 20:05:56 +000011765 if (OrigElement.isPackExpansion()) {
11766 // This key/value element is a pack expansion.
11767 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11768 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11769 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11770 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11771
11772 // Determine whether the set of unexpanded parameter packs can
11773 // and should be expanded.
11774 bool Expand = true;
11775 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011776 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11777 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011778 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11779 OrigElement.Value->getLocEnd());
11780 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11781 PatternRange,
11782 Unexpanded,
11783 Expand, RetainExpansion,
11784 NumExpansions))
11785 return ExprError();
11786
11787 if (!Expand) {
11788 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011789 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011790 // expansion.
11791 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11792 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11793 if (Key.isInvalid())
11794 return ExprError();
11795
11796 if (Key.get() != OrigElement.Key)
11797 ArgChanged = true;
11798
11799 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11800 if (Value.isInvalid())
11801 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011802
Ted Kremeneke65b0862012-03-06 20:05:56 +000011803 if (Value.get() != OrigElement.Value)
11804 ArgChanged = true;
11805
Chad Rosier1dcde962012-08-08 18:46:20 +000011806 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011807 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11808 };
11809 Elements.push_back(Expansion);
11810 continue;
11811 }
11812
11813 // Record right away that the argument was changed. This needs
11814 // to happen even if the array expands to nothing.
11815 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011816
Ted Kremeneke65b0862012-03-06 20:05:56 +000011817 // The transform has determined that we should perform an elementwise
11818 // expansion of the pattern. Do so.
11819 for (unsigned I = 0; I != *NumExpansions; ++I) {
11820 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11821 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11822 if (Key.isInvalid())
11823 return ExprError();
11824
11825 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11826 if (Value.isInvalid())
11827 return ExprError();
11828
Chad Rosier1dcde962012-08-08 18:46:20 +000011829 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011830 Key.get(), Value.get(), SourceLocation(), NumExpansions
11831 };
11832
11833 // If any unexpanded parameter packs remain, we still have a
11834 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011835 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011836 if (Key.get()->containsUnexpandedParameterPack() ||
11837 Value.get()->containsUnexpandedParameterPack())
11838 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011839
Ted Kremeneke65b0862012-03-06 20:05:56 +000011840 Elements.push_back(Element);
11841 }
11842
Richard Smith9467be42014-06-06 17:33:35 +000011843 // FIXME: Retain a pack expansion if RetainExpansion is true.
11844
Ted Kremeneke65b0862012-03-06 20:05:56 +000011845 // We've finished with this pack expansion.
11846 continue;
11847 }
11848
11849 // Transform and check key.
11850 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11851 if (Key.isInvalid())
11852 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011853
Ted Kremeneke65b0862012-03-06 20:05:56 +000011854 if (Key.get() != OrigElement.Key)
11855 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011856
Ted Kremeneke65b0862012-03-06 20:05:56 +000011857 // Transform and check value.
11858 ExprResult Value
11859 = getDerived().TransformExpr(OrigElement.Value);
11860 if (Value.isInvalid())
11861 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011862
Ted Kremeneke65b0862012-03-06 20:05:56 +000011863 if (Value.get() != OrigElement.Value)
11864 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011865
11866 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011867 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011868 };
11869 Elements.push_back(Element);
11870 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011871
Ted Kremeneke65b0862012-03-06 20:05:56 +000011872 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11873 return SemaRef.MaybeBindToTemporary(E);
11874
11875 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011876 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011877}
11878
Mike Stump11289f42009-09-09 15:08:12 +000011879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011880ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011881TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011882 TypeSourceInfo *EncodedTypeInfo
11883 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11884 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011886
Douglas Gregora16548e2009-08-11 05:31:07 +000011887 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011888 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011889 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011890
11891 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011892 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011893 E->getRParenLoc());
11894}
Mike Stump11289f42009-09-09 15:08:12 +000011895
Douglas Gregora16548e2009-08-11 05:31:07 +000011896template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011897ExprResult TreeTransform<Derived>::
11898TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011899 // This is a kind of implicit conversion, and it needs to get dropped
11900 // and recomputed for the same general reasons that ImplicitCastExprs
11901 // do, as well a more specific one: this expression is only valid when
11902 // it appears *immediately* as an argument expression.
11903 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011904}
11905
11906template<typename Derived>
11907ExprResult TreeTransform<Derived>::
11908TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011909 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011910 = getDerived().TransformType(E->getTypeInfoAsWritten());
11911 if (!TSInfo)
11912 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011913
John McCall31168b02011-06-15 23:02:42 +000011914 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011915 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011916 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011917
John McCall31168b02011-06-15 23:02:42 +000011918 if (!getDerived().AlwaysRebuild() &&
11919 TSInfo == E->getTypeInfoAsWritten() &&
11920 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011921 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011922
John McCall31168b02011-06-15 23:02:42 +000011923 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011924 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011925 Result.get());
11926}
11927
Erik Pilkington29099de2016-07-16 00:35:23 +000011928template <typename Derived>
11929ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11930 ObjCAvailabilityCheckExpr *E) {
11931 return E;
11932}
11933
John McCall31168b02011-06-15 23:02:42 +000011934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011936TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011937 // Transform arguments.
11938 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011939 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011940 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011941 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011942 &ArgChanged))
11943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011944
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011945 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11946 // Class message: transform the receiver type.
11947 TypeSourceInfo *ReceiverTypeInfo
11948 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11949 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011950 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011951
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011952 // If nothing changed, just retain the existing message send.
11953 if (!getDerived().AlwaysRebuild() &&
11954 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011955 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011956
11957 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011958 SmallVector<SourceLocation, 16> SelLocs;
11959 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011960 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11961 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011962 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011963 E->getMethodDecl(),
11964 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011965 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011966 E->getRightLoc());
11967 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011968 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11969 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011970 if (!E->getMethodDecl())
11971 return ExprError();
11972
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011973 // Build a new class message send to 'super'.
11974 SmallVector<SourceLocation, 16> SelLocs;
11975 E->getSelectorLocs(SelLocs);
11976 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11977 E->getSelector(),
11978 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011979 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011980 E->getMethodDecl(),
11981 E->getLeftLoc(),
11982 Args,
11983 E->getRightLoc());
11984 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011985
11986 // Instance message: transform the receiver
11987 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11988 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011989 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011990 = getDerived().TransformExpr(E->getInstanceReceiver());
11991 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011992 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011993
11994 // If nothing changed, just retain the existing message send.
11995 if (!getDerived().AlwaysRebuild() &&
11996 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011997 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011998
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011999 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012000 SmallVector<SourceLocation, 16> SelLocs;
12001 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012002 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012003 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012004 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012005 E->getMethodDecl(),
12006 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012007 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012008 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012009}
12010
Mike Stump11289f42009-09-09 15:08:12 +000012011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012012ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012013TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012014 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012015}
12016
Mike Stump11289f42009-09-09 15:08:12 +000012017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012018ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012019TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012020 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012021}
12022
Mike Stump11289f42009-09-09 15:08:12 +000012023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012024ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012025TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012026 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012027 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012028 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012029 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012030
12031 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012032
Douglas Gregord51d90d2010-04-26 20:11:03 +000012033 // If nothing changed, just retain the existing expression.
12034 if (!getDerived().AlwaysRebuild() &&
12035 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012036 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012037
John McCallb268a282010-08-23 23:25:46 +000012038 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012039 E->getLocation(),
12040 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012041}
12042
Mike Stump11289f42009-09-09 15:08:12 +000012043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012044ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012045TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012046 // 'super' and types never change. Property never changes. Just
12047 // retain the existing expression.
12048 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012049 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012050
Douglas Gregor9faee212010-04-26 20:47:02 +000012051 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012052 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012053 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012054 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012055
Douglas Gregor9faee212010-04-26 20:47:02 +000012056 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012057
Douglas Gregor9faee212010-04-26 20:47:02 +000012058 // If nothing changed, just retain the existing expression.
12059 if (!getDerived().AlwaysRebuild() &&
12060 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012061 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012062
John McCallb7bd14f2010-12-02 01:19:52 +000012063 if (E->isExplicitProperty())
12064 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12065 E->getExplicitProperty(),
12066 E->getLocation());
12067
12068 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012069 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012070 E->getImplicitPropertyGetter(),
12071 E->getImplicitPropertySetter(),
12072 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012073}
12074
Mike Stump11289f42009-09-09 15:08:12 +000012075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012076ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012077TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12078 // Transform the base expression.
12079 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12080 if (Base.isInvalid())
12081 return ExprError();
12082
12083 // Transform the key expression.
12084 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12085 if (Key.isInvalid())
12086 return ExprError();
12087
12088 // If nothing changed, just retain the existing expression.
12089 if (!getDerived().AlwaysRebuild() &&
12090 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012091 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012092
Chad Rosier1dcde962012-08-08 18:46:20 +000012093 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012094 Base.get(), Key.get(),
12095 E->getAtIndexMethodDecl(),
12096 E->setAtIndexMethodDecl());
12097}
12098
12099template<typename Derived>
12100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012101TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012102 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012103 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012104 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012105 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012106
Douglas Gregord51d90d2010-04-26 20:11:03 +000012107 // If nothing changed, just retain the existing expression.
12108 if (!getDerived().AlwaysRebuild() &&
12109 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012110 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012111
John McCallb268a282010-08-23 23:25:46 +000012112 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012113 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012114 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012115}
12116
Mike Stump11289f42009-09-09 15:08:12 +000012117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012119TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012120 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012121 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012122 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012123 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012124 SubExprs, &ArgumentChanged))
12125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012126
Douglas Gregora16548e2009-08-11 05:31:07 +000012127 if (!getDerived().AlwaysRebuild() &&
12128 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012129 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012130
Douglas Gregora16548e2009-08-11 05:31:07 +000012131 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012132 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012133 E->getRParenLoc());
12134}
12135
Mike Stump11289f42009-09-09 15:08:12 +000012136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012137ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012138TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12139 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12140 if (SrcExpr.isInvalid())
12141 return ExprError();
12142
12143 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12144 if (!Type)
12145 return ExprError();
12146
12147 if (!getDerived().AlwaysRebuild() &&
12148 Type == E->getTypeSourceInfo() &&
12149 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012150 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012151
12152 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12153 SrcExpr.get(), Type,
12154 E->getRParenLoc());
12155}
12156
12157template<typename Derived>
12158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012159TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012160 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012161
Craig Topperc3ec1492014-05-26 06:22:03 +000012162 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012163 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12164
12165 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012166 blockScope->TheDecl->setBlockMissingReturnType(
12167 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012168
Chris Lattner01cf8db2011-07-20 06:58:45 +000012169 SmallVector<ParmVarDecl*, 4> params;
12170 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012171
John McCallc8e321d2016-03-01 02:09:25 +000012172 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12173
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012174 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012175 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012176 if (getDerived().TransformFunctionTypeParams(
12177 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12178 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12179 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012180 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012181 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012182 }
John McCall490112f2011-02-04 18:33:18 +000012183
Eli Friedman34b49062012-01-26 03:00:14 +000012184 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012185 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012186
John McCallc8e321d2016-03-01 02:09:25 +000012187 auto epi = exprFunctionType->getExtProtoInfo();
12188 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12189
Jordan Rose5c382722013-03-08 21:51:21 +000012190 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012191 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012192 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012193
12194 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012195 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012196 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012197
12198 if (!oldBlock->blockMissingReturnType()) {
12199 blockScope->HasImplicitReturnType = false;
12200 blockScope->ReturnType = exprResultType;
12201 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012202
John McCall3882ace2011-01-05 12:14:39 +000012203 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012204 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012205 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012206 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012207 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012208 }
John McCall3882ace2011-01-05 12:14:39 +000012209
John McCall490112f2011-02-04 18:33:18 +000012210#ifndef NDEBUG
12211 // In builds with assertions, make sure that we captured everything we
12212 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012213 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012214 for (const auto &I : oldBlock->captures()) {
12215 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012216
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012217 // Ignore parameter packs.
12218 if (isa<ParmVarDecl>(oldCapture) &&
12219 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12220 continue;
John McCall490112f2011-02-04 18:33:18 +000012221
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012222 VarDecl *newCapture =
12223 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12224 oldCapture));
12225 assert(blockScope->CaptureMap.count(newCapture));
12226 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012227 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012228 }
12229#endif
12230
12231 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012232 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012233}
12234
Mike Stump11289f42009-09-09 15:08:12 +000012235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012236ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012237TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012238 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012239}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012240
12241template<typename Derived>
12242ExprResult
12243TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012244 QualType RetTy = getDerived().TransformType(E->getType());
12245 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012246 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012247 SubExprs.reserve(E->getNumSubExprs());
12248 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12249 SubExprs, &ArgumentChanged))
12250 return ExprError();
12251
12252 if (!getDerived().AlwaysRebuild() &&
12253 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012254 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012255
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012256 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012257 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012258}
Chad Rosier1dcde962012-08-08 18:46:20 +000012259
Douglas Gregora16548e2009-08-11 05:31:07 +000012260//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012261// Type reconstruction
12262//===----------------------------------------------------------------------===//
12263
Mike Stump11289f42009-09-09 15:08:12 +000012264template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012265QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12266 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012267 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012268 getDerived().getBaseEntity());
12269}
12270
Mike Stump11289f42009-09-09 15:08:12 +000012271template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012272QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12273 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012274 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012275 getDerived().getBaseEntity());
12276}
12277
Mike Stump11289f42009-09-09 15:08:12 +000012278template<typename Derived>
12279QualType
John McCall70dd5f62009-10-30 00:06:24 +000012280TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12281 bool WrittenAsLValue,
12282 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012283 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012284 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012285}
12286
12287template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012288QualType
John McCall70dd5f62009-10-30 00:06:24 +000012289TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12290 QualType ClassType,
12291 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012292 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12293 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012294}
12295
12296template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012297QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12298 const ObjCTypeParamDecl *Decl,
12299 SourceLocation ProtocolLAngleLoc,
12300 ArrayRef<ObjCProtocolDecl *> Protocols,
12301 ArrayRef<SourceLocation> ProtocolLocs,
12302 SourceLocation ProtocolRAngleLoc) {
12303 return SemaRef.BuildObjCTypeParamType(Decl,
12304 ProtocolLAngleLoc, Protocols,
12305 ProtocolLocs, ProtocolRAngleLoc,
12306 /*FailOnError=*/true);
12307}
12308
12309template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012310QualType TreeTransform<Derived>::RebuildObjCObjectType(
12311 QualType BaseType,
12312 SourceLocation Loc,
12313 SourceLocation TypeArgsLAngleLoc,
12314 ArrayRef<TypeSourceInfo *> TypeArgs,
12315 SourceLocation TypeArgsRAngleLoc,
12316 SourceLocation ProtocolLAngleLoc,
12317 ArrayRef<ObjCProtocolDecl *> Protocols,
12318 ArrayRef<SourceLocation> ProtocolLocs,
12319 SourceLocation ProtocolRAngleLoc) {
12320 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12321 TypeArgs, TypeArgsRAngleLoc,
12322 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12323 ProtocolRAngleLoc,
12324 /*FailOnError=*/true);
12325}
12326
12327template<typename Derived>
12328QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12329 QualType PointeeType,
12330 SourceLocation Star) {
12331 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12332}
12333
12334template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012335QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012336TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12337 ArrayType::ArraySizeModifier SizeMod,
12338 const llvm::APInt *Size,
12339 Expr *SizeExpr,
12340 unsigned IndexTypeQuals,
12341 SourceRange BracketsRange) {
12342 if (SizeExpr || !Size)
12343 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12344 IndexTypeQuals, BracketsRange,
12345 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012346
12347 QualType Types[] = {
12348 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12349 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12350 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012351 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012352 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012353 QualType SizeType;
12354 for (unsigned I = 0; I != NumTypes; ++I)
12355 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12356 SizeType = Types[I];
12357 break;
12358 }
Mike Stump11289f42009-09-09 15:08:12 +000012359
Eli Friedman9562f392012-01-25 23:20:27 +000012360 // Note that we can return a VariableArrayType here in the case where
12361 // the element type was a dependent VariableArrayType.
12362 IntegerLiteral *ArraySize
12363 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12364 /*FIXME*/BracketsRange.getBegin());
12365 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012366 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012367 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012368}
Mike Stump11289f42009-09-09 15:08:12 +000012369
Douglas Gregord6ff3322009-08-04 16:50:30 +000012370template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012371QualType
12372TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012373 ArrayType::ArraySizeModifier SizeMod,
12374 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012375 unsigned IndexTypeQuals,
12376 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012377 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012378 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012379}
12380
12381template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012382QualType
Mike Stump11289f42009-09-09 15:08:12 +000012383TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012384 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012385 unsigned IndexTypeQuals,
12386 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012387 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012388 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012389}
Mike Stump11289f42009-09-09 15:08:12 +000012390
Douglas Gregord6ff3322009-08-04 16:50:30 +000012391template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012392QualType
12393TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012394 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012395 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012396 unsigned IndexTypeQuals,
12397 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012398 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012399 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012400 IndexTypeQuals, BracketsRange);
12401}
12402
12403template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012404QualType
12405TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012406 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012407 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012408 unsigned IndexTypeQuals,
12409 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012410 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012411 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012412 IndexTypeQuals, BracketsRange);
12413}
12414
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012415template <typename Derived>
12416QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12417 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12418 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12419 AttributeLoc);
12420}
12421
12422template <typename Derived>
12423QualType
12424TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12425 unsigned NumElements,
12426 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012427 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012428 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012429}
Mike Stump11289f42009-09-09 15:08:12 +000012430
Erich Keanef702b022018-07-13 19:46:04 +000012431template <typename Derived>
12432QualType TreeTransform<Derived>::RebuildDependentVectorType(
12433 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12434 VectorType::VectorKind VecKind) {
12435 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12436}
12437
Douglas Gregord6ff3322009-08-04 16:50:30 +000012438template<typename Derived>
12439QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12440 unsigned NumElements,
12441 SourceLocation AttributeLoc) {
12442 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12443 NumElements, true);
12444 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012445 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12446 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012447 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012448}
Mike Stump11289f42009-09-09 15:08:12 +000012449
Douglas Gregord6ff3322009-08-04 16:50:30 +000012450template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012451QualType
12452TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012453 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012454 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012455 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012456}
Mike Stump11289f42009-09-09 15:08:12 +000012457
Douglas Gregord6ff3322009-08-04 16:50:30 +000012458template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012459QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12460 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012461 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012462 const FunctionProtoType::ExtProtoInfo &EPI) {
12463 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012464 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012465 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012466 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012467}
Mike Stump11289f42009-09-09 15:08:12 +000012468
Douglas Gregord6ff3322009-08-04 16:50:30 +000012469template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012470QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12471 return SemaRef.Context.getFunctionNoProtoType(T);
12472}
12473
12474template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012475QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12476 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012477 assert(D && "no decl found");
12478 if (D->isInvalidDecl()) return QualType();
12479
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012480 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012481 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012482 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12483 // A valid resolved using typename pack expansion decl can have multiple
12484 // UsingDecls, but they must each have exactly one type, and it must be
12485 // the same type in every case. But we must have at least one expansion!
12486 if (UPD->expansions().empty()) {
12487 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12488 << UPD->isCXXClassMember() << UPD;
12489 return QualType();
12490 }
12491
12492 // We might still have some unresolved types. Try to pick a resolved type
12493 // if we can. The final instantiation will check that the remaining
12494 // unresolved types instantiate to the type we pick.
12495 QualType FallbackT;
12496 QualType T;
12497 for (auto *E : UPD->expansions()) {
12498 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12499 if (ThisT.isNull())
12500 continue;
12501 else if (ThisT->getAs<UnresolvedUsingType>())
12502 FallbackT = ThisT;
12503 else if (T.isNull())
12504 T = ThisT;
12505 else
12506 assert(getSema().Context.hasSameType(ThisT, T) &&
12507 "mismatched resolved types in using pack expansion");
12508 }
12509 return T.isNull() ? FallbackT : T;
12510 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012511 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012512 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12513
12514 // A valid resolved using typename decl points to exactly one type decl.
12515 assert(++Using->shadow_begin() == Using->shadow_end());
12516 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012517 } else {
12518 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12519 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12520 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12521 }
12522
12523 return SemaRef.Context.getTypeDeclType(Ty);
12524}
12525
12526template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012527QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12528 SourceLocation Loc) {
12529 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012530}
12531
12532template<typename Derived>
12533QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12534 return SemaRef.Context.getTypeOfType(Underlying);
12535}
12536
12537template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012538QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12539 SourceLocation Loc) {
12540 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012541}
12542
12543template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012544QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12545 UnaryTransformType::UTTKind UKind,
12546 SourceLocation Loc) {
12547 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12548}
12549
12550template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012551QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012552 TemplateName Template,
12553 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012554 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012555 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012556}
Mike Stump11289f42009-09-09 15:08:12 +000012557
Douglas Gregor1135c352009-08-06 05:28:30 +000012558template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012559QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12560 SourceLocation KWLoc) {
12561 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12562}
12563
12564template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012565QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012566 SourceLocation KWLoc,
12567 bool isReadPipe) {
12568 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12569 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012570}
12571
12572template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012573TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012574TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012575 bool TemplateKW,
12576 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012577 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012578 Template);
12579}
12580
12581template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012582TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012583TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012584 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000012585 const IdentifierInfo &Name,
12586 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012587 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012588 NamedDecl *FirstQualifierInScope,
12589 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012590 UnqualifiedId TemplateName;
12591 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012592 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012593 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012594 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012595 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012596 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012597 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012598 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012599}
Mike Stump11289f42009-09-09 15:08:12 +000012600
Douglas Gregora16548e2009-08-11 05:31:07 +000012601template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012602TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012603TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012604 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012605 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012606 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012607 QualType ObjectType,
12608 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012609 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012610 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012611 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012612 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000012613 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012614 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012615 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012616 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012617 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012618 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012619 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012620}
Chad Rosier1dcde962012-08-08 18:46:20 +000012621
Douglas Gregor71395fa2009-11-04 00:56:37 +000012622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012623ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012624TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12625 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012626 Expr *OrigCallee,
12627 Expr *First,
12628 Expr *Second) {
12629 Expr *Callee = OrigCallee->IgnoreParenCasts();
12630 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012631
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012632 if (First->getObjectKind() == OK_ObjCProperty) {
12633 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12634 if (BinaryOperator::isAssignmentOp(Opc))
12635 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12636 First, Second);
12637 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12638 if (Result.isInvalid())
12639 return ExprError();
12640 First = Result.get();
12641 }
12642
12643 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12644 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12645 if (Result.isInvalid())
12646 return ExprError();
12647 Second = Result.get();
12648 }
12649
Douglas Gregora16548e2009-08-11 05:31:07 +000012650 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012651 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012652 if (!First->getType()->isOverloadableType() &&
12653 !Second->getType()->isOverloadableType())
12654 return getSema().CreateBuiltinArraySubscriptExpr(First,
12655 Callee->getLocStart(),
12656 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012657 } else if (Op == OO_Arrow) {
12658 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012659 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12660 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000012661 if (!First->getType()->isOverloadableType() ||
12662 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
12663 // The argument is not of overloadable type, or this is an expression
12664 // of the form &Class::member, so try to create a built-in unary
12665 // operation.
John McCalle3027922010-08-25 11:45:40 +000012666 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012667 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012668
John McCallb268a282010-08-23 23:25:46 +000012669 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012670 }
12671 } else {
John McCallb268a282010-08-23 23:25:46 +000012672 if (!First->getType()->isOverloadableType() &&
12673 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012674 // Neither of the arguments is an overloadable type, so try to
12675 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012676 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012677 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012678 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012679 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012681
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012682 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012683 }
12684 }
Mike Stump11289f42009-09-09 15:08:12 +000012685
12686 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012687 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012688 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000012689 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000012690
John McCallb268a282010-08-23 23:25:46 +000012691 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000012692 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000012693 // If the overload could not be resolved in the template definition
12694 // (because we had a dependent argument), ADL is performed as part of
12695 // template instantiation.
12696 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000012697 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012698 // If we've resolved this to a particular non-member function, just call
12699 // that function. If we resolved it to a member function,
12700 // CreateOverloaded* will find that function for us.
12701 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12702 if (!isa<CXXMethodDecl>(ND))
12703 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000012704 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000012705 }
Mike Stump11289f42009-09-09 15:08:12 +000012706
Douglas Gregora16548e2009-08-11 05:31:07 +000012707 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012708 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012709 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012710
Douglas Gregora16548e2009-08-11 05:31:07 +000012711 // Create the overloaded operator invocation for unary operators.
12712 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012713 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012714 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000012715 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12716 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012717 }
Mike Stump11289f42009-09-09 15:08:12 +000012718
Douglas Gregore9d62932011-07-15 16:25:15 +000012719 if (Op == OO_Subscript) {
12720 SourceLocation LBrace;
12721 SourceLocation RBrace;
12722
12723 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012724 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012725 LBrace = SourceLocation::getFromRawEncoding(
12726 NameLoc.CXXOperatorName.BeginOpNameLoc);
12727 RBrace = SourceLocation::getFromRawEncoding(
12728 NameLoc.CXXOperatorName.EndOpNameLoc);
12729 } else {
12730 LBrace = Callee->getLocStart();
12731 RBrace = OpLoc;
12732 }
12733
12734 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12735 First, Second);
12736 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012737
Douglas Gregora16548e2009-08-11 05:31:07 +000012738 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012739 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000012740 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12741 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012742 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012744
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012745 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012746}
Mike Stump11289f42009-09-09 15:08:12 +000012747
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012748template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012749ExprResult
John McCallb268a282010-08-23 23:25:46 +000012750TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012751 SourceLocation OperatorLoc,
12752 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012753 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012754 TypeSourceInfo *ScopeType,
12755 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012756 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012757 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012758 QualType BaseType = Base->getType();
12759 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012760 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012761 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012762 !BaseType->getAs<PointerType>()->getPointeeType()
12763 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012764 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012765 return SemaRef.BuildPseudoDestructorExpr(
12766 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12767 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012768 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012769
Douglas Gregor678f90d2010-02-25 01:56:36 +000012770 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012771 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12772 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12773 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12774 NameInfo.setNamedTypeInfo(DestroyedType);
12775
Richard Smith8e4a3862012-05-15 06:15:11 +000012776 // The scope type is now known to be a valid nested name specifier
12777 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012778 if (ScopeType) {
12779 if (!ScopeType->getType()->getAs<TagType>()) {
12780 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12781 diag::err_expected_class_or_namespace)
12782 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12783 return ExprError();
12784 }
12785 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12786 CCLoc);
12787 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012788
Abramo Bagnara7945c982012-01-27 09:46:47 +000012789 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012790 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012791 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012792 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012793 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012794 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012795 /*TemplateArgs*/ nullptr,
12796 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012797}
12798
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012799template<typename Derived>
12800StmtResult
12801TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012802 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012803 CapturedDecl *CD = S->getCapturedDecl();
12804 unsigned NumParams = CD->getNumParams();
12805 unsigned ContextParamPos = CD->getContextParamPosition();
12806 SmallVector<Sema::CapturedParamNameType, 4> Params;
12807 for (unsigned I = 0; I < NumParams; ++I) {
12808 if (I != ContextParamPos) {
12809 Params.push_back(
12810 std::make_pair(
12811 CD->getParam(I)->getName(),
12812 getDerived().TransformType(CD->getParam(I)->getType())));
12813 } else {
12814 Params.push_back(std::make_pair(StringRef(), QualType()));
12815 }
12816 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012817 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012818 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012819 StmtResult Body;
12820 {
12821 Sema::CompoundScopeRAII CompoundScope(getSema());
12822 Body = getDerived().TransformStmt(S->getCapturedStmt());
12823 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012824
12825 if (Body.isInvalid()) {
12826 getSema().ActOnCapturedRegionError();
12827 return StmtError();
12828 }
12829
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012830 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012831}
12832
Douglas Gregord6ff3322009-08-04 16:50:30 +000012833} // end namespace clang
12834
Hans Wennborg59dbe862015-09-29 20:56:43 +000012835#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H