blob: a52234663d73d48a95723f8b9d41d4e61ca828a4 [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
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Richard Smith03a4aa32016-06-23 19:02:52 +0000413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000431 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregorebe10102009-08-20 07:17:43 +0000439 /// \brief Transform the definition of the given declaration.
440 ///
Mike Stump11289f42009-09-09 15:08:12 +0000441 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000442 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000445 }
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000450 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000459
Douglas Gregor14454802011-02-25 02:25:35 +0000460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000470
Douglas Gregorf816bd72009-09-03 22:13:48 +0000471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000477 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000481 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000505
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// \brief Transform the given template argument.
507 ///
Mike Stump11289f42009-09-09 15:08:12 +0000508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000517
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \brief Transform the given set of template arguments.
519 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000520 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000543
544 /// \brief Transform the given set of template arguments.
545 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000546 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000548 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000549 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563
John McCall0ad16662009-10-29 08:12:44 +0000564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
John McCallbcd03502009-12-07 02:54:59 +0000568 /// \brief Fakes up a TypeSourceInfo for a type.
569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000571 getDerived().getBaseLocation());
572 }
Mike Stump11289f42009-09-09 15:08:12 +0000573
John McCall550e0c22009-10-21 00:40:46 +0000574#define ABSTRACT_TYPELOC(CLASS, PARENT)
575#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000577#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Richard Smith2e321552014-11-12 02:00:47 +0000579 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000590
David Majnemerfad8f482013-10-15 09:33:02 +0000591 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000592
Chad Rosier1dcde962012-08-08 18:46:20 +0000593 QualType
John McCall31f82722010-11-12 08:19:04 +0000594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
Chad Rosier1dcde962012-08-08 18:46:20 +0000598 QualType
John McCall31f82722010-11-12 08:19:04 +0000599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000601 TemplateName Template,
602 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000603
Nico Weberc153d242014-07-28 00:02:09 +0000604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000607
John McCall58f10c32010-03-11 09:03:00 +0000608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000615 bool TransformFunctionTypeParams(
616 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617 const QualType *ParamTypes,
618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
619 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000621
622 /// \brief Transforms a single function-type parameter. Return null
623 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000624 ///
625 /// \param indexAdjustment - A number to add to the parameter's
626 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000627 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000628 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000629 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000630 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000631
John McCall31f82722010-11-12 08:19:04 +0000632 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000633
John McCalldadc5752010-08-24 06:29:42 +0000634 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000636
Faisal Vali2cba1332013-10-23 06:44:28 +0000637 TemplateParameterList *TransformTemplateParameterList(
638 TemplateParameterList *TPL) {
639 return TPL;
640 }
641
Richard Smithdb2630f2012-10-21 03:28:35 +0000642 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000643
Richard Smithdb2630f2012-10-21 03:28:35 +0000644 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000645 bool IsAddressOfOperand,
646 TypeSourceInfo **RecoveryTSI);
647
648 ExprResult TransformParenDependentScopeDeclRefExpr(
649 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000652 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000653
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000654// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000656#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000658 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000659#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000660 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000661 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000662#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000663#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000664
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000665#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000666 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667 OMPClause *Transform ## Class(Class *S);
668#include "clang/Basic/OpenMPKinds.def"
669
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// \brief Build a new pointer type given its pointee type.
671 ///
672 /// By default, performs semantic analysis when building the pointer type.
673 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000674 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675
676 /// \brief Build a new block pointer type given its pointee type.
677 ///
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000680 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681
John McCall70dd5f62009-10-30 00:06:24 +0000682 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683 ///
John McCall70dd5f62009-10-30 00:06:24 +0000684 /// By default, performs semantic analysis when building the
685 /// reference type. Subclasses may override this routine to provide
686 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
John McCall70dd5f62009-10-30 00:06:24 +0000688 /// \param LValue whether the type was written with an lvalue sigil
689 /// or an rvalue sigil.
690 QualType RebuildReferenceType(QualType ReferentType,
691 bool LValue,
692 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new member pointer type given the pointee type and the
695 /// class type it refers into.
696 ///
697 /// By default, performs semantic analysis when building the member pointer
698 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000699 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Manman Rene6be26c2016-09-13 17:25:08 +0000702 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
703 SourceLocation ProtocolLAngleLoc,
704 ArrayRef<ObjCProtocolDecl *> Protocols,
705 ArrayRef<SourceLocation> ProtocolLocs,
706 SourceLocation ProtocolRAngleLoc);
707
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000708 /// \brief Build an Objective-C object type.
709 ///
710 /// By default, performs semantic analysis when building the object type.
711 /// Subclasses may override this routine to provide different behavior.
712 QualType RebuildObjCObjectType(QualType BaseType,
713 SourceLocation Loc,
714 SourceLocation TypeArgsLAngleLoc,
715 ArrayRef<TypeSourceInfo *> TypeArgs,
716 SourceLocation TypeArgsRAngleLoc,
717 SourceLocation ProtocolLAngleLoc,
718 ArrayRef<ObjCProtocolDecl *> Protocols,
719 ArrayRef<SourceLocation> ProtocolLocs,
720 SourceLocation ProtocolRAngleLoc);
721
722 /// \brief Build a new Objective-C object pointer type given the pointee type.
723 ///
724 /// By default, directly builds the pointer type, with no additional semantic
725 /// analysis.
726 QualType RebuildObjCObjectPointerType(QualType PointeeType,
727 SourceLocation Star);
728
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 /// \brief Build a new array type given the element type, size
730 /// modifier, size of the array (if known), size expression, and index type
731 /// qualifiers.
732 ///
733 /// By default, performs semantic analysis when building the array type.
734 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000735 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000736 QualType RebuildArrayType(QualType ElementType,
737 ArrayType::ArraySizeModifier SizeMod,
738 const llvm::APInt *Size,
739 Expr *SizeExpr,
740 unsigned IndexTypeQuals,
741 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000742
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 /// \brief Build a new constant array type given the element type, size
744 /// modifier, (known) size of the array, and index type qualifiers.
745 ///
746 /// By default, performs semantic analysis when building the array type.
747 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000748 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000749 ArrayType::ArraySizeModifier SizeMod,
750 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000751 unsigned IndexTypeQuals,
752 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 /// \brief Build a new incomplete array type given the element type, size
755 /// modifier, and index type qualifiers.
756 ///
757 /// By default, performs semantic analysis when building the array type.
758 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000759 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000761 unsigned IndexTypeQuals,
762 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763
Mike Stump11289f42009-09-09 15:08:12 +0000764 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 /// size modifier, size expression, and index type qualifiers.
766 ///
767 /// By default, performs semantic analysis when building the array type.
768 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000769 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000771 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 unsigned IndexTypeQuals,
773 SourceRange BracketsRange);
774
Mike Stump11289f42009-09-09 15:08:12 +0000775 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 /// size modifier, size expression, and index type qualifiers.
777 ///
778 /// By default, performs semantic analysis when building the array type.
779 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000780 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000781 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000782 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 unsigned IndexTypeQuals,
784 SourceRange BracketsRange);
785
786 /// \brief Build a new vector type given the element type and
787 /// number of elements.
788 ///
789 /// By default, performs semantic analysis when building the vector type.
790 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000791 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000792 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000793
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 /// \brief Build a new extended vector type given the element type and
795 /// number of elements.
796 ///
797 /// By default, performs semantic analysis when building the vector type.
798 /// Subclasses may override this routine to provide different behavior.
799 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
800 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000801
802 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 /// given the element type and number of elements.
804 ///
805 /// By default, performs semantic analysis when building the vector type.
806 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000807 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000808 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000809 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new function type.
812 ///
813 /// By default, performs semantic analysis when building the function type.
814 /// Subclasses may override this routine to provide different behavior.
815 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000816 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000817 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000818
John McCall550e0c22009-10-21 00:40:46 +0000819 /// \brief Build a new unprototyped function type.
820 QualType RebuildFunctionNoProtoType(QualType ResultType);
821
John McCallb96ec562009-12-04 22:46:56 +0000822 /// \brief Rebuild an unresolved typename type, given the decl that
823 /// the UnresolvedUsingTypenameDecl was transformed to.
824 QualType RebuildUnresolvedUsingType(Decl *D);
825
Douglas Gregord6ff3322009-08-04 16:50:30 +0000826 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000827 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 return SemaRef.Context.getTypeDeclType(Typedef);
829 }
830
831 /// \brief Build a new class/struct/union type.
832 QualType RebuildRecordType(RecordDecl *Record) {
833 return SemaRef.Context.getTypeDeclType(Record);
834 }
835
836 /// \brief Build a new Enum type.
837 QualType RebuildEnumType(EnumDecl *Enum) {
838 return SemaRef.Context.getTypeDeclType(Enum);
839 }
John McCallfcc33b02009-09-05 00:15:47 +0000840
Mike Stump11289f42009-09-09 15:08:12 +0000841 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000842 ///
843 /// By default, performs semantic analysis when building the typeof type.
844 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000845 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000846
Mike Stump11289f42009-09-09 15:08:12 +0000847 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000848 ///
849 /// By default, builds a new TypeOfType with the given underlying type.
850 QualType RebuildTypeOfType(QualType Underlying);
851
Alexis Hunte852b102011-05-24 22:41:36 +0000852 /// \brief Build a new unary transform type.
853 QualType RebuildUnaryTransformType(QualType BaseType,
854 UnaryTransformType::UTTKind UKind,
855 SourceLocation Loc);
856
Richard Smith74aeef52013-04-26 16:15:35 +0000857 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000858 ///
859 /// By default, performs semantic analysis when building the decltype type.
860 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000861 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000862
Richard Smith74aeef52013-04-26 16:15:35 +0000863 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000864 ///
865 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000866 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000867 // Note, IsDependent is always false here: we implicitly convert an 'auto'
868 // which has been deduced to a dependent type into an undeduced 'auto', so
869 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000870 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000871 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000872 }
873
Douglas Gregord6ff3322009-08-04 16:50:30 +0000874 /// \brief Build a new template specialization type.
875 ///
876 /// By default, performs semantic analysis when building the template
877 /// specialization type. Subclasses may override this routine to provide
878 /// different behavior.
879 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000880 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000881 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000882
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000883 /// \brief Build a new parenthesized type.
884 ///
885 /// By default, builds a new ParenType type from the inner type.
886 /// Subclasses may override this routine to provide different behavior.
887 QualType RebuildParenType(QualType InnerType) {
888 return SemaRef.Context.getParenType(InnerType);
889 }
890
Douglas Gregord6ff3322009-08-04 16:50:30 +0000891 /// \brief Build a new qualified name type.
892 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000893 /// By default, builds a new ElaboratedType type from the keyword,
894 /// the nested-name-specifier and the named type.
895 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000896 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
897 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000898 NestedNameSpecifierLoc QualifierLoc,
899 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 return SemaRef.Context.getElaboratedType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000902 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000903 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000904
905 /// \brief Build a new typename type that refers to a template-id.
906 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000907 /// By default, builds a new DependentNameType type from the
908 /// nested-name-specifier and the given type. Subclasses may override
909 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000910 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000911 ElaboratedTypeKeyword Keyword,
912 NestedNameSpecifierLoc QualifierLoc,
913 const IdentifierInfo *Name,
914 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000915 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000916 // Rebuild the template name.
917 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000918 CXXScopeSpec SS;
919 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000920 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000921 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
922 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000923
Douglas Gregora7a795b2011-03-01 20:11:18 +0000924 if (InstName.isNull())
925 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregora7a795b2011-03-01 20:11:18 +0000927 // If it's still dependent, make a dependent specialization.
928 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000929 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
930 QualifierLoc.getNestedNameSpecifier(),
931 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000932 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Douglas Gregora7a795b2011-03-01 20:11:18 +0000934 // Otherwise, make an elaborated type wrapping a non-dependent
935 // specialization.
936 QualType T =
937 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
938 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000939
Craig Topperc3ec1492014-05-26 06:22:03 +0000940 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000941 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000942
943 return SemaRef.Context.getElaboratedType(Keyword,
944 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000945 T);
946 }
947
Douglas Gregord6ff3322009-08-04 16:50:30 +0000948 /// \brief Build a new typename type that refers to an identifier.
949 ///
950 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000951 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000952 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000953 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 NestedNameSpecifierLoc QualifierLoc,
956 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000957 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000958 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000959 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000961 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000962 // If the name is still dependent, just build a new dependent name type.
963 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000964 return SemaRef.Context.getDependentNameType(Keyword,
965 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000966 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000967 }
968
Abramo Bagnara6150c882010-05-11 21:36:43 +0000969 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000970 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000971 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000972
973 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
974
Abramo Bagnarad7548482010-05-19 21:37:53 +0000975 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000976 // into a non-dependent elaborated-type-specifier. Find the tag we're
977 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000978 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000979 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
980 if (!DC)
981 return QualType();
982
John McCallbf8c5192010-05-27 06:40:31 +0000983 if (SemaRef.RequireCompleteDeclContext(SS, DC))
984 return QualType();
985
Craig Topperc3ec1492014-05-26 06:22:03 +0000986 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000987 SemaRef.LookupQualifiedName(Result, DC);
988 switch (Result.getResultKind()) {
989 case LookupResult::NotFound:
990 case LookupResult::NotFoundInCurrentInstantiation:
991 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000992
Douglas Gregore677daf2010-03-31 22:19:08 +0000993 case LookupResult::Found:
994 Tag = Result.getAsSingle<TagDecl>();
995 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000996
Douglas Gregore677daf2010-03-31 22:19:08 +0000997 case LookupResult::FoundOverloaded:
998 case LookupResult::FoundUnresolvedValue:
999 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001000
Douglas Gregore677daf2010-03-31 22:19:08 +00001001 case LookupResult::Ambiguous:
1002 // Let the LookupResult structure handle ambiguities.
1003 return QualType();
1004 }
1005
1006 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001007 // Check where the name exists but isn't a tag type and use that to emit
1008 // better diagnostics.
1009 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1010 SemaRef.LookupQualifiedName(Result, DC);
1011 switch (Result.getResultKind()) {
1012 case LookupResult::Found:
1013 case LookupResult::FoundOverloaded:
1014 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001015 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00001016 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl);
1017 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << NTK;
Nick Lewycky0c438082011-01-24 19:01:04 +00001018 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1019 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001020 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001021 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001022 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001023 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001024 break;
1025 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001026 return QualType();
1027 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001028
Richard Trieucaa33d32011-06-10 03:11:26 +00001029 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001030 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001031 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001032 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1033 return QualType();
1034 }
1035
1036 // Build the elaborated-type-specifier type.
1037 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001038 return SemaRef.Context.getElaboratedType(Keyword,
1039 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001040 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001041 }
Mike Stump11289f42009-09-09 15:08:12 +00001042
Douglas Gregor822d0302011-01-12 17:07:58 +00001043 /// \brief Build a new pack expansion type.
1044 ///
1045 /// By default, builds a new PackExpansionType type from the given pattern.
1046 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001047 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001048 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001049 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001050 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001051 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1052 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001053 }
1054
Eli Friedman0dfb8892011-10-06 23:00:33 +00001055 /// \brief Build a new atomic type given its value type.
1056 ///
1057 /// By default, performs semantic analysis when building the atomic type.
1058 /// Subclasses may override this routine to provide different behavior.
1059 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1060
Xiuli Pan9c14e282016-01-09 12:53:17 +00001061 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001062 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1063 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001064
Douglas Gregor71dc5092009-08-06 06:41:21 +00001065 /// \brief Build a new template name given a nested name specifier, a flag
1066 /// indicating whether the "template" keyword was provided, and the template
1067 /// that the template name refers to.
1068 ///
1069 /// By default, builds the new template name directly. Subclasses may override
1070 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001071 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001072 bool TemplateKW,
1073 TemplateDecl *Template);
1074
Douglas Gregor71dc5092009-08-06 06:41:21 +00001075 /// \brief Build a new template name given a nested name specifier and the
1076 /// name that is referred to as a template.
1077 ///
1078 /// By default, performs semantic analysis to determine whether the name can
1079 /// be resolved to a specific template, then builds the appropriate kind of
1080 /// template name. Subclasses may override this routine to provide different
1081 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001082 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1083 const IdentifierInfo &Name,
1084 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001085 QualType ObjectType,
1086 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001087
Douglas Gregor71395fa2009-11-04 00:56:37 +00001088 /// \brief Build a new template name given a nested name specifier and the
1089 /// overloaded operator name that is referred to as a template.
1090 ///
1091 /// By default, performs semantic analysis to determine whether the name can
1092 /// be resolved to a specific template, then builds the appropriate kind of
1093 /// template name. Subclasses may override this routine to provide different
1094 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001095 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001096 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001097 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001098 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001099
1100 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001101 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001102 ///
1103 /// By default, performs semantic analysis to determine whether the name can
1104 /// be resolved to a specific template, then builds the appropriate kind of
1105 /// template name. Subclasses may override this routine to provide different
1106 /// behavior.
1107 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1108 const TemplateArgument &ArgPack) {
1109 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1110 }
1111
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 /// \brief Build a new compound statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001116 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001117 MultiStmtArg Statements,
1118 SourceLocation RBraceLoc,
1119 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001120 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 IsStmtExpr);
1122 }
1123
1124 /// \brief Build a new case statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001129 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001131 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001133 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 ColonLoc);
1135 }
Mike Stump11289f42009-09-09 15:08:12 +00001136
Douglas Gregorebe10102009-08-20 07:17:43 +00001137 /// \brief Attach the body to a new case statement.
1138 ///
1139 /// By default, performs semantic analysis to build the new statement.
1140 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001141 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001142 getSema().ActOnCaseStmtBody(S, Body);
1143 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 }
Mike Stump11289f42009-09-09 15:08:12 +00001145
Douglas Gregorebe10102009-08-20 07:17:43 +00001146 /// \brief Build a new default statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001150 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001152 Stmt *SubStmt) {
1153 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001154 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001155 }
Mike Stump11289f42009-09-09 15:08:12 +00001156
Douglas Gregorebe10102009-08-20 07:17:43 +00001157 /// \brief Build a new label statement.
1158 ///
1159 /// By default, performs semantic analysis to build the new statement.
1160 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001161 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1162 SourceLocation ColonLoc, Stmt *SubStmt) {
1163 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Richard Smithc202b282012-04-14 00:33:13 +00001166 /// \brief Build a new label statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001170 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1171 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001172 Stmt *SubStmt) {
1173 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1174 }
1175
Douglas Gregorebe10102009-08-20 07:17:43 +00001176 /// \brief Build a new "if" statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001180 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001181 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001182 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001183 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001184 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 }
Mike Stump11289f42009-09-09 15:08:12 +00001186
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 /// \brief Start building a new switch statement.
1188 ///
1189 /// By default, performs semantic analysis to build the new statement.
1190 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001191 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001192 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001193 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001194 }
Mike Stump11289f42009-09-09 15:08:12 +00001195
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 /// \brief Attach the body to the switch statement.
1197 ///
1198 /// By default, performs semantic analysis to build the new statement.
1199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001200 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001201 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001202 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001203 }
1204
1205 /// \brief Build a new while statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001209 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1210 Sema::ConditionResult Cond, Stmt *Body) {
1211 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 /// \brief Build a new do-while statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001218 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001219 SourceLocation WhileLoc, SourceLocation LParenLoc,
1220 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001221 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1222 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 }
1224
1225 /// \brief Build a new for statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001229 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001230 Stmt *Init, Sema::ConditionResult Cond,
1231 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1232 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001233 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001234 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 }
Mike Stump11289f42009-09-09 15:08:12 +00001236
Douglas Gregorebe10102009-08-20 07:17:43 +00001237 /// \brief Build a new goto statement.
1238 ///
1239 /// By default, performs semantic analysis to build the new statement.
1240 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001241 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1242 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001243 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 }
1245
1246 /// \brief Build a new indirect goto statement.
1247 ///
1248 /// By default, performs semantic analysis to build the new statement.
1249 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001250 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001251 SourceLocation StarLoc,
1252 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001253 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001254 }
Mike Stump11289f42009-09-09 15:08:12 +00001255
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 /// \brief Build a new return statement.
1257 ///
1258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001260 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001261 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001262 }
Mike Stump11289f42009-09-09 15:08:12 +00001263
Douglas Gregorebe10102009-08-20 07:17:43 +00001264 /// \brief Build a new declaration statement.
1265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001268 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001269 SourceLocation StartLoc, SourceLocation EndLoc) {
1270 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001271 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001272 }
Mike Stump11289f42009-09-09 15:08:12 +00001273
Anders Carlssonaaeef072010-01-24 05:50:09 +00001274 /// \brief Build a new inline asm statement.
1275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001278 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1279 bool IsVolatile, unsigned NumOutputs,
1280 unsigned NumInputs, IdentifierInfo **Names,
1281 MultiExprArg Constraints, MultiExprArg Exprs,
1282 Expr *AsmString, MultiExprArg Clobbers,
1283 SourceLocation RParenLoc) {
1284 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1285 NumInputs, Names, Constraints, Exprs,
1286 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001287 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001288
Chad Rosier32503022012-06-11 20:47:18 +00001289 /// \brief Build a new MS style inline asm statement.
1290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001293 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001294 ArrayRef<Token> AsmToks,
1295 StringRef AsmString,
1296 unsigned NumOutputs, unsigned NumInputs,
1297 ArrayRef<StringRef> Constraints,
1298 ArrayRef<StringRef> Clobbers,
1299 ArrayRef<Expr*> Exprs,
1300 SourceLocation EndLoc) {
1301 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1302 NumOutputs, NumInputs,
1303 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001304 }
1305
Richard Smith9f690bd2015-10-27 06:02:45 +00001306 /// \brief Build a new co_return statement.
1307 ///
1308 /// By default, performs semantic analysis to build the new statement.
1309 /// Subclasses may override this routine to provide different behavior.
1310 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1311 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1312 }
1313
1314 /// \brief Build a new co_await expression.
1315 ///
1316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
1318 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1319 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1320 }
1321
1322 /// \brief Build a new co_yield expression.
1323 ///
1324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
1326 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1327 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1328 }
1329
James Dennett2a4d13c2012-06-15 07:13:21 +00001330 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001336 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001337 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001338 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001339 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001340 }
1341
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001342 /// \brief Rebuild an Objective-C exception declaration.
1343 ///
1344 /// By default, performs semantic analysis to build the new declaration.
1345 /// Subclasses may override this routine to provide different behavior.
1346 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1347 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001348 return getSema().BuildObjCExceptionDecl(TInfo, T,
1349 ExceptionDecl->getInnerLocStart(),
1350 ExceptionDecl->getLocation(),
1351 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001352 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001353
James Dennett2a4d13c2012-06-15 07:13:21 +00001354 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001355 ///
1356 /// By default, performs semantic analysis to build the new statement.
1357 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001358 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001359 SourceLocation RParenLoc,
1360 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001361 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001362 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001363 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001365
James Dennett2a4d13c2012-06-15 07:13:21 +00001366 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001367 ///
1368 /// By default, performs semantic analysis to build the new statement.
1369 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001370 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001371 Stmt *Body) {
1372 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001373 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001374
James Dennett2a4d13c2012-06-15 07:13:21 +00001375 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001379 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001380 Expr *Operand) {
1381 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001383
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001384 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001385 ///
1386 /// By default, performs semantic analysis to build the new statement.
1387 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001388 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001389 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001390 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001391 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001392 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001393 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001394 return getSema().ActOnOpenMPExecutableDirective(
1395 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001396 }
1397
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001398 /// \brief Build a new OpenMP 'if' clause.
1399 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001400 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001401 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001402 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1403 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001404 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001405 SourceLocation NameModifierLoc,
1406 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001407 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001408 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1409 LParenLoc, NameModifierLoc, ColonLoc,
1410 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001411 }
1412
Alexey Bataev3778b602014-07-17 07:32:53 +00001413 /// \brief Build a new OpenMP 'final' clause.
1414 ///
1415 /// By default, performs semantic analysis to build the new OpenMP clause.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1418 SourceLocation LParenLoc,
1419 SourceLocation EndLoc) {
1420 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1421 EndLoc);
1422 }
1423
Alexey Bataev568a8332014-03-06 06:15:19 +00001424 /// \brief Build a new OpenMP 'num_threads' clause.
1425 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001426 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001427 /// Subclasses may override this routine to provide different behavior.
1428 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1429 SourceLocation StartLoc,
1430 SourceLocation LParenLoc,
1431 SourceLocation EndLoc) {
1432 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1433 LParenLoc, EndLoc);
1434 }
1435
Alexey Bataev62c87d22014-03-21 04:51:18 +00001436 /// \brief Build a new OpenMP 'safelen' clause.
1437 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001438 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001439 /// Subclasses may override this routine to provide different behavior.
1440 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1441 SourceLocation LParenLoc,
1442 SourceLocation EndLoc) {
1443 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1444 }
1445
Alexey Bataev66b15b52015-08-21 11:14:16 +00001446 /// \brief Build a new OpenMP 'simdlen' clause.
1447 ///
1448 /// By default, performs semantic analysis to build the new OpenMP clause.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1451 SourceLocation LParenLoc,
1452 SourceLocation EndLoc) {
1453 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1454 }
1455
Alexander Musman8bd31e62014-05-27 15:12:19 +00001456 /// \brief Build a new OpenMP 'collapse' clause.
1457 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001458 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001459 /// Subclasses may override this routine to provide different behavior.
1460 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1461 SourceLocation LParenLoc,
1462 SourceLocation EndLoc) {
1463 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1464 EndLoc);
1465 }
1466
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001467 /// \brief Build a new OpenMP 'default' clause.
1468 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001469 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001470 /// Subclasses may override this routine to provide different behavior.
1471 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1472 SourceLocation KindKwLoc,
1473 SourceLocation StartLoc,
1474 SourceLocation LParenLoc,
1475 SourceLocation EndLoc) {
1476 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1477 StartLoc, LParenLoc, EndLoc);
1478 }
1479
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001480 /// \brief Build a new OpenMP 'proc_bind' clause.
1481 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001482 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001483 /// Subclasses may override this routine to provide different behavior.
1484 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1485 SourceLocation KindKwLoc,
1486 SourceLocation StartLoc,
1487 SourceLocation LParenLoc,
1488 SourceLocation EndLoc) {
1489 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1490 StartLoc, LParenLoc, EndLoc);
1491 }
1492
Alexey Bataev56dafe82014-06-20 07:16:17 +00001493 /// \brief Build a new OpenMP 'schedule' clause.
1494 ///
1495 /// By default, performs semantic analysis to build the new OpenMP clause.
1496 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001497 OMPClause *RebuildOMPScheduleClause(
1498 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1499 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1500 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1501 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001502 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001503 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1504 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001505 }
1506
Alexey Bataev10e775f2015-07-30 11:36:16 +00001507 /// \brief Build a new OpenMP 'ordered' clause.
1508 ///
1509 /// By default, performs semantic analysis to build the new OpenMP clause.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1512 SourceLocation EndLoc,
1513 SourceLocation LParenLoc, Expr *Num) {
1514 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1515 }
1516
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001517 /// \brief Build a new OpenMP 'private' clause.
1518 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001519 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001520 /// Subclasses may override this routine to provide different behavior.
1521 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1522 SourceLocation StartLoc,
1523 SourceLocation LParenLoc,
1524 SourceLocation EndLoc) {
1525 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1526 EndLoc);
1527 }
1528
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001529 /// \brief Build a new OpenMP 'firstprivate' clause.
1530 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001531 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001532 /// Subclasses may override this routine to provide different behavior.
1533 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1534 SourceLocation StartLoc,
1535 SourceLocation LParenLoc,
1536 SourceLocation EndLoc) {
1537 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1538 EndLoc);
1539 }
1540
Alexander Musman1bb328c2014-06-04 13:06:39 +00001541 /// \brief Build a new OpenMP 'lastprivate' clause.
1542 ///
1543 /// By default, performs semantic analysis to build the new OpenMP clause.
1544 /// Subclasses may override this routine to provide different behavior.
1545 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1546 SourceLocation StartLoc,
1547 SourceLocation LParenLoc,
1548 SourceLocation EndLoc) {
1549 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1550 EndLoc);
1551 }
1552
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001553 /// \brief Build a new OpenMP 'shared' clause.
1554 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001555 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001556 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001557 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1558 SourceLocation StartLoc,
1559 SourceLocation LParenLoc,
1560 SourceLocation EndLoc) {
1561 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1562 EndLoc);
1563 }
1564
Alexey Bataevc5e02582014-06-16 07:08:35 +00001565 /// \brief Build a new OpenMP 'reduction' clause.
1566 ///
1567 /// By default, performs semantic analysis to build the new statement.
1568 /// Subclasses may override this routine to provide different behavior.
1569 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1570 SourceLocation StartLoc,
1571 SourceLocation LParenLoc,
1572 SourceLocation ColonLoc,
1573 SourceLocation EndLoc,
1574 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001575 const DeclarationNameInfo &ReductionId,
1576 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001577 return getSema().ActOnOpenMPReductionClause(
1578 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001579 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001580 }
1581
Alexander Musman8dba6642014-04-22 13:09:42 +00001582 /// \brief Build a new OpenMP 'linear' clause.
1583 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001584 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001585 /// Subclasses may override this routine to provide different behavior.
1586 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1587 SourceLocation StartLoc,
1588 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001589 OpenMPLinearClauseKind Modifier,
1590 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001591 SourceLocation ColonLoc,
1592 SourceLocation EndLoc) {
1593 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001594 Modifier, ModifierLoc, ColonLoc,
1595 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001596 }
1597
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001598 /// \brief Build a new OpenMP 'aligned' clause.
1599 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001600 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001601 /// Subclasses may override this routine to provide different behavior.
1602 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1603 SourceLocation StartLoc,
1604 SourceLocation LParenLoc,
1605 SourceLocation ColonLoc,
1606 SourceLocation EndLoc) {
1607 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1608 LParenLoc, ColonLoc, EndLoc);
1609 }
1610
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001611 /// \brief Build a new OpenMP 'copyin' clause.
1612 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001613 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001614 /// Subclasses may override this routine to provide different behavior.
1615 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1616 SourceLocation StartLoc,
1617 SourceLocation LParenLoc,
1618 SourceLocation EndLoc) {
1619 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1620 EndLoc);
1621 }
1622
Alexey Bataevbae9a792014-06-27 10:37:06 +00001623 /// \brief Build a new OpenMP 'copyprivate' clause.
1624 ///
1625 /// By default, performs semantic analysis to build the new OpenMP clause.
1626 /// Subclasses may override this routine to provide different behavior.
1627 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1628 SourceLocation StartLoc,
1629 SourceLocation LParenLoc,
1630 SourceLocation EndLoc) {
1631 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1632 EndLoc);
1633 }
1634
Alexey Bataev6125da92014-07-21 11:26:11 +00001635 /// \brief Build a new OpenMP 'flush' pseudo clause.
1636 ///
1637 /// By default, performs semantic analysis to build the new OpenMP clause.
1638 /// Subclasses may override this routine to provide different behavior.
1639 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1640 SourceLocation StartLoc,
1641 SourceLocation LParenLoc,
1642 SourceLocation EndLoc) {
1643 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1644 EndLoc);
1645 }
1646
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001647 /// \brief Build a new OpenMP 'depend' pseudo clause.
1648 ///
1649 /// By default, performs semantic analysis to build the new OpenMP clause.
1650 /// Subclasses may override this routine to provide different behavior.
1651 OMPClause *
1652 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1653 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1654 SourceLocation StartLoc, SourceLocation LParenLoc,
1655 SourceLocation EndLoc) {
1656 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1657 StartLoc, LParenLoc, EndLoc);
1658 }
1659
Michael Wonge710d542015-08-07 16:16:36 +00001660 /// \brief Build a new OpenMP 'device' clause.
1661 ///
1662 /// By default, performs semantic analysis to build the new statement.
1663 /// Subclasses may override this routine to provide different behavior.
1664 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1665 SourceLocation LParenLoc,
1666 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001667 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001668 EndLoc);
1669 }
1670
Kelvin Li0bff7af2015-11-23 05:32:03 +00001671 /// \brief Build a new OpenMP 'map' clause.
1672 ///
1673 /// By default, performs semantic analysis to build the new OpenMP clause.
1674 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001675 OMPClause *
1676 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1677 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1678 SourceLocation MapLoc, SourceLocation ColonLoc,
1679 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1680 SourceLocation LParenLoc, SourceLocation EndLoc) {
1681 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1682 IsMapTypeImplicit, MapLoc, ColonLoc,
1683 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001684 }
1685
Kelvin Li099bb8c2015-11-24 20:50:12 +00001686 /// \brief Build a new OpenMP 'num_teams' clause.
1687 ///
1688 /// By default, performs semantic analysis to build the new statement.
1689 /// Subclasses may override this routine to provide different behavior.
1690 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1691 SourceLocation LParenLoc,
1692 SourceLocation EndLoc) {
1693 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1694 EndLoc);
1695 }
1696
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001697 /// \brief Build a new OpenMP 'thread_limit' clause.
1698 ///
1699 /// By default, performs semantic analysis to build the new statement.
1700 /// Subclasses may override this routine to provide different behavior.
1701 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1702 SourceLocation StartLoc,
1703 SourceLocation LParenLoc,
1704 SourceLocation EndLoc) {
1705 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1706 LParenLoc, EndLoc);
1707 }
1708
Alexey Bataeva0569352015-12-01 10:17:31 +00001709 /// \brief Build a new OpenMP 'priority' clause.
1710 ///
1711 /// By default, performs semantic analysis to build the new statement.
1712 /// Subclasses may override this routine to provide different behavior.
1713 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1714 SourceLocation LParenLoc,
1715 SourceLocation EndLoc) {
1716 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1717 EndLoc);
1718 }
1719
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001720 /// \brief Build a new OpenMP 'grainsize' clause.
1721 ///
1722 /// By default, performs semantic analysis to build the new statement.
1723 /// Subclasses may override this routine to provide different behavior.
1724 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1725 SourceLocation LParenLoc,
1726 SourceLocation EndLoc) {
1727 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1728 EndLoc);
1729 }
1730
Alexey Bataev382967a2015-12-08 12:06:20 +00001731 /// \brief Build a new OpenMP 'num_tasks' clause.
1732 ///
1733 /// By default, performs semantic analysis to build the new statement.
1734 /// Subclasses may override this routine to provide different behavior.
1735 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1736 SourceLocation LParenLoc,
1737 SourceLocation EndLoc) {
1738 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1739 EndLoc);
1740 }
1741
Alexey Bataev28c75412015-12-15 08:19:24 +00001742 /// \brief Build a new OpenMP 'hint' clause.
1743 ///
1744 /// By default, performs semantic analysis to build the new statement.
1745 /// Subclasses may override this routine to provide different behavior.
1746 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1747 SourceLocation LParenLoc,
1748 SourceLocation EndLoc) {
1749 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1750 }
1751
Carlo Bertollib4adf552016-01-15 18:50:31 +00001752 /// \brief Build a new OpenMP 'dist_schedule' clause.
1753 ///
1754 /// By default, performs semantic analysis to build the new OpenMP clause.
1755 /// Subclasses may override this routine to provide different behavior.
1756 OMPClause *
1757 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1758 Expr *ChunkSize, SourceLocation StartLoc,
1759 SourceLocation LParenLoc, SourceLocation KindLoc,
1760 SourceLocation CommaLoc, SourceLocation EndLoc) {
1761 return getSema().ActOnOpenMPDistScheduleClause(
1762 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1763 }
1764
Samuel Antao661c0902016-05-26 17:39:58 +00001765 /// \brief Build a new OpenMP 'to' clause.
1766 ///
1767 /// By default, performs semantic analysis to build the new statement.
1768 /// Subclasses may override this routine to provide different behavior.
1769 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1770 SourceLocation StartLoc,
1771 SourceLocation LParenLoc,
1772 SourceLocation EndLoc) {
1773 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1774 }
1775
Samuel Antaoec172c62016-05-26 17:49:04 +00001776 /// \brief Build a new OpenMP 'from' clause.
1777 ///
1778 /// By default, performs semantic analysis to build the new statement.
1779 /// Subclasses may override this routine to provide different behavior.
1780 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1781 SourceLocation StartLoc,
1782 SourceLocation LParenLoc,
1783 SourceLocation EndLoc) {
1784 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1785 EndLoc);
1786 }
1787
Carlo Bertolli2404b172016-07-13 15:37:16 +00001788 /// Build a new OpenMP 'use_device_ptr' clause.
1789 ///
1790 /// By default, performs semantic analysis to build the new OpenMP clause.
1791 /// Subclasses may override this routine to provide different behavior.
1792 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1793 SourceLocation StartLoc,
1794 SourceLocation LParenLoc,
1795 SourceLocation EndLoc) {
1796 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1797 EndLoc);
1798 }
1799
Carlo Bertolli70594e92016-07-13 17:16:49 +00001800 /// Build a new OpenMP 'is_device_ptr' clause.
1801 ///
1802 /// By default, performs semantic analysis to build the new OpenMP clause.
1803 /// Subclasses may override this routine to provide different behavior.
1804 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1805 SourceLocation StartLoc,
1806 SourceLocation LParenLoc,
1807 SourceLocation EndLoc) {
1808 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1809 EndLoc);
1810 }
1811
James Dennett2a4d13c2012-06-15 07:13:21 +00001812 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001813 ///
1814 /// By default, performs semantic analysis to build the new statement.
1815 /// Subclasses may override this routine to provide different behavior.
1816 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1817 Expr *object) {
1818 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1819 }
1820
James Dennett2a4d13c2012-06-15 07:13:21 +00001821 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001822 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001823 /// By default, performs semantic analysis to build the new statement.
1824 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001825 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001826 Expr *Object, Stmt *Body) {
1827 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001828 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001829
James Dennett2a4d13c2012-06-15 07:13:21 +00001830 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001831 ///
1832 /// By default, performs semantic analysis to build the new statement.
1833 /// Subclasses may override this routine to provide different behavior.
1834 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1835 Stmt *Body) {
1836 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1837 }
John McCall53848232011-07-27 01:07:15 +00001838
Douglas Gregorf68a5082010-04-22 23:10:45 +00001839 /// \brief Build a new Objective-C fast enumeration statement.
1840 ///
1841 /// By default, performs semantic analysis to build the new statement.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001844 Stmt *Element,
1845 Expr *Collection,
1846 SourceLocation RParenLoc,
1847 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001848 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001849 Element,
John McCallb268a282010-08-23 23:25:46 +00001850 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001851 RParenLoc);
1852 if (ForEachStmt.isInvalid())
1853 return StmtError();
1854
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001855 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001856 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001857
Douglas Gregorebe10102009-08-20 07:17:43 +00001858 /// \brief Build a new C++ exception declaration.
1859 ///
1860 /// By default, performs semantic analysis to build the new decaration.
1861 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001862 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001863 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001864 SourceLocation StartLoc,
1865 SourceLocation IdLoc,
1866 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001867 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001868 StartLoc, IdLoc, Id);
1869 if (Var)
1870 getSema().CurContext->addDecl(Var);
1871 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001872 }
1873
1874 /// \brief Build a new C++ catch statement.
1875 ///
1876 /// By default, performs semantic analysis to build the new statement.
1877 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001879 VarDecl *ExceptionDecl,
1880 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001881 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1882 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001883 }
Mike Stump11289f42009-09-09 15:08:12 +00001884
Douglas Gregorebe10102009-08-20 07:17:43 +00001885 /// \brief Build a new C++ try statement.
1886 ///
1887 /// By default, performs semantic analysis to build the new statement.
1888 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001889 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1890 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001891 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001892 }
Mike Stump11289f42009-09-09 15:08:12 +00001893
Richard Smith02e85f32011-04-14 22:09:26 +00001894 /// \brief Build a new C++0x range-based for statement.
1895 ///
1896 /// By default, performs semantic analysis to build the new statement.
1897 /// Subclasses may override this routine to provide different behavior.
1898 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001899 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001900 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001901 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001902 Expr *Cond, Expr *Inc,
1903 Stmt *LoopVar,
1904 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001905 // If we've just learned that the range is actually an Objective-C
1906 // collection, treat this as an Objective-C fast enumeration loop.
1907 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1908 if (RangeStmt->isSingleDecl()) {
1909 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001910 if (RangeVar->isInvalidDecl())
1911 return StmtError();
1912
Douglas Gregorf7106af2013-04-08 18:40:13 +00001913 Expr *RangeExpr = RangeVar->getInit();
1914 if (!RangeExpr->isTypeDependent() &&
1915 RangeExpr->getType()->isObjCObjectPointerType())
1916 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1917 RParenLoc);
1918 }
1919 }
1920 }
1921
Richard Smithcfd53b42015-10-22 06:13:50 +00001922 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001923 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001924 Cond, Inc, LoopVar, RParenLoc,
1925 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001926 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001927
1928 /// \brief Build a new C++0x range-based for statement.
1929 ///
1930 /// By default, performs semantic analysis to build the new statement.
1931 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001932 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001933 bool IsIfExists,
1934 NestedNameSpecifierLoc QualifierLoc,
1935 DeclarationNameInfo NameInfo,
1936 Stmt *Nested) {
1937 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1938 QualifierLoc, NameInfo, Nested);
1939 }
1940
Richard Smith02e85f32011-04-14 22:09:26 +00001941 /// \brief Attach body to a C++0x range-based for statement.
1942 ///
1943 /// By default, performs semantic analysis to finish the new statement.
1944 /// Subclasses may override this routine to provide different behavior.
1945 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1946 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001948
David Majnemerfad8f482013-10-15 09:33:02 +00001949 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001950 Stmt *TryBlock, Stmt *Handler) {
1951 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001952 }
1953
David Majnemerfad8f482013-10-15 09:33:02 +00001954 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001955 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001956 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001957 }
1958
David Majnemerfad8f482013-10-15 09:33:02 +00001959 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001960 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001961 }
1962
Alexey Bataevec474782014-10-09 08:45:04 +00001963 /// \brief Build a new predefined expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
1967 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1968 PredefinedExpr::IdentType IT) {
1969 return getSema().BuildPredefinedExpr(Loc, IT);
1970 }
1971
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 /// \brief Build a new expression that references a declaration.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001976 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001977 LookupResult &R,
1978 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001979 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1980 }
1981
1982
1983 /// \brief Build a new expression that references a declaration.
1984 ///
1985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001987 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001988 ValueDecl *VD,
1989 const DeclarationNameInfo &NameInfo,
1990 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001991 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001992 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001993
1994 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001995
1996 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 }
Mike Stump11289f42009-09-09 15:08:12 +00001998
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002000 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 /// By default, performs semantic analysis to build the new expression.
2002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002003 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002005 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 }
2007
Douglas Gregorad8a3362009-09-04 17:36:40 +00002008 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002009 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002012 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002013 SourceLocation OperatorLoc,
2014 bool isArrow,
2015 CXXScopeSpec &SS,
2016 TypeSourceInfo *ScopeType,
2017 SourceLocation CCLoc,
2018 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002019 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002020
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002022 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002026 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002027 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002028 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 }
Mike Stump11289f42009-09-09 15:08:12 +00002030
Douglas Gregor882211c2010-04-28 22:16:22 +00002031 /// \brief Build a new builtin offsetof expression.
2032 ///
2033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002036 TypeSourceInfo *Type,
2037 ArrayRef<Sema::OffsetOfComponent> Components,
2038 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002039 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002040 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002041 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002042
2043 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002044 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002045 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002048 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2049 SourceLocation OpLoc,
2050 UnaryExprOrTypeTrait ExprKind,
2051 SourceRange R) {
2052 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 }
2054
Peter Collingbournee190dee2011-03-11 19:24:49 +00002055 /// \brief Build a new sizeof, alignof or vec step expression with an
2056 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002057 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002060 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2061 UnaryExprOrTypeTrait ExprKind,
2062 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002064 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002067
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002068 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 }
Mike Stump11289f42009-09-09 15:08:12 +00002070
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002072 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002075 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002077 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002079 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002080 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 RBracketLoc);
2082 }
2083
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002084 /// \brief Build a new array section expression.
2085 ///
2086 /// By default, performs semantic analysis to build the new expression.
2087 /// Subclasses may override this routine to provide different behavior.
2088 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2089 Expr *LowerBound,
2090 SourceLocation ColonLoc, Expr *Length,
2091 SourceLocation RBracketLoc) {
2092 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2093 ColonLoc, Length, RBracketLoc);
2094 }
2095
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002097 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002102 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002103 Expr *ExecConfig = nullptr) {
2104 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002105 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 }
2107
2108 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002109 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002112 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002113 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002114 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002115 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002116 const DeclarationNameInfo &MemberNameInfo,
2117 ValueDecl *Member,
2118 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002119 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002120 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002121 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2122 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002123 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002124 // We have a reference to an unnamed field. This is always the
2125 // base of an anonymous struct/union member access, i.e. the
2126 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002127 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002128 assert(Member->getType()->isRecordType() &&
2129 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002130
Richard Smithcab9a7d2011-10-26 19:06:56 +00002131 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002132 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002133 QualifierLoc.getNestedNameSpecifier(),
2134 FoundDecl, Member);
2135 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002136 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002137 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002138 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002139 MemberExpr *ME = new (getSema().Context)
2140 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2141 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002142 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002143 }
Mike Stump11289f42009-09-09 15:08:12 +00002144
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002145 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002146 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002147
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002148 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002149 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002150
John McCall16df1e52010-03-30 21:47:33 +00002151 // FIXME: this involves duplicating earlier analysis in a lot of
2152 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002153 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002154 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002155 R.resolveKind();
2156
John McCallb268a282010-08-23 23:25:46 +00002157 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002158 SS, TemplateKWLoc,
2159 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002160 R, ExplicitTemplateArgs,
2161 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 }
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002165 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002168 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002169 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002170 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002171 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 }
2173
2174 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002175 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 /// By default, performs semantic analysis to build the new expression.
2177 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002178 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002179 SourceLocation QuestionLoc,
2180 Expr *LHS,
2181 SourceLocation ColonLoc,
2182 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002183 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2184 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 }
2186
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002188 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002191 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002192 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002194 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002195 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002196 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 }
Mike Stump11289f42009-09-09 15:08:12 +00002198
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002200 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002203 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002204 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002206 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002207 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002208 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 SourceLocation OpLoc,
2217 SourceLocation AccessorLoc,
2218 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002219
John McCall10eae182009-11-30 22:42:35 +00002220 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002221 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002222 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002223 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002224 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002225 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002226 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002227 /* TemplateArgs */ nullptr,
2228 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 }
Mike Stump11289f42009-09-09 15:08:12 +00002230
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002232 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 /// By default, performs semantic analysis to build the new expression.
2234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002235 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002236 MultiExprArg Inits,
2237 SourceLocation RBraceLoc,
2238 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002240 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002241 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002242 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002243
Douglas Gregord3d93062009-11-09 17:16:50 +00002244 // Patch in the result type we were given, which may have been computed
2245 // when the initial InitListExpr was built.
2246 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2247 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002248 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 }
Mike Stump11289f42009-09-09 15:08:12 +00002250
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002252 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002255 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 MultiExprArg ArrayExprs,
2257 SourceLocation EqualOrColonLoc,
2258 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002259 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002260 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002262 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002265
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002266 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 }
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002270 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 /// By default, builds the implicit value initialization without performing
2272 /// any semantic analysis. Subclasses may override this routine to provide
2273 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002274 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002275 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 }
Mike Stump11289f42009-09-09 15:08:12 +00002277
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002279 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002282 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002283 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002284 SourceLocation RParenLoc) {
2285 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002286 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002287 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 }
2289
2290 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002291 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 /// By default, performs semantic analysis to build the new expression.
2293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002294 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002295 MultiExprArg SubExprs,
2296 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002297 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 }
Mike Stump11289f42009-09-09 15:08:12 +00002299
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002301 ///
2302 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 /// rather than attempting to map the label statement itself.
2304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002305 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002306 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002307 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002314 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002315 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002317 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 }
Mike Stump11289f42009-09-09 15:08:12 +00002319
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 /// \brief Build a new __builtin_choose_expr expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002324 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002325 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 SourceLocation RParenLoc) {
2327 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002328 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 RParenLoc);
2330 }
Mike Stump11289f42009-09-09 15:08:12 +00002331
Peter Collingbourne91147592011-04-15 00:35:48 +00002332 /// \brief Build a new generic selection expression.
2333 ///
2334 /// By default, performs semantic analysis to build the new expression.
2335 /// Subclasses may override this routine to provide different behavior.
2336 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2337 SourceLocation DefaultLoc,
2338 SourceLocation RParenLoc,
2339 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002340 ArrayRef<TypeSourceInfo *> Types,
2341 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002342 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002343 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002344 }
2345
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 /// \brief Build a new overloaded operator call expression.
2347 ///
2348 /// By default, performs semantic analysis to build the new expression.
2349 /// The semantic analysis provides the behavior of template instantiation,
2350 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002351 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 /// argument-dependent lookup, etc. Subclasses may override this routine to
2353 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002354 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002356 Expr *Callee,
2357 Expr *First,
2358 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002359
2360 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 /// reinterpret_cast.
2362 ///
2363 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002364 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002366 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 Stmt::StmtClass Class,
2368 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002369 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 SourceLocation RAngleLoc,
2371 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002372 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 SourceLocation RParenLoc) {
2374 switch (Class) {
2375 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002376 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002377 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002378 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002379
2380 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002381 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002382 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002383 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002384
Douglas Gregora16548e2009-08-11 05:31:07 +00002385 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002386 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002387 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002388 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002390
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002392 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002393 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002394 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002395
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002397 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 }
Mike Stump11289f42009-09-09 15:08:12 +00002400
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 /// \brief Build a new C++ static_cast expression.
2402 ///
2403 /// By default, performs semantic analysis to build the new expression.
2404 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002405 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002407 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 SourceLocation RAngleLoc,
2409 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002410 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002412 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002413 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002414 SourceRange(LAngleLoc, RAngleLoc),
2415 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 }
2417
2418 /// \brief Build a new C++ dynamic_cast expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002422 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002423 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002424 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 SourceLocation RAngleLoc,
2426 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002427 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002429 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002430 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002431 SourceRange(LAngleLoc, RAngleLoc),
2432 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 }
2434
2435 /// \brief Build a new C++ reinterpret_cast expression.
2436 ///
2437 /// By default, performs semantic analysis to build the new expression.
2438 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002439 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002441 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002442 SourceLocation RAngleLoc,
2443 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002444 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002445 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002446 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002447 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002448 SourceRange(LAngleLoc, RAngleLoc),
2449 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002450 }
2451
2452 /// \brief Build a new C++ const_cast expression.
2453 ///
2454 /// By default, performs semantic analysis to build the new expression.
2455 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002456 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002458 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 SourceLocation RAngleLoc,
2460 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002461 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002462 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002463 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002464 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002465 SourceRange(LAngleLoc, RAngleLoc),
2466 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 }
Mike Stump11289f42009-09-09 15:08:12 +00002468
Douglas Gregora16548e2009-08-11 05:31:07 +00002469 /// \brief Build a new C++ functional-style cast expression.
2470 ///
2471 /// By default, performs semantic analysis to build the new expression.
2472 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002473 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2474 SourceLocation LParenLoc,
2475 Expr *Sub,
2476 SourceLocation RParenLoc) {
2477 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002478 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002479 RParenLoc);
2480 }
Mike Stump11289f42009-09-09 15:08:12 +00002481
Douglas Gregora16548e2009-08-11 05:31:07 +00002482 /// \brief Build a new C++ typeid(type) expression.
2483 ///
2484 /// By default, performs semantic analysis to build the new expression.
2485 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002486 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002487 SourceLocation TypeidLoc,
2488 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002490 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002491 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002492 }
Mike Stump11289f42009-09-09 15:08:12 +00002493
Francois Pichet9f4f2072010-09-08 12:20:18 +00002494
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 /// \brief Build a new C++ typeid(expr) expression.
2496 ///
2497 /// By default, performs semantic analysis to build the new expression.
2498 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002499 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002500 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002501 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002503 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002504 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002505 }
2506
Francois Pichet9f4f2072010-09-08 12:20:18 +00002507 /// \brief Build a new C++ __uuidof(type) expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
2511 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2512 SourceLocation TypeidLoc,
2513 TypeSourceInfo *Operand,
2514 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002515 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002516 RParenLoc);
2517 }
2518
2519 /// \brief Build a new C++ __uuidof(expr) expression.
2520 ///
2521 /// By default, performs semantic analysis to build the new expression.
2522 /// Subclasses may override this routine to provide different behavior.
2523 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2524 SourceLocation TypeidLoc,
2525 Expr *Operand,
2526 SourceLocation RParenLoc) {
2527 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2528 RParenLoc);
2529 }
2530
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 /// \brief Build a new C++ "this" expression.
2532 ///
2533 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002534 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002535 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002536 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002537 QualType ThisType,
2538 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002539 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002540 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 }
2542
2543 /// \brief Build a new C++ throw expression.
2544 ///
2545 /// By default, performs semantic analysis to build the new expression.
2546 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002547 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2548 bool IsThrownVariableInScope) {
2549 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 }
2551
2552 /// \brief Build a new C++ default-argument expression.
2553 ///
2554 /// By default, builds a new default-argument expression, which does not
2555 /// require any semantic analysis. Subclasses may override this routine to
2556 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002557 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002558 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002559 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002560 }
2561
Richard Smith852c9db2013-04-20 22:23:05 +00002562 /// \brief Build a new C++11 default-initialization expression.
2563 ///
2564 /// By default, builds a new default field initialization expression, which
2565 /// does not require any semantic analysis. Subclasses may override this
2566 /// routine to provide different behavior.
2567 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2568 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002569 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002570 }
2571
Douglas Gregora16548e2009-08-11 05:31:07 +00002572 /// \brief Build a new C++ zero-initialization expression.
2573 ///
2574 /// By default, performs semantic analysis to build the new expression.
2575 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002576 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2577 SourceLocation LParenLoc,
2578 SourceLocation RParenLoc) {
2579 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002580 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 }
Mike Stump11289f42009-09-09 15:08:12 +00002582
Douglas Gregora16548e2009-08-11 05:31:07 +00002583 /// \brief Build a new C++ "new" expression.
2584 ///
2585 /// By default, performs semantic analysis to build the new expression.
2586 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002587 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002588 bool UseGlobal,
2589 SourceLocation PlacementLParen,
2590 MultiExprArg PlacementArgs,
2591 SourceLocation PlacementRParen,
2592 SourceRange TypeIdParens,
2593 QualType AllocatedType,
2594 TypeSourceInfo *AllocatedTypeInfo,
2595 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002596 SourceRange DirectInitRange,
2597 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002598 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002599 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002600 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002602 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002603 AllocatedType,
2604 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002605 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002606 DirectInitRange,
2607 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002608 }
Mike Stump11289f42009-09-09 15:08:12 +00002609
Douglas Gregora16548e2009-08-11 05:31:07 +00002610 /// \brief Build a new C++ "delete" expression.
2611 ///
2612 /// By default, performs semantic analysis to build the new expression.
2613 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002614 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002615 bool IsGlobalDelete,
2616 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002617 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002618 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002619 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002620 }
Mike Stump11289f42009-09-09 15:08:12 +00002621
Douglas Gregor29c42f22012-02-24 07:38:34 +00002622 /// \brief Build a new type trait expression.
2623 ///
2624 /// By default, performs semantic analysis to build the new expression.
2625 /// Subclasses may override this routine to provide different behavior.
2626 ExprResult RebuildTypeTrait(TypeTrait Trait,
2627 SourceLocation StartLoc,
2628 ArrayRef<TypeSourceInfo *> Args,
2629 SourceLocation RParenLoc) {
2630 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002632
John Wiegley6242b6a2011-04-28 00:16:57 +00002633 /// \brief Build a new array type trait expression.
2634 ///
2635 /// By default, performs semantic analysis to build the new expression.
2636 /// Subclasses may override this routine to provide different behavior.
2637 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2638 SourceLocation StartLoc,
2639 TypeSourceInfo *TSInfo,
2640 Expr *DimExpr,
2641 SourceLocation RParenLoc) {
2642 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2643 }
2644
John Wiegleyf9f65842011-04-25 06:54:41 +00002645 /// \brief Build a new expression trait expression.
2646 ///
2647 /// By default, performs semantic analysis to build the new expression.
2648 /// Subclasses may override this routine to provide different behavior.
2649 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2650 SourceLocation StartLoc,
2651 Expr *Queried,
2652 SourceLocation RParenLoc) {
2653 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2654 }
2655
Mike Stump11289f42009-09-09 15:08:12 +00002656 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002657 /// expression.
2658 ///
2659 /// By default, performs semantic analysis to build the new expression.
2660 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002661 ExprResult RebuildDependentScopeDeclRefExpr(
2662 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002663 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002664 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002665 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002666 bool IsAddressOfOperand,
2667 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002669 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002670
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002671 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002672 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2673 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002674
Reid Kleckner32506ed2014-06-12 23:03:48 +00002675 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002676 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002677 }
2678
2679 /// \brief Build a new template-id expression.
2680 ///
2681 /// By default, performs semantic analysis to build the new expression.
2682 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002683 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002684 SourceLocation TemplateKWLoc,
2685 LookupResult &R,
2686 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002687 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002688 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2689 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002690 }
2691
2692 /// \brief Build a new object-construction expression.
2693 ///
2694 /// By default, performs semantic analysis to build the new expression.
2695 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002696 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002697 SourceLocation Loc,
2698 CXXConstructorDecl *Constructor,
2699 bool IsElidable,
2700 MultiExprArg Args,
2701 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002702 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002703 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002704 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002705 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002706 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002707 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002708 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002709 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002710 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002711
Richard Smithc83bf822016-06-10 00:58:19 +00002712 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002713 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002714 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002715 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002716 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002717 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002718 RequiresZeroInit, ConstructKind,
2719 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002720 }
2721
Richard Smith5179eb72016-06-28 19:03:57 +00002722 /// \brief Build a new implicit construction via inherited constructor
2723 /// expression.
2724 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2725 CXXConstructorDecl *Constructor,
2726 bool ConstructsVBase,
2727 bool InheritedFromVBase) {
2728 return new (getSema().Context) CXXInheritedCtorInitExpr(
2729 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2730 }
2731
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 /// \brief Build a new object-construction expression.
2733 ///
2734 /// By default, performs semantic analysis to build the new expression.
2735 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002736 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2737 SourceLocation LParenLoc,
2738 MultiExprArg Args,
2739 SourceLocation RParenLoc) {
2740 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002741 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002742 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002743 RParenLoc);
2744 }
2745
2746 /// \brief Build a new object-construction expression.
2747 ///
2748 /// By default, performs semantic analysis to build the new expression.
2749 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002750 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2751 SourceLocation LParenLoc,
2752 MultiExprArg Args,
2753 SourceLocation RParenLoc) {
2754 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002755 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002756 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002757 RParenLoc);
2758 }
Mike Stump11289f42009-09-09 15:08:12 +00002759
Douglas Gregora16548e2009-08-11 05:31:07 +00002760 /// \brief Build a new member reference expression.
2761 ///
2762 /// By default, performs semantic analysis to build the new expression.
2763 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002764 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002765 QualType BaseType,
2766 bool IsArrow,
2767 SourceLocation OperatorLoc,
2768 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002769 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002770 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002771 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002772 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002773 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002774 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002775
John McCallb268a282010-08-23 23:25:46 +00002776 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002777 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002778 SS, TemplateKWLoc,
2779 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002780 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002781 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002782 }
2783
John McCall10eae182009-11-30 22:42:35 +00002784 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002785 ///
2786 /// By default, performs semantic analysis to build the new expression.
2787 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002788 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2789 SourceLocation OperatorLoc,
2790 bool IsArrow,
2791 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002792 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002793 NamedDecl *FirstQualifierInScope,
2794 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002795 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002796 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002797 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002798
John McCallb268a282010-08-23 23:25:46 +00002799 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002800 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002801 SS, TemplateKWLoc,
2802 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002803 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002804 }
Mike Stump11289f42009-09-09 15:08:12 +00002805
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002806 /// \brief Build a new noexcept expression.
2807 ///
2808 /// By default, performs semantic analysis to build the new expression.
2809 /// Subclasses may override this routine to provide different behavior.
2810 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2811 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2812 }
2813
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002814 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002815 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2816 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002817 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002818 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002819 Optional<unsigned> Length,
2820 ArrayRef<TemplateArgument> PartialArgs) {
2821 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2822 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002823 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002824
Patrick Beard0caa3942012-04-19 00:25:12 +00002825 /// \brief Build a new Objective-C boxed expression.
2826 ///
2827 /// By default, performs semantic analysis to build the new expression.
2828 /// Subclasses may override this routine to provide different behavior.
2829 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2830 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2831 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002832
Ted Kremeneke65b0862012-03-06 20:05:56 +00002833 /// \brief Build a new Objective-C array literal.
2834 ///
2835 /// By default, performs semantic analysis to build the new expression.
2836 /// Subclasses may override this routine to provide different behavior.
2837 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2838 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002839 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002840 MultiExprArg(Elements, NumElements));
2841 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002842
2843 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002844 Expr *Base, Expr *Key,
2845 ObjCMethodDecl *getterMethod,
2846 ObjCMethodDecl *setterMethod) {
2847 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2848 getterMethod, setterMethod);
2849 }
2850
2851 /// \brief Build a new Objective-C dictionary literal.
2852 ///
2853 /// By default, performs semantic analysis to build the new expression.
2854 /// Subclasses may override this routine to provide different behavior.
2855 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002856 MutableArrayRef<ObjCDictionaryElement> Elements) {
2857 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002858 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002859
James Dennett2a4d13c2012-06-15 07:13:21 +00002860 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002861 ///
2862 /// By default, performs semantic analysis to build the new expression.
2863 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002864 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002865 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002866 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002867 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002868 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002869
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002870 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002871 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002872 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002873 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002874 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002875 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002876 MultiExprArg Args,
2877 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002878 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2879 ReceiverTypeInfo->getType(),
2880 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002881 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002882 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002883 }
2884
2885 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002886 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002887 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002888 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002889 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002890 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002891 MultiExprArg Args,
2892 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002893 return SemaRef.BuildInstanceMessage(Receiver,
2894 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002895 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002896 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002897 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002898 }
2899
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002900 /// \brief Build a new Objective-C instance/class message to 'super'.
2901 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2902 Selector Sel,
2903 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002904 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002905 ObjCMethodDecl *Method,
2906 SourceLocation LBracLoc,
2907 MultiExprArg Args,
2908 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002909 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002910 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002911 SuperLoc,
2912 Sel, Method, LBracLoc, SelectorLocs,
2913 RBracLoc, Args)
2914 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002915 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002916 SuperLoc,
2917 Sel, Method, LBracLoc, SelectorLocs,
2918 RBracLoc, Args);
2919
2920
2921 }
2922
Douglas Gregord51d90d2010-04-26 20:11:03 +00002923 /// \brief Build a new Objective-C ivar reference expression.
2924 ///
2925 /// By default, performs semantic analysis to build the new expression.
2926 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002927 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002928 SourceLocation IvarLoc,
2929 bool IsArrow, bool IsFreeIvar) {
2930 // FIXME: We lose track of the IsFreeIvar bit.
2931 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002932 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2933 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002934 /*FIXME:*/IvarLoc, IsArrow,
2935 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002936 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002937 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002938 /*TemplateArgs=*/nullptr,
2939 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002940 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002941
2942 /// \brief Build a new Objective-C property reference expression.
2943 ///
2944 /// By default, performs semantic analysis to build the new expression.
2945 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002946 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002947 ObjCPropertyDecl *Property,
2948 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002949 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002950 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2951 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2952 /*FIXME:*/PropertyLoc,
2953 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002954 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002955 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002956 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002957 /*TemplateArgs=*/nullptr,
2958 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
John McCallb7bd14f2010-12-02 01:19:52 +00002961 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002962 ///
2963 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002964 /// Subclasses may override this routine to provide different behavior.
2965 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2966 ObjCMethodDecl *Getter,
2967 ObjCMethodDecl *Setter,
2968 SourceLocation PropertyLoc) {
2969 // Since these expressions can only be value-dependent, we do not
2970 // need to perform semantic analysis again.
2971 return Owned(
2972 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2973 VK_LValue, OK_ObjCProperty,
2974 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002975 }
2976
Douglas Gregord51d90d2010-04-26 20:11:03 +00002977 /// \brief Build a new Objective-C "isa" expression.
2978 ///
2979 /// By default, performs semantic analysis to build the new expression.
2980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002981 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002982 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002983 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002984 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2985 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002986 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002987 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002988 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002989 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002990 /*TemplateArgs=*/nullptr,
2991 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002993
Douglas Gregora16548e2009-08-11 05:31:07 +00002994 /// \brief Build a new shuffle vector expression.
2995 ///
2996 /// By default, performs semantic analysis to build the new expression.
2997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002998 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002999 MultiExprArg SubExprs,
3000 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003001 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003002 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003003 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3004 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3005 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003006 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003007
Douglas Gregora16548e2009-08-11 05:31:07 +00003008 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003009 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003010 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3011 SemaRef.Context.BuiltinFnTy,
3012 VK_RValue, BuiltinLoc);
3013 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3014 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003015 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003016
3017 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003018 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003019 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003020 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003021
Douglas Gregora16548e2009-08-11 05:31:07 +00003022 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003023 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003024 }
John McCall31f82722010-11-12 08:19:04 +00003025
Hal Finkelc4d7c822013-09-18 03:29:45 +00003026 /// \brief Build a new convert vector expression.
3027 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3028 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3029 SourceLocation RParenLoc) {
3030 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3031 BuiltinLoc, RParenLoc);
3032 }
3033
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003034 /// \brief Build a new template argument pack expansion.
3035 ///
3036 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003037 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003038 /// different behavior.
3039 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003040 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003041 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003042 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003043 case TemplateArgument::Expression: {
3044 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003045 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3046 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003047 if (Result.isInvalid())
3048 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003049
Douglas Gregor98318c22011-01-03 21:37:45 +00003050 return TemplateArgumentLoc(Result.get(), Result.get());
3051 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003052
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003053 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003054 return TemplateArgumentLoc(TemplateArgument(
3055 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003056 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003057 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003058 Pattern.getTemplateNameLoc(),
3059 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003060
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003061 case TemplateArgument::Null:
3062 case TemplateArgument::Integral:
3063 case TemplateArgument::Declaration:
3064 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003065 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003066 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003068
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003069 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003070 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003071 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003072 EllipsisLoc,
3073 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003074 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3075 Expansion);
3076 break;
3077 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003078
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003079 return TemplateArgumentLoc();
3080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003081
Douglas Gregor968f23a2011-01-03 19:31:53 +00003082 /// \brief Build a new expression pack expansion.
3083 ///
3084 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003085 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003086 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003087 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003088 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003089 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003090 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003091
Richard Smith0f0af192014-11-08 05:07:16 +00003092 /// \brief Build a new C++1z fold-expression.
3093 ///
3094 /// By default, performs semantic analysis in order to build a new fold
3095 /// expression.
3096 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3097 BinaryOperatorKind Operator,
3098 SourceLocation EllipsisLoc, Expr *RHS,
3099 SourceLocation RParenLoc) {
3100 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3101 RHS, RParenLoc);
3102 }
3103
3104 /// \brief Build an empty C++1z fold-expression with the given operator.
3105 ///
3106 /// By default, produces the fallback value for the fold-expression, or
3107 /// produce an error if there is no fallback value.
3108 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3109 BinaryOperatorKind Operator) {
3110 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3111 }
3112
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003113 /// \brief Build a new atomic operation expression.
3114 ///
3115 /// By default, performs semantic analysis to build the new expression.
3116 /// Subclasses may override this routine to provide different behavior.
3117 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3118 MultiExprArg SubExprs,
3119 QualType RetTy,
3120 AtomicExpr::AtomicOp Op,
3121 SourceLocation RParenLoc) {
3122 // Just create the expression; there is not any interesting semantic
3123 // analysis here because we can't actually build an AtomicExpr until
3124 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003125 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003126 RParenLoc);
3127 }
3128
John McCall31f82722010-11-12 08:19:04 +00003129private:
Douglas Gregor14454802011-02-25 02:25:35 +00003130 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3131 QualType ObjectType,
3132 NamedDecl *FirstQualifierInScope,
3133 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003134
3135 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3136 QualType ObjectType,
3137 NamedDecl *FirstQualifierInScope,
3138 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003139
3140 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3141 NamedDecl *FirstQualifierInScope,
3142 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003143};
Douglas Gregora16548e2009-08-11 05:31:07 +00003144
Douglas Gregorebe10102009-08-20 07:17:43 +00003145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003146StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003147 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003148 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregorebe10102009-08-20 07:17:43 +00003150 switch (S->getStmtClass()) {
3151 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003152
Douglas Gregorebe10102009-08-20 07:17:43 +00003153 // Transform individual statement nodes
3154#define STMT(Node, Parent) \
3155 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003156#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003157#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003158#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003159
Douglas Gregorebe10102009-08-20 07:17:43 +00003160 // Transform expressions by calling TransformExpr.
3161#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003162#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003163#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003164#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003165 {
John McCalldadc5752010-08-24 06:29:42 +00003166 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003167 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003168 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003169
Richard Smith945f8d32013-01-14 22:39:08 +00003170 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003171 }
Mike Stump11289f42009-09-09 15:08:12 +00003172 }
3173
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003174 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003175}
Mike Stump11289f42009-09-09 15:08:12 +00003176
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003177template<typename Derived>
3178OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3179 if (!S)
3180 return S;
3181
3182 switch (S->getClauseKind()) {
3183 default: break;
3184 // Transform individual clause nodes
3185#define OPENMP_CLAUSE(Name, Class) \
3186 case OMPC_ ## Name : \
3187 return getDerived().Transform ## Class(cast<Class>(S));
3188#include "clang/Basic/OpenMPKinds.def"
3189 }
3190
3191 return S;
3192}
3193
Mike Stump11289f42009-09-09 15:08:12 +00003194
Douglas Gregore922c772009-08-04 22:27:00 +00003195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003196ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003197 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003198 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003199
3200 switch (E->getStmtClass()) {
3201 case Stmt::NoStmtClass: break;
3202#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003203#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003204#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003205 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003206#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003207 }
3208
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003209 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003210}
3211
3212template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003213ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003214 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003215 // Initializers are instantiated like expressions, except that various outer
3216 // layers are stripped.
3217 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003218 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003219
3220 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3221 Init = ExprTemp->getSubExpr();
3222
Richard Smithe6ca4752013-05-30 22:40:16 +00003223 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3224 Init = MTE->GetTemporaryExpr();
3225
Richard Smithd59b8322012-12-19 01:39:02 +00003226 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3227 Init = Binder->getSubExpr();
3228
3229 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3230 Init = ICE->getSubExprAsWritten();
3231
Richard Smithcc1b96d2013-06-12 22:31:48 +00003232 if (CXXStdInitializerListExpr *ILE =
3233 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003234 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003235
Richard Smithc6abd962014-07-25 01:12:44 +00003236 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003237 // InitListExprs. Other forms of copy-initialization will be a no-op if
3238 // the initializer is already the right type.
3239 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003240 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003241 return getDerived().TransformExpr(Init);
3242
3243 // Revert value-initialization back to empty parens.
3244 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3245 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003246 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003247 Parens.getEnd());
3248 }
3249
3250 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3251 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003252 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003253 SourceLocation());
3254
3255 // Revert initialization by constructor back to a parenthesized or braced list
3256 // of expressions. Any other form of initializer can just be reused directly.
3257 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003258 return getDerived().TransformExpr(Init);
3259
Richard Smithf8adcdc2014-07-17 05:12:35 +00003260 // If the initialization implicitly converted an initializer list to a
3261 // std::initializer_list object, unwrap the std::initializer_list too.
3262 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003263 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003264
Richard Smithd59b8322012-12-19 01:39:02 +00003265 SmallVector<Expr*, 8> NewArgs;
3266 bool ArgChanged = false;
3267 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003268 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003269 return ExprError();
3270
3271 // If this was list initialization, revert to list form.
3272 if (Construct->isListInitialization())
3273 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3274 Construct->getLocEnd(),
3275 Construct->getType());
3276
Richard Smithd59b8322012-12-19 01:39:02 +00003277 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003278 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003279 if (Parens.isInvalid()) {
3280 // This was a variable declaration's initialization for which no initializer
3281 // was specified.
3282 assert(NewArgs.empty() &&
3283 "no parens or braces but have direct init with arguments?");
3284 return ExprEmpty();
3285 }
Richard Smithd59b8322012-12-19 01:39:02 +00003286 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3287 Parens.getEnd());
3288}
3289
3290template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003291bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003292 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003293 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003294 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003295 bool *ArgChanged) {
3296 for (unsigned I = 0; I != NumInputs; ++I) {
3297 // If requested, drop call arguments that need to be dropped.
3298 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3299 if (ArgChanged)
3300 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003301
Douglas Gregora3efea12011-01-03 19:04:46 +00003302 break;
3303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregor968f23a2011-01-03 19:31:53 +00003305 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3306 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003307
Chris Lattner01cf8db2011-07-20 06:58:45 +00003308 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003309 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3310 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregor968f23a2011-01-03 19:31:53 +00003312 // Determine whether the set of unexpanded parameter packs can and should
3313 // be expanded.
3314 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003315 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003316 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3317 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003318 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3319 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003320 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003321 Expand, RetainExpansion,
3322 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003323 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregor968f23a2011-01-03 19:31:53 +00003325 if (!Expand) {
3326 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003327 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003328 // expansion.
3329 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3330 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3331 if (OutPattern.isInvalid())
3332 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003333
3334 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003335 Expansion->getEllipsisLoc(),
3336 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003337 if (Out.isInvalid())
3338 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Douglas Gregor968f23a2011-01-03 19:31:53 +00003340 if (ArgChanged)
3341 *ArgChanged = true;
3342 Outputs.push_back(Out.get());
3343 continue;
3344 }
John McCall542e7c62011-07-06 07:30:07 +00003345
3346 // Record right away that the argument was changed. This needs
3347 // to happen even if the array expands to nothing.
3348 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregor968f23a2011-01-03 19:31:53 +00003350 // The transform has determined that we should perform an elementwise
3351 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003352 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003353 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3354 ExprResult Out = getDerived().TransformExpr(Pattern);
3355 if (Out.isInvalid())
3356 return true;
3357
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003358 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003359 Out = getDerived().RebuildPackExpansion(
3360 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003361 if (Out.isInvalid())
3362 return true;
3363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
Douglas Gregor968f23a2011-01-03 19:31:53 +00003365 Outputs.push_back(Out.get());
3366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Richard Smith9467be42014-06-06 17:33:35 +00003368 // If we're supposed to retain a pack expansion, do so by temporarily
3369 // forgetting the partially-substituted parameter pack.
3370 if (RetainExpansion) {
3371 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3372
3373 ExprResult Out = getDerived().TransformExpr(Pattern);
3374 if (Out.isInvalid())
3375 return true;
3376
3377 Out = getDerived().RebuildPackExpansion(
3378 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3379 if (Out.isInvalid())
3380 return true;
3381
3382 Outputs.push_back(Out.get());
3383 }
3384
Douglas Gregor968f23a2011-01-03 19:31:53 +00003385 continue;
3386 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Richard Smithd59b8322012-12-19 01:39:02 +00003388 ExprResult Result =
3389 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3390 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003391 if (Result.isInvalid())
3392 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003393
Douglas Gregora3efea12011-01-03 19:04:46 +00003394 if (Result.get() != Inputs[I] && ArgChanged)
3395 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003396
3397 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003398 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregora3efea12011-01-03 19:04:46 +00003400 return false;
3401}
3402
Richard Smith03a4aa32016-06-23 19:02:52 +00003403template <typename Derived>
3404Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3405 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3406 if (Var) {
3407 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3408 getDerived().TransformDefinition(Var->getLocation(), Var));
3409
3410 if (!ConditionVar)
3411 return Sema::ConditionError();
3412
3413 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3414 }
3415
3416 if (Expr) {
3417 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3418
3419 if (CondExpr.isInvalid())
3420 return Sema::ConditionError();
3421
3422 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3423 }
3424
3425 return Sema::ConditionResult();
3426}
3427
Douglas Gregora3efea12011-01-03 19:04:46 +00003428template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003429NestedNameSpecifierLoc
3430TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3431 NestedNameSpecifierLoc NNS,
3432 QualType ObjectType,
3433 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003434 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003435 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003436 Qualifier = Qualifier.getPrefix())
3437 Qualifiers.push_back(Qualifier);
3438
3439 CXXScopeSpec SS;
3440 while (!Qualifiers.empty()) {
3441 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3442 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003443
Douglas Gregor14454802011-02-25 02:25:35 +00003444 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003445 case NestedNameSpecifier::Identifier: {
3446 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3447 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3448 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3449 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003450 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003451 }
Douglas Gregor14454802011-02-25 02:25:35 +00003452 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregor14454802011-02-25 02:25:35 +00003454 case NestedNameSpecifier::Namespace: {
3455 NamespaceDecl *NS
3456 = cast_or_null<NamespaceDecl>(
3457 getDerived().TransformDecl(
3458 Q.getLocalBeginLoc(),
3459 QNNS->getAsNamespace()));
3460 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3461 break;
3462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregor14454802011-02-25 02:25:35 +00003464 case NestedNameSpecifier::NamespaceAlias: {
3465 NamespaceAliasDecl *Alias
3466 = cast_or_null<NamespaceAliasDecl>(
3467 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3468 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003469 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003470 Q.getLocalEndLoc());
3471 break;
3472 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003473
Douglas Gregor14454802011-02-25 02:25:35 +00003474 case NestedNameSpecifier::Global:
3475 // There is no meaningful transformation that one could perform on the
3476 // global scope.
3477 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3478 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003479
Nikola Smiljanic67860242014-09-26 00:28:20 +00003480 case NestedNameSpecifier::Super: {
3481 CXXRecordDecl *RD =
3482 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3483 SourceLocation(), QNNS->getAsRecordDecl()));
3484 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3485 break;
3486 }
3487
Douglas Gregor14454802011-02-25 02:25:35 +00003488 case NestedNameSpecifier::TypeSpecWithTemplate:
3489 case NestedNameSpecifier::TypeSpec: {
3490 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3491 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003492
Douglas Gregor14454802011-02-25 02:25:35 +00003493 if (!TL)
3494 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003495
Douglas Gregor14454802011-02-25 02:25:35 +00003496 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003497 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003498 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003499 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003500 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003501 if (TL.getType()->isEnumeralType())
3502 SemaRef.Diag(TL.getBeginLoc(),
3503 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003504 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3505 Q.getLocalEndLoc());
3506 break;
3507 }
Richard Trieude756fb2011-05-07 01:36:37 +00003508 // If the nested-name-specifier is an invalid type def, don't emit an
3509 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003510 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3511 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003512 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003513 << TL.getType() << SS.getRange();
3514 }
Douglas Gregor14454802011-02-25 02:25:35 +00003515 return NestedNameSpecifierLoc();
3516 }
Douglas Gregore16af532011-02-28 18:50:33 +00003517 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003518
Douglas Gregore16af532011-02-28 18:50:33 +00003519 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003520 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003521 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003522 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003523
Douglas Gregor14454802011-02-25 02:25:35 +00003524 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003525 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003526 !getDerived().AlwaysRebuild())
3527 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003528
3529 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003530 // nested-name-specifier, do so.
3531 if (SS.location_size() == NNS.getDataLength() &&
3532 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3533 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3534
3535 // Allocate new nested-name-specifier location information.
3536 return SS.getWithLocInContext(SemaRef.Context);
3537}
3538
3539template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003540DeclarationNameInfo
3541TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003542::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003543 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003544 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003545 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003546
3547 switch (Name.getNameKind()) {
3548 case DeclarationName::Identifier:
3549 case DeclarationName::ObjCZeroArgSelector:
3550 case DeclarationName::ObjCOneArgSelector:
3551 case DeclarationName::ObjCMultiArgSelector:
3552 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003553 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003554 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003555 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregorf816bd72009-09-03 22:13:48 +00003557 case DeclarationName::CXXConstructorName:
3558 case DeclarationName::CXXDestructorName:
3559 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003560 TypeSourceInfo *NewTInfo;
3561 CanQualType NewCanTy;
3562 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003563 NewTInfo = getDerived().TransformType(OldTInfo);
3564 if (!NewTInfo)
3565 return DeclarationNameInfo();
3566 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003567 }
3568 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003569 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003570 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003571 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003572 if (NewT.isNull())
3573 return DeclarationNameInfo();
3574 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3575 }
Mike Stump11289f42009-09-09 15:08:12 +00003576
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003577 DeclarationName NewName
3578 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3579 NewCanTy);
3580 DeclarationNameInfo NewNameInfo(NameInfo);
3581 NewNameInfo.setName(NewName);
3582 NewNameInfo.setNamedTypeInfo(NewTInfo);
3583 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003584 }
Mike Stump11289f42009-09-09 15:08:12 +00003585 }
3586
David Blaikie83d382b2011-09-23 05:06:16 +00003587 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003588}
3589
3590template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003591TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003592TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3593 TemplateName Name,
3594 SourceLocation NameLoc,
3595 QualType ObjectType,
3596 NamedDecl *FirstQualifierInScope) {
3597 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3598 TemplateDecl *Template = QTN->getTemplateDecl();
3599 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Douglas Gregor9db53502011-03-02 18:07:45 +00003601 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003602 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003603 Template));
3604 if (!TransTemplate)
3605 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003606
Douglas Gregor9db53502011-03-02 18:07:45 +00003607 if (!getDerived().AlwaysRebuild() &&
3608 SS.getScopeRep() == QTN->getQualifier() &&
3609 TransTemplate == Template)
3610 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregor9db53502011-03-02 18:07:45 +00003612 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3613 TransTemplate);
3614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
Douglas Gregor9db53502011-03-02 18:07:45 +00003616 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3617 if (SS.getScopeRep()) {
3618 // These apply to the scope specifier, not the template.
3619 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003620 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003621 }
3622
Douglas Gregor9db53502011-03-02 18:07:45 +00003623 if (!getDerived().AlwaysRebuild() &&
3624 SS.getScopeRep() == DTN->getQualifier() &&
3625 ObjectType.isNull())
3626 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregor9db53502011-03-02 18:07:45 +00003628 if (DTN->isIdentifier()) {
3629 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003630 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003631 NameLoc,
3632 ObjectType,
3633 FirstQualifierInScope);
3634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor9db53502011-03-02 18:07:45 +00003636 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3637 ObjectType);
3638 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor9db53502011-03-02 18:07:45 +00003640 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3641 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003642 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003643 Template));
3644 if (!TransTemplate)
3645 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregor9db53502011-03-02 18:07:45 +00003647 if (!getDerived().AlwaysRebuild() &&
3648 TransTemplate == Template)
3649 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003650
Douglas Gregor9db53502011-03-02 18:07:45 +00003651 return TemplateName(TransTemplate);
3652 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor9db53502011-03-02 18:07:45 +00003654 if (SubstTemplateTemplateParmPackStorage *SubstPack
3655 = Name.getAsSubstTemplateTemplateParmPack()) {
3656 TemplateTemplateParmDecl *TransParam
3657 = cast_or_null<TemplateTemplateParmDecl>(
3658 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3659 if (!TransParam)
3660 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003661
Douglas Gregor9db53502011-03-02 18:07:45 +00003662 if (!getDerived().AlwaysRebuild() &&
3663 TransParam == SubstPack->getParameterPack())
3664 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003665
3666 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003667 SubstPack->getArgumentPack());
3668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregor9db53502011-03-02 18:07:45 +00003670 // These should be getting filtered out before they reach the AST.
3671 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003672}
3673
3674template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003675void TreeTransform<Derived>::InventTemplateArgumentLoc(
3676 const TemplateArgument &Arg,
3677 TemplateArgumentLoc &Output) {
3678 SourceLocation Loc = getDerived().getBaseLocation();
3679 switch (Arg.getKind()) {
3680 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003681 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003682 break;
3683
3684 case TemplateArgument::Type:
3685 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003686 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003687
John McCall0ad16662009-10-29 08:12:44 +00003688 break;
3689
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003690 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003691 case TemplateArgument::TemplateExpansion: {
3692 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003693 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003694 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3695 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3696 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3697 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregor9d802122011-03-02 17:09:35 +00003699 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003700 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003701 Builder.getWithLocInContext(SemaRef.Context),
3702 Loc);
3703 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003704 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003705 Builder.getWithLocInContext(SemaRef.Context),
3706 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003707
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003708 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003709 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003710
John McCall0ad16662009-10-29 08:12:44 +00003711 case TemplateArgument::Expression:
3712 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3713 break;
3714
3715 case TemplateArgument::Declaration:
3716 case TemplateArgument::Integral:
3717 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003718 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003719 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003720 break;
3721 }
3722}
3723
3724template<typename Derived>
3725bool TreeTransform<Derived>::TransformTemplateArgument(
3726 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003727 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003728 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003729 switch (Arg.getKind()) {
3730 case TemplateArgument::Null:
3731 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003732 case TemplateArgument::Pack:
3733 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003734 case TemplateArgument::NullPtr:
3735 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregore922c772009-08-04 22:27:00 +00003737 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003738 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003739 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003740 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003741
3742 DI = getDerived().TransformType(DI);
3743 if (!DI) return true;
3744
3745 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3746 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003747 }
Mike Stump11289f42009-09-09 15:08:12 +00003748
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003749 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003750 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3751 if (QualifierLoc) {
3752 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3753 if (!QualifierLoc)
3754 return true;
3755 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003756
Douglas Gregordf846d12011-03-02 18:46:51 +00003757 CXXScopeSpec SS;
3758 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003759 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003760 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3761 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003762 if (Template.isNull())
3763 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregor9d802122011-03-02 17:09:35 +00003765 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003766 Input.getTemplateNameLoc());
3767 return false;
3768 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003769
3770 case TemplateArgument::TemplateExpansion:
3771 llvm_unreachable("Caller should expand pack expansions");
3772
Douglas Gregore922c772009-08-04 22:27:00 +00003773 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003774 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003775 EnterExpressionEvaluationContext Unevaluated(
3776 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003777
John McCall0ad16662009-10-29 08:12:44 +00003778 Expr *InputExpr = Input.getSourceExpression();
3779 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3780
Chris Lattnercdb591a2011-04-25 20:37:58 +00003781 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003782 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003783 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003784 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003785 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003786 }
Douglas Gregore922c772009-08-04 22:27:00 +00003787 }
Mike Stump11289f42009-09-09 15:08:12 +00003788
Douglas Gregore922c772009-08-04 22:27:00 +00003789 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003790 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003791}
3792
Douglas Gregorfe921a72010-12-20 23:36:19 +00003793/// \brief Iterator adaptor that invents template argument location information
3794/// for each of the template arguments in its underlying iterator.
3795template<typename Derived, typename InputIterator>
3796class TemplateArgumentLocInventIterator {
3797 TreeTransform<Derived> &Self;
3798 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003799
Douglas Gregorfe921a72010-12-20 23:36:19 +00003800public:
3801 typedef TemplateArgumentLoc value_type;
3802 typedef TemplateArgumentLoc reference;
3803 typedef typename std::iterator_traits<InputIterator>::difference_type
3804 difference_type;
3805 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003806
Douglas Gregorfe921a72010-12-20 23:36:19 +00003807 class pointer {
3808 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003809
Douglas Gregorfe921a72010-12-20 23:36:19 +00003810 public:
3811 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003812
Douglas Gregorfe921a72010-12-20 23:36:19 +00003813 const TemplateArgumentLoc *operator->() const { return &Arg; }
3814 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003815
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003816 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003817
Douglas Gregorfe921a72010-12-20 23:36:19 +00003818 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3819 InputIterator Iter)
3820 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003821
Douglas Gregorfe921a72010-12-20 23:36:19 +00003822 TemplateArgumentLocInventIterator &operator++() {
3823 ++Iter;
3824 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003826
Douglas Gregorfe921a72010-12-20 23:36:19 +00003827 TemplateArgumentLocInventIterator operator++(int) {
3828 TemplateArgumentLocInventIterator Old(*this);
3829 ++(*this);
3830 return Old;
3831 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003832
Douglas Gregorfe921a72010-12-20 23:36:19 +00003833 reference operator*() const {
3834 TemplateArgumentLoc Result;
3835 Self.InventTemplateArgumentLoc(*Iter, Result);
3836 return Result;
3837 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003838
Douglas Gregorfe921a72010-12-20 23:36:19 +00003839 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003840
Douglas Gregorfe921a72010-12-20 23:36:19 +00003841 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3842 const TemplateArgumentLocInventIterator &Y) {
3843 return X.Iter == Y.Iter;
3844 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003845
Douglas Gregorfe921a72010-12-20 23:36:19 +00003846 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3847 const TemplateArgumentLocInventIterator &Y) {
3848 return X.Iter != Y.Iter;
3849 }
3850};
Chad Rosier1dcde962012-08-08 18:46:20 +00003851
Douglas Gregor42cafa82010-12-20 17:42:22 +00003852template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003853template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003854bool TreeTransform<Derived>::TransformTemplateArguments(
3855 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3856 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003857 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003858 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003859 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003860
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003861 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3862 // Unpack argument packs, which we translate them into separate
3863 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003864 // FIXME: We could do much better if we could guarantee that the
3865 // TemplateArgumentLocInfo for the pack expansion would be usable for
3866 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003867 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003868 TemplateArgument::pack_iterator>
3869 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003870 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003871 In.getArgument().pack_begin()),
3872 PackLocIterator(*this,
3873 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003874 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003875 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003877 continue;
3878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003879
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003880 if (In.getArgument().isPackExpansion()) {
3881 // We have a pack expansion, for which we will be substituting into
3882 // the pattern.
3883 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003884 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003885 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003886 = getSema().getTemplateArgumentPackExpansionPattern(
3887 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003888
Chris Lattner01cf8db2011-07-20 06:58:45 +00003889 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003890 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3891 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003892
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003893 // Determine whether the set of unexpanded parameter packs can and should
3894 // be expanded.
3895 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003896 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003897 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003898 if (getDerived().TryExpandParameterPacks(Ellipsis,
3899 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003900 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003901 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003902 RetainExpansion,
3903 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003904 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003905
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003906 if (!Expand) {
3907 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003908 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003909 // expansion.
3910 TemplateArgumentLoc OutPattern;
3911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003912 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003913 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003915 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3916 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003917 if (Out.getArgument().isNull())
3918 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003919
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003920 Outputs.addArgument(Out);
3921 continue;
3922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003924 // The transform has determined that we should perform an elementwise
3925 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003926 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003927 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3928
Richard Smithd784e682015-09-23 21:41:42 +00003929 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003930 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003931
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003932 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003933 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3934 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003935 if (Out.getArgument().isNull())
3936 return true;
3937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003938
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003939 Outputs.addArgument(Out);
3940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003941
Douglas Gregor48d24112011-01-10 20:53:55 +00003942 // If we're supposed to retain a pack expansion, do so by temporarily
3943 // forgetting the partially-substituted parameter pack.
3944 if (RetainExpansion) {
3945 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003946
Richard Smithd784e682015-09-23 21:41:42 +00003947 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003948 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003949
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003950 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3951 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003952 if (Out.getArgument().isNull())
3953 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003954
Douglas Gregor48d24112011-01-10 20:53:55 +00003955 Outputs.addArgument(Out);
3956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003958 continue;
3959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003960
3961 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003962 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003963 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003964
Douglas Gregor42cafa82010-12-20 17:42:22 +00003965 Outputs.addArgument(Out);
3966 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003967
Douglas Gregor42cafa82010-12-20 17:42:22 +00003968 return false;
3969
3970}
3971
Douglas Gregord6ff3322009-08-04 16:50:30 +00003972//===----------------------------------------------------------------------===//
3973// Type transformation
3974//===----------------------------------------------------------------------===//
3975
3976template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003977QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003978 if (getDerived().AlreadyTransformed(T))
3979 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003980
John McCall550e0c22009-10-21 00:40:46 +00003981 // Temporary workaround. All of these transformations should
3982 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003983 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3984 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003985
John McCall31f82722010-11-12 08:19:04 +00003986 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003987
John McCall550e0c22009-10-21 00:40:46 +00003988 if (!NewDI)
3989 return QualType();
3990
3991 return NewDI->getType();
3992}
3993
3994template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003995TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003996 // Refine the base location to the type's location.
3997 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3998 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003999 if (getDerived().AlreadyTransformed(DI->getType()))
4000 return DI;
4001
4002 TypeLocBuilder TLB;
4003
4004 TypeLoc TL = DI->getTypeLoc();
4005 TLB.reserve(TL.getFullDataSize());
4006
John McCall31f82722010-11-12 08:19:04 +00004007 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004008 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004009 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004010
John McCallbcd03502009-12-07 02:54:59 +00004011 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004012}
4013
4014template<typename Derived>
4015QualType
John McCall31f82722010-11-12 08:19:04 +00004016TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004017 switch (T.getTypeLocClass()) {
4018#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004019#define TYPELOC(CLASS, PARENT) \
4020 case TypeLoc::CLASS: \
4021 return getDerived().Transform##CLASS##Type(TLB, \
4022 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004023#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004024 }
Mike Stump11289f42009-09-09 15:08:12 +00004025
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004026 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004027}
4028
4029/// FIXME: By default, this routine adds type qualifiers only to types
4030/// that can have qualifiers, and silently suppresses those qualifiers
4031/// that are not permitted (e.g., qualifiers on reference or function
4032/// types). This is the right thing for template instantiation, but
4033/// probably not for other clients.
4034template<typename Derived>
4035QualType
4036TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004037 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004038 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004039
John McCall31f82722010-11-12 08:19:04 +00004040 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004041 if (Result.isNull())
4042 return QualType();
4043
4044 // Silently suppress qualifiers if the result type can't be qualified.
4045 // FIXME: this is the right thing for template instantiation, but
4046 // probably not for other clients.
4047 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004048 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004049
John McCall31168b02011-06-15 23:02:42 +00004050 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004051 // resulting type.
4052 if (Quals.hasObjCLifetime()) {
4053 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4054 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004055 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004056 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004057 // A lifetime qualifier applied to a substituted template parameter
4058 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004059 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004060 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004061 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4062 QualType Replacement = SubstTypeParam->getReplacementType();
4063 Qualifiers Qs = Replacement.getQualifiers();
4064 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004065 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004066 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4067 Qs);
4068 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004069 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004070 Replacement);
4071 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004072 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4073 // 'auto' types behave the same way as template parameters.
4074 QualType Deduced = AutoTy->getDeducedType();
4075 Qualifiers Qs = Deduced.getQualifiers();
4076 Qs.removeObjCLifetime();
4077 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4078 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004079 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004080 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004081 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004082 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004083 // Otherwise, complain about the addition of a qualifier to an
4084 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004085 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004086 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004087 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004088
Douglas Gregore46db902011-06-17 22:11:49 +00004089 Quals.removeObjCLifetime();
4090 }
4091 }
4092 }
John McCallcb0f89a2010-06-05 06:41:15 +00004093 if (!Quals.empty()) {
4094 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004095 // BuildQualifiedType might not add qualifiers if they are invalid.
4096 if (Result.hasLocalQualifiers())
4097 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004098 // No location information to preserve.
4099 }
John McCall550e0c22009-10-21 00:40:46 +00004100
4101 return Result;
4102}
4103
Douglas Gregor14454802011-02-25 02:25:35 +00004104template<typename Derived>
4105TypeLoc
4106TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4107 QualType ObjectType,
4108 NamedDecl *UnqualLookup,
4109 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004110 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004111 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004112
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004113 TypeSourceInfo *TSI =
4114 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4115 if (TSI)
4116 return TSI->getTypeLoc();
4117 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004118}
4119
Douglas Gregor579c15f2011-03-02 18:32:08 +00004120template<typename Derived>
4121TypeSourceInfo *
4122TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4123 QualType ObjectType,
4124 NamedDecl *UnqualLookup,
4125 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004126 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004127 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004128
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004129 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4130 UnqualLookup, SS);
4131}
4132
4133template <typename Derived>
4134TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4135 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4136 CXXScopeSpec &SS) {
4137 QualType T = TL.getType();
4138 assert(!getDerived().AlreadyTransformed(T));
4139
Douglas Gregor579c15f2011-03-02 18:32:08 +00004140 TypeLocBuilder TLB;
4141 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004142
Douglas Gregor579c15f2011-03-02 18:32:08 +00004143 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004144 TemplateSpecializationTypeLoc SpecTL =
4145 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004146
Douglas Gregor579c15f2011-03-02 18:32:08 +00004147 TemplateName Template
4148 = getDerived().TransformTemplateName(SS,
4149 SpecTL.getTypePtr()->getTemplateName(),
4150 SpecTL.getTemplateNameLoc(),
4151 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004152 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004153 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004154
4155 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004156 Template);
4157 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004158 DependentTemplateSpecializationTypeLoc SpecTL =
4159 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004160
Douglas Gregor579c15f2011-03-02 18:32:08 +00004161 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004162 = getDerived().RebuildTemplateName(SS,
4163 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004164 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004165 ObjectType, UnqualLookup);
4166 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004167 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004168
4169 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004170 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004171 Template,
4172 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004173 } else {
4174 // Nothing special needs to be done for these.
4175 Result = getDerived().TransformType(TLB, TL);
4176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004177
4178 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004179 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004180
Douglas Gregor579c15f2011-03-02 18:32:08 +00004181 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4182}
4183
John McCall550e0c22009-10-21 00:40:46 +00004184template <class TyLoc> static inline
4185QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4186 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4187 NewT.setNameLoc(T.getNameLoc());
4188 return T.getType();
4189}
4190
John McCall550e0c22009-10-21 00:40:46 +00004191template<typename Derived>
4192QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004193 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004194 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4195 NewT.setBuiltinLoc(T.getBuiltinLoc());
4196 if (T.needsExtraLocalData())
4197 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4198 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004199}
Mike Stump11289f42009-09-09 15:08:12 +00004200
Douglas Gregord6ff3322009-08-04 16:50:30 +00004201template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004202QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004203 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004204 // FIXME: recurse?
4205 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206}
Mike Stump11289f42009-09-09 15:08:12 +00004207
Reid Kleckner0503a872013-12-05 01:23:43 +00004208template <typename Derived>
4209QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4210 AdjustedTypeLoc TL) {
4211 // Adjustments applied during transformation are handled elsewhere.
4212 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4213}
4214
Douglas Gregord6ff3322009-08-04 16:50:30 +00004215template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004216QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4217 DecayedTypeLoc TL) {
4218 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4219 if (OriginalType.isNull())
4220 return QualType();
4221
4222 QualType Result = TL.getType();
4223 if (getDerived().AlwaysRebuild() ||
4224 OriginalType != TL.getOriginalLoc().getType())
4225 Result = SemaRef.Context.getDecayedType(OriginalType);
4226 TLB.push<DecayedTypeLoc>(Result);
4227 // Nothing to set for DecayedTypeLoc.
4228 return Result;
4229}
4230
4231template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004232QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004233 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004234 QualType PointeeType
4235 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004236 if (PointeeType.isNull())
4237 return QualType();
4238
4239 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004240 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004241 // A dependent pointer type 'T *' has is being transformed such
4242 // that an Objective-C class type is being replaced for 'T'. The
4243 // resulting pointer type is an ObjCObjectPointerType, not a
4244 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004245 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004246
John McCall8b07ec22010-05-15 11:32:37 +00004247 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4248 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004249 return Result;
4250 }
John McCall31f82722010-11-12 08:19:04 +00004251
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004252 if (getDerived().AlwaysRebuild() ||
4253 PointeeType != TL.getPointeeLoc().getType()) {
4254 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4255 if (Result.isNull())
4256 return QualType();
4257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004258
John McCall31168b02011-06-15 23:02:42 +00004259 // Objective-C ARC can add lifetime qualifiers to the type that we're
4260 // pointing to.
4261 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004262
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004263 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4264 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004265 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004266}
Mike Stump11289f42009-09-09 15:08:12 +00004267
4268template<typename Derived>
4269QualType
John McCall550e0c22009-10-21 00:40:46 +00004270TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004271 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004272 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004273 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4274 if (PointeeType.isNull())
4275 return QualType();
4276
4277 QualType Result = TL.getType();
4278 if (getDerived().AlwaysRebuild() ||
4279 PointeeType != TL.getPointeeLoc().getType()) {
4280 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004281 TL.getSigilLoc());
4282 if (Result.isNull())
4283 return QualType();
4284 }
4285
Douglas Gregor049211a2010-04-22 16:50:51 +00004286 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004287 NewT.setSigilLoc(TL.getSigilLoc());
4288 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004289}
4290
John McCall70dd5f62009-10-30 00:06:24 +00004291/// Transforms a reference type. Note that somewhat paradoxically we
4292/// don't care whether the type itself is an l-value type or an r-value
4293/// type; we only care if the type was *written* as an l-value type
4294/// or an r-value type.
4295template<typename Derived>
4296QualType
4297TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004298 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004299 const ReferenceType *T = TL.getTypePtr();
4300
4301 // Note that this works with the pointee-as-written.
4302 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4303 if (PointeeType.isNull())
4304 return QualType();
4305
4306 QualType Result = TL.getType();
4307 if (getDerived().AlwaysRebuild() ||
4308 PointeeType != T->getPointeeTypeAsWritten()) {
4309 Result = getDerived().RebuildReferenceType(PointeeType,
4310 T->isSpelledAsLValue(),
4311 TL.getSigilLoc());
4312 if (Result.isNull())
4313 return QualType();
4314 }
4315
John McCall31168b02011-06-15 23:02:42 +00004316 // Objective-C ARC can add lifetime qualifiers to the type that we're
4317 // referring to.
4318 TLB.TypeWasModifiedSafely(
4319 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4320
John McCall70dd5f62009-10-30 00:06:24 +00004321 // r-value references can be rebuilt as l-value references.
4322 ReferenceTypeLoc NewTL;
4323 if (isa<LValueReferenceType>(Result))
4324 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4325 else
4326 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4327 NewTL.setSigilLoc(TL.getSigilLoc());
4328
4329 return Result;
4330}
4331
Mike Stump11289f42009-09-09 15:08:12 +00004332template<typename Derived>
4333QualType
John McCall550e0c22009-10-21 00:40:46 +00004334TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004335 LValueReferenceTypeLoc TL) {
4336 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004337}
4338
Mike Stump11289f42009-09-09 15:08:12 +00004339template<typename Derived>
4340QualType
John McCall550e0c22009-10-21 00:40:46 +00004341TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004342 RValueReferenceTypeLoc TL) {
4343 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004344}
Mike Stump11289f42009-09-09 15:08:12 +00004345
Douglas Gregord6ff3322009-08-04 16:50:30 +00004346template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004347QualType
John McCall550e0c22009-10-21 00:40:46 +00004348TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004349 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004350 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004351 if (PointeeType.isNull())
4352 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004353
Abramo Bagnara509357842011-03-05 14:42:21 +00004354 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004355 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004356 if (OldClsTInfo) {
4357 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4358 if (!NewClsTInfo)
4359 return QualType();
4360 }
4361
4362 const MemberPointerType *T = TL.getTypePtr();
4363 QualType OldClsType = QualType(T->getClass(), 0);
4364 QualType NewClsType;
4365 if (NewClsTInfo)
4366 NewClsType = NewClsTInfo->getType();
4367 else {
4368 NewClsType = getDerived().TransformType(OldClsType);
4369 if (NewClsType.isNull())
4370 return QualType();
4371 }
Mike Stump11289f42009-09-09 15:08:12 +00004372
John McCall550e0c22009-10-21 00:40:46 +00004373 QualType Result = TL.getType();
4374 if (getDerived().AlwaysRebuild() ||
4375 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004376 NewClsType != OldClsType) {
4377 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004378 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004379 if (Result.isNull())
4380 return QualType();
4381 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004382
Reid Kleckner0503a872013-12-05 01:23:43 +00004383 // If we had to adjust the pointee type when building a member pointer, make
4384 // sure to push TypeLoc info for it.
4385 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4386 if (MPT && PointeeType != MPT->getPointeeType()) {
4387 assert(isa<AdjustedType>(MPT->getPointeeType()));
4388 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4389 }
4390
John McCall550e0c22009-10-21 00:40:46 +00004391 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4392 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004393 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004394
4395 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004396}
4397
Mike Stump11289f42009-09-09 15:08:12 +00004398template<typename Derived>
4399QualType
John McCall550e0c22009-10-21 00:40:46 +00004400TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004401 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004402 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004403 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004404 if (ElementType.isNull())
4405 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004406
John McCall550e0c22009-10-21 00:40:46 +00004407 QualType Result = TL.getType();
4408 if (getDerived().AlwaysRebuild() ||
4409 ElementType != T->getElementType()) {
4410 Result = getDerived().RebuildConstantArrayType(ElementType,
4411 T->getSizeModifier(),
4412 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004413 T->getIndexTypeCVRQualifiers(),
4414 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004415 if (Result.isNull())
4416 return QualType();
4417 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004418
4419 // We might have either a ConstantArrayType or a VariableArrayType now:
4420 // a ConstantArrayType is allowed to have an element type which is a
4421 // VariableArrayType if the type is dependent. Fortunately, all array
4422 // types have the same location layout.
4423 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004424 NewTL.setLBracketLoc(TL.getLBracketLoc());
4425 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004426
John McCall550e0c22009-10-21 00:40:46 +00004427 Expr *Size = TL.getSizeExpr();
4428 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004429 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4430 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004431 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4432 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004433 }
4434 NewTL.setSizeExpr(Size);
4435
4436 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004437}
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregord6ff3322009-08-04 16:50:30 +00004439template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004440QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004441 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004442 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004443 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004444 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004445 if (ElementType.isNull())
4446 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004447
John McCall550e0c22009-10-21 00:40:46 +00004448 QualType Result = TL.getType();
4449 if (getDerived().AlwaysRebuild() ||
4450 ElementType != T->getElementType()) {
4451 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004452 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004453 T->getIndexTypeCVRQualifiers(),
4454 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004455 if (Result.isNull())
4456 return QualType();
4457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004458
John McCall550e0c22009-10-21 00:40:46 +00004459 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4460 NewTL.setLBracketLoc(TL.getLBracketLoc());
4461 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004462 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004463
4464 return Result;
4465}
4466
4467template<typename Derived>
4468QualType
4469TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004470 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004471 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004472 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4473 if (ElementType.isNull())
4474 return QualType();
4475
John McCalldadc5752010-08-24 06:29:42 +00004476 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004477 = getDerived().TransformExpr(T->getSizeExpr());
4478 if (SizeResult.isInvalid())
4479 return QualType();
4480
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004481 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004482
4483 QualType Result = TL.getType();
4484 if (getDerived().AlwaysRebuild() ||
4485 ElementType != T->getElementType() ||
4486 Size != T->getSizeExpr()) {
4487 Result = getDerived().RebuildVariableArrayType(ElementType,
4488 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004489 Size,
John McCall550e0c22009-10-21 00:40:46 +00004490 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004491 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004492 if (Result.isNull())
4493 return QualType();
4494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004495
Serge Pavlov774c6d02014-02-06 03:49:11 +00004496 // We might have constant size array now, but fortunately it has the same
4497 // location layout.
4498 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004499 NewTL.setLBracketLoc(TL.getLBracketLoc());
4500 NewTL.setRBracketLoc(TL.getRBracketLoc());
4501 NewTL.setSizeExpr(Size);
4502
4503 return Result;
4504}
4505
4506template<typename Derived>
4507QualType
4508TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004509 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004510 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004511 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4512 if (ElementType.isNull())
4513 return QualType();
4514
Richard Smith764d2fe2011-12-20 02:08:33 +00004515 // Array bounds are constant expressions.
4516 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4517 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004518
John McCall33ddac02011-01-19 10:06:00 +00004519 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4520 Expr *origSize = TL.getSizeExpr();
4521 if (!origSize) origSize = T->getSizeExpr();
4522
4523 ExprResult sizeResult
4524 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004525 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004526 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004527 return QualType();
4528
John McCall33ddac02011-01-19 10:06:00 +00004529 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004530
4531 QualType Result = TL.getType();
4532 if (getDerived().AlwaysRebuild() ||
4533 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004534 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004535 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4536 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004537 size,
John McCall550e0c22009-10-21 00:40:46 +00004538 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004539 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004540 if (Result.isNull())
4541 return QualType();
4542 }
John McCall550e0c22009-10-21 00:40:46 +00004543
4544 // We might have any sort of array type now, but fortunately they
4545 // all have the same location layout.
4546 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4547 NewTL.setLBracketLoc(TL.getLBracketLoc());
4548 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004549 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004550
4551 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004552}
Mike Stump11289f42009-09-09 15:08:12 +00004553
4554template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004555QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004556 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004557 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004558 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004559
4560 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004561 QualType ElementType = getDerived().TransformType(T->getElementType());
4562 if (ElementType.isNull())
4563 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004564
Richard Smith764d2fe2011-12-20 02:08:33 +00004565 // Vector sizes are constant expressions.
4566 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4567 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004568
John McCalldadc5752010-08-24 06:29:42 +00004569 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004570 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004571 if (Size.isInvalid())
4572 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004573
John McCall550e0c22009-10-21 00:40:46 +00004574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004576 ElementType != T->getElementType() ||
4577 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004578 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004579 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004580 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004581 if (Result.isNull())
4582 return QualType();
4583 }
John McCall550e0c22009-10-21 00:40:46 +00004584
4585 // Result might be dependent or not.
4586 if (isa<DependentSizedExtVectorType>(Result)) {
4587 DependentSizedExtVectorTypeLoc NewTL
4588 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4589 NewTL.setNameLoc(TL.getNameLoc());
4590 } else {
4591 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4592 NewTL.setNameLoc(TL.getNameLoc());
4593 }
4594
4595 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004596}
Mike Stump11289f42009-09-09 15:08:12 +00004597
4598template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004599QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004600 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004601 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004602 QualType ElementType = getDerived().TransformType(T->getElementType());
4603 if (ElementType.isNull())
4604 return QualType();
4605
John McCall550e0c22009-10-21 00:40:46 +00004606 QualType Result = TL.getType();
4607 if (getDerived().AlwaysRebuild() ||
4608 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004609 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004610 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004611 if (Result.isNull())
4612 return QualType();
4613 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004614
John McCall550e0c22009-10-21 00:40:46 +00004615 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4616 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004617
John McCall550e0c22009-10-21 00:40:46 +00004618 return Result;
4619}
4620
4621template<typename Derived>
4622QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004623 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004624 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004625 QualType ElementType = getDerived().TransformType(T->getElementType());
4626 if (ElementType.isNull())
4627 return QualType();
4628
4629 QualType Result = TL.getType();
4630 if (getDerived().AlwaysRebuild() ||
4631 ElementType != T->getElementType()) {
4632 Result = getDerived().RebuildExtVectorType(ElementType,
4633 T->getNumElements(),
4634 /*FIXME*/ SourceLocation());
4635 if (Result.isNull())
4636 return QualType();
4637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004638
John McCall550e0c22009-10-21 00:40:46 +00004639 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4640 NewTL.setNameLoc(TL.getNameLoc());
4641
4642 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004643}
Mike Stump11289f42009-09-09 15:08:12 +00004644
David Blaikie05785d12013-02-20 22:23:23 +00004645template <typename Derived>
4646ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4647 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4648 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004649 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004650 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004651
Douglas Gregor715e4612011-01-14 22:40:04 +00004652 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004653 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004654 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004655 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004656 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004657
Douglas Gregor715e4612011-01-14 22:40:04 +00004658 TypeLocBuilder TLB;
4659 TypeLoc NewTL = OldDI->getTypeLoc();
4660 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004661
4662 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004663 OldExpansionTL.getPatternLoc());
4664 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004665 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004666
4667 Result = RebuildPackExpansionType(Result,
4668 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004669 OldExpansionTL.getEllipsisLoc(),
4670 NumExpansions);
4671 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004672 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004673
Douglas Gregor715e4612011-01-14 22:40:04 +00004674 PackExpansionTypeLoc NewExpansionTL
4675 = TLB.push<PackExpansionTypeLoc>(Result);
4676 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4677 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4678 } else
4679 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004680 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004681 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004682
John McCall8fb0d9d2011-05-01 22:35:37 +00004683 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004684 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004685
4686 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4687 OldParm->getDeclContext(),
4688 OldParm->getInnerLocStart(),
4689 OldParm->getLocation(),
4690 OldParm->getIdentifier(),
4691 NewDI->getType(),
4692 NewDI,
4693 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004694 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004695 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4696 OldParm->getFunctionScopeIndex() + indexAdjustment);
4697 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004698}
4699
David Majnemer59f77922016-06-24 04:05:48 +00004700template <typename Derived>
4701bool TreeTransform<Derived>::TransformFunctionTypeParams(
4702 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4703 const QualType *ParamTypes,
4704 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4705 SmallVectorImpl<QualType> &OutParamTypes,
4706 SmallVectorImpl<ParmVarDecl *> *PVars,
4707 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004708 int indexAdjustment = 0;
4709
David Majnemer59f77922016-06-24 04:05:48 +00004710 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004711 for (unsigned i = 0; i != NumParams; ++i) {
4712 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004713 assert(OldParm->getFunctionScopeIndex() == i);
4714
David Blaikie05785d12013-02-20 22:23:23 +00004715 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004716 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004717 if (OldParm->isParameterPack()) {
4718 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004719 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004720
Douglas Gregor5499af42011-01-05 23:12:31 +00004721 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004722 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004723 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004724 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4725 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004726 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4727
Douglas Gregor5499af42011-01-05 23:12:31 +00004728 // Determine whether we should expand the parameter packs.
4729 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004730 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004731 Optional<unsigned> OrigNumExpansions =
4732 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004733 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004734 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4735 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004736 Unexpanded,
4737 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004738 RetainExpansion,
4739 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004740 return true;
4741 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004742
Douglas Gregor5499af42011-01-05 23:12:31 +00004743 if (ShouldExpand) {
4744 // Expand the function parameter pack into multiple, separate
4745 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004746 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004747 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004748 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004749 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004750 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004751 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004752 OrigNumExpansions,
4753 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004754 if (!NewParm)
4755 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004756
John McCallc8e321d2016-03-01 02:09:25 +00004757 if (ParamInfos)
4758 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004759 OutParamTypes.push_back(NewParm->getType());
4760 if (PVars)
4761 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004762 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004763
4764 // If we're supposed to retain a pack expansion, do so by temporarily
4765 // forgetting the partially-substituted parameter pack.
4766 if (RetainExpansion) {
4767 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004768 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004769 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004770 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004771 OrigNumExpansions,
4772 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004773 if (!NewParm)
4774 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004775
John McCallc8e321d2016-03-01 02:09:25 +00004776 if (ParamInfos)
4777 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004778 OutParamTypes.push_back(NewParm->getType());
4779 if (PVars)
4780 PVars->push_back(NewParm);
4781 }
4782
John McCall8fb0d9d2011-05-01 22:35:37 +00004783 // The next parameter should have the same adjustment as the
4784 // last thing we pushed, but we post-incremented indexAdjustment
4785 // on every push. Also, if we push nothing, the adjustment should
4786 // go down by one.
4787 indexAdjustment--;
4788
Douglas Gregor5499af42011-01-05 23:12:31 +00004789 // We're done with the pack expansion.
4790 continue;
4791 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004792
4793 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004794 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004795 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4796 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004797 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004798 NumExpansions,
4799 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004800 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004801 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004802 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004803 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004804
John McCall58f10c32010-03-11 09:03:00 +00004805 if (!NewParm)
4806 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004807
John McCallc8e321d2016-03-01 02:09:25 +00004808 if (ParamInfos)
4809 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004810 OutParamTypes.push_back(NewParm->getType());
4811 if (PVars)
4812 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004813 continue;
4814 }
John McCall58f10c32010-03-11 09:03:00 +00004815
4816 // Deal with the possibility that we don't have a parameter
4817 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004818 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004819 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004820 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004821 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004822 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004823 = dyn_cast<PackExpansionType>(OldType)) {
4824 // We have a function parameter pack that may need to be expanded.
4825 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004826 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004827 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004828
Douglas Gregor5499af42011-01-05 23:12:31 +00004829 // Determine whether we should expand the parameter packs.
4830 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004831 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004832 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004833 Unexpanded,
4834 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004835 RetainExpansion,
4836 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004837 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004839
Douglas Gregor5499af42011-01-05 23:12:31 +00004840 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004841 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004842 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004843 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004844 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4845 QualType NewType = getDerived().TransformType(Pattern);
4846 if (NewType.isNull())
4847 return true;
John McCall58f10c32010-03-11 09:03:00 +00004848
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00004849 if (NewType->containsUnexpandedParameterPack()) {
4850 NewType =
4851 getSema().getASTContext().getPackExpansionType(NewType, None);
4852
4853 if (NewType.isNull())
4854 return true;
4855 }
4856
John McCallc8e321d2016-03-01 02:09:25 +00004857 if (ParamInfos)
4858 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004859 OutParamTypes.push_back(NewType);
4860 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004861 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004863
Douglas Gregor5499af42011-01-05 23:12:31 +00004864 // We're done with the pack expansion.
4865 continue;
4866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004867
Douglas Gregor48d24112011-01-10 20:53:55 +00004868 // If we're supposed to retain a pack expansion, do so by temporarily
4869 // forgetting the partially-substituted parameter pack.
4870 if (RetainExpansion) {
4871 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4872 QualType NewType = getDerived().TransformType(Pattern);
4873 if (NewType.isNull())
4874 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004875
John McCallc8e321d2016-03-01 02:09:25 +00004876 if (ParamInfos)
4877 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004878 OutParamTypes.push_back(NewType);
4879 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004880 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004881 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004882
Chad Rosier1dcde962012-08-08 18:46:20 +00004883 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004884 // expansion.
4885 OldType = Expansion->getPattern();
4886 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004887 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4888 NewType = getDerived().TransformType(OldType);
4889 } else {
4890 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004892
Douglas Gregor5499af42011-01-05 23:12:31 +00004893 if (NewType.isNull())
4894 return true;
4895
4896 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004897 NewType = getSema().Context.getPackExpansionType(NewType,
4898 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004899
John McCallc8e321d2016-03-01 02:09:25 +00004900 if (ParamInfos)
4901 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004902 OutParamTypes.push_back(NewType);
4903 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004904 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004905 }
4906
John McCall8fb0d9d2011-05-01 22:35:37 +00004907#ifndef NDEBUG
4908 if (PVars) {
4909 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4910 if (ParmVarDecl *parm = (*PVars)[i])
4911 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004912 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004913#endif
4914
4915 return false;
4916}
John McCall58f10c32010-03-11 09:03:00 +00004917
4918template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004919QualType
John McCall550e0c22009-10-21 00:40:46 +00004920TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004921 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004922 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004923 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004924 return getDerived().TransformFunctionProtoType(
4925 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004926 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4927 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4928 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004929 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004930}
4931
Richard Smith2e321552014-11-12 02:00:47 +00004932template<typename Derived> template<typename Fn>
4933QualType TreeTransform<Derived>::TransformFunctionProtoType(
4934 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4935 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004936
Douglas Gregor4afc2362010-08-31 00:26:14 +00004937 // Transform the parameters and return type.
4938 //
Richard Smithf623c962012-04-17 00:58:00 +00004939 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004940 // When the function has a trailing return type, we instantiate the
4941 // parameters before the return type, since the return type can then refer
4942 // to the parameters themselves (via decltype, sizeof, etc.).
4943 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004944 SmallVector<QualType, 4> ParamTypes;
4945 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004946 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004947 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004948
Douglas Gregor7fb25412010-10-01 18:44:50 +00004949 QualType ResultType;
4950
Richard Smith1226c602012-08-14 22:51:13 +00004951 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004952 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004953 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004954 TL.getTypePtr()->param_type_begin(),
4955 T->getExtParameterInfosOrNull(),
4956 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004957 return QualType();
4958
Douglas Gregor3024f072012-04-16 07:05:22 +00004959 {
4960 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004961 // If a declaration declares a member function or member function
4962 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004963 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004964 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004965 // declarator.
4966 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004967
Alp Toker42a16a62014-01-25 23:51:36 +00004968 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004969 if (ResultType.isNull())
4970 return QualType();
4971 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004972 }
4973 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004974 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004975 if (ResultType.isNull())
4976 return QualType();
4977
Alp Toker9cacbab2014-01-20 20:26:09 +00004978 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004979 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004980 TL.getTypePtr()->param_type_begin(),
4981 T->getExtParameterInfosOrNull(),
4982 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004983 return QualType();
4984 }
4985
Richard Smith2e321552014-11-12 02:00:47 +00004986 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4987
4988 bool EPIChanged = false;
4989 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4990 return QualType();
4991
John McCallc8e321d2016-03-01 02:09:25 +00004992 // Handle extended parameter information.
4993 if (auto NewExtParamInfos =
4994 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4995 if (!EPI.ExtParameterInfos ||
4996 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4997 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4998 EPIChanged = true;
4999 }
5000 EPI.ExtParameterInfos = NewExtParamInfos;
5001 } else if (EPI.ExtParameterInfos) {
5002 EPIChanged = true;
5003 EPI.ExtParameterInfos = nullptr;
5004 }
Richard Smithf623c962012-04-17 00:58:00 +00005005
John McCall550e0c22009-10-21 00:40:46 +00005006 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005007 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005008 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005009 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005010 if (Result.isNull())
5011 return QualType();
5012 }
Mike Stump11289f42009-09-09 15:08:12 +00005013
John McCall550e0c22009-10-21 00:40:46 +00005014 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005015 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005016 NewTL.setLParenLoc(TL.getLParenLoc());
5017 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005018 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005019 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5020 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005021
5022 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005023}
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregord6ff3322009-08-04 16:50:30 +00005025template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005026bool TreeTransform<Derived>::TransformExceptionSpec(
5027 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5028 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5029 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5030
5031 // Instantiate a dynamic noexcept expression, if any.
5032 if (ESI.Type == EST_ComputedNoexcept) {
5033 EnterExpressionEvaluationContext Unevaluated(getSema(),
5034 Sema::ConstantEvaluated);
5035 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5036 if (NoexceptExpr.isInvalid())
5037 return true;
5038
Richard Smith03a4aa32016-06-23 19:02:52 +00005039 // FIXME: This is bogus, a noexcept expression is not a condition.
5040 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005041 if (NoexceptExpr.isInvalid())
5042 return true;
5043
5044 if (!NoexceptExpr.get()->isValueDependent()) {
5045 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5046 NoexceptExpr.get(), nullptr,
5047 diag::err_noexcept_needs_constant_expression,
5048 /*AllowFold*/false);
5049 if (NoexceptExpr.isInvalid())
5050 return true;
5051 }
5052
5053 if (ESI.NoexceptExpr != NoexceptExpr.get())
5054 Changed = true;
5055 ESI.NoexceptExpr = NoexceptExpr.get();
5056 }
5057
5058 if (ESI.Type != EST_Dynamic)
5059 return false;
5060
5061 // Instantiate a dynamic exception specification's type.
5062 for (QualType T : ESI.Exceptions) {
5063 if (const PackExpansionType *PackExpansion =
5064 T->getAs<PackExpansionType>()) {
5065 Changed = true;
5066
5067 // We have a pack expansion. Instantiate it.
5068 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5069 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5070 Unexpanded);
5071 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5072
5073 // Determine whether the set of unexpanded parameter packs can and
5074 // should
5075 // be expanded.
5076 bool Expand = false;
5077 bool RetainExpansion = false;
5078 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5079 // FIXME: Track the location of the ellipsis (and track source location
5080 // information for the types in the exception specification in general).
5081 if (getDerived().TryExpandParameterPacks(
5082 Loc, SourceRange(), Unexpanded, Expand,
5083 RetainExpansion, NumExpansions))
5084 return true;
5085
5086 if (!Expand) {
5087 // We can't expand this pack expansion into separate arguments yet;
5088 // just substitute into the pattern and create a new pack expansion
5089 // type.
5090 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5091 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5092 if (U.isNull())
5093 return true;
5094
5095 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5096 Exceptions.push_back(U);
5097 continue;
5098 }
5099
5100 // Substitute into the pack expansion pattern for each slice of the
5101 // pack.
5102 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5103 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5104
5105 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5106 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5107 return true;
5108
5109 Exceptions.push_back(U);
5110 }
5111 } else {
5112 QualType U = getDerived().TransformType(T);
5113 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5114 return true;
5115 if (T != U)
5116 Changed = true;
5117
5118 Exceptions.push_back(U);
5119 }
5120 }
5121
5122 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005123 if (ESI.Exceptions.empty())
5124 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005125 return false;
5126}
5127
5128template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005129QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005130 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005131 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005132 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005133 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005134 if (ResultType.isNull())
5135 return QualType();
5136
5137 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005138 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005139 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5140
5141 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005142 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005143 NewTL.setLParenLoc(TL.getLParenLoc());
5144 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005145 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005146
5147 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005148}
Mike Stump11289f42009-09-09 15:08:12 +00005149
John McCallb96ec562009-12-04 22:46:56 +00005150template<typename Derived> QualType
5151TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005152 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005153 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005154 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005155 if (!D)
5156 return QualType();
5157
5158 QualType Result = TL.getType();
5159 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5160 Result = getDerived().RebuildUnresolvedUsingType(D);
5161 if (Result.isNull())
5162 return QualType();
5163 }
5164
5165 // We might get an arbitrary type spec type back. We should at
5166 // least always get a type spec type, though.
5167 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5168 NewTL.setNameLoc(TL.getNameLoc());
5169
5170 return Result;
5171}
5172
Douglas Gregord6ff3322009-08-04 16:50:30 +00005173template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005174QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005175 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005176 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005177 TypedefNameDecl *Typedef
5178 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5179 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005180 if (!Typedef)
5181 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005182
John McCall550e0c22009-10-21 00:40:46 +00005183 QualType Result = TL.getType();
5184 if (getDerived().AlwaysRebuild() ||
5185 Typedef != T->getDecl()) {
5186 Result = getDerived().RebuildTypedefType(Typedef);
5187 if (Result.isNull())
5188 return QualType();
5189 }
Mike Stump11289f42009-09-09 15:08:12 +00005190
John McCall550e0c22009-10-21 00:40:46 +00005191 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5192 NewTL.setNameLoc(TL.getNameLoc());
5193
5194 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005195}
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregord6ff3322009-08-04 16:50:30 +00005197template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005198QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005199 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005200 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005201 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5202 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005203
John McCalldadc5752010-08-24 06:29:42 +00005204 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005205 if (E.isInvalid())
5206 return QualType();
5207
Eli Friedmane4f22df2012-02-29 04:03:55 +00005208 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5209 if (E.isInvalid())
5210 return QualType();
5211
John McCall550e0c22009-10-21 00:40:46 +00005212 QualType Result = TL.getType();
5213 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005214 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005215 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005216 if (Result.isNull())
5217 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005218 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005219 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005220
John McCall550e0c22009-10-21 00:40:46 +00005221 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005222 NewTL.setTypeofLoc(TL.getTypeofLoc());
5223 NewTL.setLParenLoc(TL.getLParenLoc());
5224 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005225
5226 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005227}
Mike Stump11289f42009-09-09 15:08:12 +00005228
5229template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005230QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005231 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005232 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5233 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5234 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005235 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005236
John McCall550e0c22009-10-21 00:40:46 +00005237 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005238 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5239 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005240 if (Result.isNull())
5241 return QualType();
5242 }
Mike Stump11289f42009-09-09 15:08:12 +00005243
John McCall550e0c22009-10-21 00:40:46 +00005244 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005245 NewTL.setTypeofLoc(TL.getTypeofLoc());
5246 NewTL.setLParenLoc(TL.getLParenLoc());
5247 NewTL.setRParenLoc(TL.getRParenLoc());
5248 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005249
5250 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005251}
Mike Stump11289f42009-09-09 15:08:12 +00005252
5253template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005254QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005255 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005256 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005257
Douglas Gregore922c772009-08-04 22:27:00 +00005258 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005259 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5260 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005261
John McCalldadc5752010-08-24 06:29:42 +00005262 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005263 if (E.isInvalid())
5264 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005265
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005266 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005267 if (E.isInvalid())
5268 return QualType();
5269
John McCall550e0c22009-10-21 00:40:46 +00005270 QualType Result = TL.getType();
5271 if (getDerived().AlwaysRebuild() ||
5272 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005273 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005274 if (Result.isNull())
5275 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005276 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005277 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005278
John McCall550e0c22009-10-21 00:40:46 +00005279 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5280 NewTL.setNameLoc(TL.getNameLoc());
5281
5282 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005283}
5284
5285template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005286QualType TreeTransform<Derived>::TransformUnaryTransformType(
5287 TypeLocBuilder &TLB,
5288 UnaryTransformTypeLoc TL) {
5289 QualType Result = TL.getType();
5290 if (Result->isDependentType()) {
5291 const UnaryTransformType *T = TL.getTypePtr();
5292 QualType NewBase =
5293 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5294 Result = getDerived().RebuildUnaryTransformType(NewBase,
5295 T->getUTTKind(),
5296 TL.getKWLoc());
5297 if (Result.isNull())
5298 return QualType();
5299 }
5300
5301 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5302 NewTL.setKWLoc(TL.getKWLoc());
5303 NewTL.setParensRange(TL.getParensRange());
5304 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5305 return Result;
5306}
5307
5308template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005309QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5310 AutoTypeLoc TL) {
5311 const AutoType *T = TL.getTypePtr();
5312 QualType OldDeduced = T->getDeducedType();
5313 QualType NewDeduced;
5314 if (!OldDeduced.isNull()) {
5315 NewDeduced = getDerived().TransformType(OldDeduced);
5316 if (NewDeduced.isNull())
5317 return QualType();
5318 }
5319
5320 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005321 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5322 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005323 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005324 if (Result.isNull())
5325 return QualType();
5326 }
5327
5328 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5329 NewTL.setNameLoc(TL.getNameLoc());
5330
5331 return Result;
5332}
5333
5334template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005335QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005336 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005337 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005338 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005339 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5340 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005341 if (!Record)
5342 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005343
John McCall550e0c22009-10-21 00:40:46 +00005344 QualType Result = TL.getType();
5345 if (getDerived().AlwaysRebuild() ||
5346 Record != T->getDecl()) {
5347 Result = getDerived().RebuildRecordType(Record);
5348 if (Result.isNull())
5349 return QualType();
5350 }
Mike Stump11289f42009-09-09 15:08:12 +00005351
John McCall550e0c22009-10-21 00:40:46 +00005352 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5353 NewTL.setNameLoc(TL.getNameLoc());
5354
5355 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005356}
Mike Stump11289f42009-09-09 15:08:12 +00005357
5358template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005359QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005360 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005361 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005362 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005363 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5364 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005365 if (!Enum)
5366 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005367
John McCall550e0c22009-10-21 00:40:46 +00005368 QualType Result = TL.getType();
5369 if (getDerived().AlwaysRebuild() ||
5370 Enum != T->getDecl()) {
5371 Result = getDerived().RebuildEnumType(Enum);
5372 if (Result.isNull())
5373 return QualType();
5374 }
Mike Stump11289f42009-09-09 15:08:12 +00005375
John McCall550e0c22009-10-21 00:40:46 +00005376 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5377 NewTL.setNameLoc(TL.getNameLoc());
5378
5379 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005380}
John McCallfcc33b02009-09-05 00:15:47 +00005381
John McCalle78aac42010-03-10 03:28:59 +00005382template<typename Derived>
5383QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5384 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005385 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005386 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5387 TL.getTypePtr()->getDecl());
5388 if (!D) return QualType();
5389
5390 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5391 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5392 return T;
5393}
5394
Douglas Gregord6ff3322009-08-04 16:50:30 +00005395template<typename Derived>
5396QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005397 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005398 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005399 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005400}
5401
Mike Stump11289f42009-09-09 15:08:12 +00005402template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005403QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005404 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005405 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005406 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005407
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005408 // Substitute into the replacement type, which itself might involve something
5409 // that needs to be transformed. This only tends to occur with default
5410 // template arguments of template template parameters.
5411 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5412 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5413 if (Replacement.isNull())
5414 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005415
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005416 // Always canonicalize the replacement type.
5417 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5418 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005419 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005420 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005421
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005422 // Propagate type-source information.
5423 SubstTemplateTypeParmTypeLoc NewTL
5424 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5425 NewTL.setNameLoc(TL.getNameLoc());
5426 return Result;
5427
John McCallcebee162009-10-18 09:09:24 +00005428}
5429
5430template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005431QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5432 TypeLocBuilder &TLB,
5433 SubstTemplateTypeParmPackTypeLoc TL) {
5434 return TransformTypeSpecType(TLB, TL);
5435}
5436
5437template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005438QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005439 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005440 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005441 const TemplateSpecializationType *T = TL.getTypePtr();
5442
Douglas Gregordf846d12011-03-02 18:46:51 +00005443 // The nested-name-specifier never matters in a TemplateSpecializationType,
5444 // because we can't have a dependent nested-name-specifier anyway.
5445 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005446 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005447 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5448 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005449 if (Template.isNull())
5450 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005451
John McCall31f82722010-11-12 08:19:04 +00005452 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5453}
5454
Eli Friedman0dfb8892011-10-06 23:00:33 +00005455template<typename Derived>
5456QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5457 AtomicTypeLoc TL) {
5458 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5459 if (ValueType.isNull())
5460 return QualType();
5461
5462 QualType Result = TL.getType();
5463 if (getDerived().AlwaysRebuild() ||
5464 ValueType != TL.getValueLoc().getType()) {
5465 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5466 if (Result.isNull())
5467 return QualType();
5468 }
5469
5470 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5471 NewTL.setKWLoc(TL.getKWLoc());
5472 NewTL.setLParenLoc(TL.getLParenLoc());
5473 NewTL.setRParenLoc(TL.getRParenLoc());
5474
5475 return Result;
5476}
5477
Xiuli Pan9c14e282016-01-09 12:53:17 +00005478template <typename Derived>
5479QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5480 PipeTypeLoc TL) {
5481 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5482 if (ValueType.isNull())
5483 return QualType();
5484
5485 QualType Result = TL.getType();
5486 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005487 const PipeType *PT = Result->getAs<PipeType>();
5488 bool isReadPipe = PT->isReadOnly();
5489 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005490 if (Result.isNull())
5491 return QualType();
5492 }
5493
5494 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5495 NewTL.setKWLoc(TL.getKWLoc());
5496
5497 return Result;
5498}
5499
Chad Rosier1dcde962012-08-08 18:46:20 +00005500 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005501 /// container that provides a \c getArgLoc() member function.
5502 ///
5503 /// This iterator is intended to be used with the iterator form of
5504 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5505 template<typename ArgLocContainer>
5506 class TemplateArgumentLocContainerIterator {
5507 ArgLocContainer *Container;
5508 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005509
Douglas Gregorfe921a72010-12-20 23:36:19 +00005510 public:
5511 typedef TemplateArgumentLoc value_type;
5512 typedef TemplateArgumentLoc reference;
5513 typedef int difference_type;
5514 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005515
Douglas Gregorfe921a72010-12-20 23:36:19 +00005516 class pointer {
5517 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005518
Douglas Gregorfe921a72010-12-20 23:36:19 +00005519 public:
5520 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005521
Douglas Gregorfe921a72010-12-20 23:36:19 +00005522 const TemplateArgumentLoc *operator->() const {
5523 return &Arg;
5524 }
5525 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005526
5527
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005528 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005529
Douglas Gregorfe921a72010-12-20 23:36:19 +00005530 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5531 unsigned Index)
5532 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005533
Douglas Gregorfe921a72010-12-20 23:36:19 +00005534 TemplateArgumentLocContainerIterator &operator++() {
5535 ++Index;
5536 return *this;
5537 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005538
Douglas Gregorfe921a72010-12-20 23:36:19 +00005539 TemplateArgumentLocContainerIterator operator++(int) {
5540 TemplateArgumentLocContainerIterator Old(*this);
5541 ++(*this);
5542 return Old;
5543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005544
Douglas Gregorfe921a72010-12-20 23:36:19 +00005545 TemplateArgumentLoc operator*() const {
5546 return Container->getArgLoc(Index);
5547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005548
Douglas Gregorfe921a72010-12-20 23:36:19 +00005549 pointer operator->() const {
5550 return pointer(Container->getArgLoc(Index));
5551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregorfe921a72010-12-20 23:36:19 +00005553 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005554 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005555 return X.Container == Y.Container && X.Index == Y.Index;
5556 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005557
Douglas Gregorfe921a72010-12-20 23:36:19 +00005558 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005559 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005560 return !(X == Y);
5561 }
5562 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005563
5564
John McCall31f82722010-11-12 08:19:04 +00005565template <typename Derived>
5566QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5567 TypeLocBuilder &TLB,
5568 TemplateSpecializationTypeLoc TL,
5569 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005570 TemplateArgumentListInfo NewTemplateArgs;
5571 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5572 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005573 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5574 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005575 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005576 ArgIterator(TL, TL.getNumArgs()),
5577 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005579
John McCall0ad16662009-10-29 08:12:44 +00005580 // FIXME: maybe don't rebuild if all the template arguments are the same.
5581
5582 QualType Result =
5583 getDerived().RebuildTemplateSpecializationType(Template,
5584 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005585 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005586
5587 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005588 // Specializations of template template parameters are represented as
5589 // TemplateSpecializationTypes, and substitution of type alias templates
5590 // within a dependent context can transform them into
5591 // DependentTemplateSpecializationTypes.
5592 if (isa<DependentTemplateSpecializationType>(Result)) {
5593 DependentTemplateSpecializationTypeLoc NewTL
5594 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005595 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005596 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005597 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005598 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005599 NewTL.setLAngleLoc(TL.getLAngleLoc());
5600 NewTL.setRAngleLoc(TL.getRAngleLoc());
5601 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5602 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5603 return Result;
5604 }
5605
John McCall0ad16662009-10-29 08:12:44 +00005606 TemplateSpecializationTypeLoc NewTL
5607 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005608 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005609 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5610 NewTL.setLAngleLoc(TL.getLAngleLoc());
5611 NewTL.setRAngleLoc(TL.getRAngleLoc());
5612 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5613 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005614 }
Mike Stump11289f42009-09-09 15:08:12 +00005615
John McCall0ad16662009-10-29 08:12:44 +00005616 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005617}
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregor5a064722011-02-28 17:23:35 +00005619template <typename Derived>
5620QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5621 TypeLocBuilder &TLB,
5622 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005623 TemplateName Template,
5624 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005625 TemplateArgumentListInfo NewTemplateArgs;
5626 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5627 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5628 typedef TemplateArgumentLocContainerIterator<
5629 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005630 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005631 ArgIterator(TL, TL.getNumArgs()),
5632 NewTemplateArgs))
5633 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005634
Douglas Gregor5a064722011-02-28 17:23:35 +00005635 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005636
Douglas Gregor5a064722011-02-28 17:23:35 +00005637 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5638 QualType Result
5639 = getSema().Context.getDependentTemplateSpecializationType(
5640 TL.getTypePtr()->getKeyword(),
5641 DTN->getQualifier(),
5642 DTN->getIdentifier(),
5643 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005644
Douglas Gregor5a064722011-02-28 17:23:35 +00005645 DependentTemplateSpecializationTypeLoc NewTL
5646 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005647 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005648 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005649 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005650 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005651 NewTL.setLAngleLoc(TL.getLAngleLoc());
5652 NewTL.setRAngleLoc(TL.getRAngleLoc());
5653 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5654 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5655 return Result;
5656 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005657
5658 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005659 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005660 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005661 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005662
Douglas Gregor5a064722011-02-28 17:23:35 +00005663 if (!Result.isNull()) {
5664 /// FIXME: Wrap this in an elaborated-type-specifier?
5665 TemplateSpecializationTypeLoc NewTL
5666 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005667 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005668 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005669 NewTL.setLAngleLoc(TL.getLAngleLoc());
5670 NewTL.setRAngleLoc(TL.getRAngleLoc());
5671 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5672 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5673 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005674
Douglas Gregor5a064722011-02-28 17:23:35 +00005675 return Result;
5676}
5677
Mike Stump11289f42009-09-09 15:08:12 +00005678template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005679QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005680TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005681 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005682 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005683
Douglas Gregor844cb502011-03-01 18:12:44 +00005684 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005685 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005686 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005687 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005688 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5689 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005690 return QualType();
5691 }
Mike Stump11289f42009-09-09 15:08:12 +00005692
John McCall31f82722010-11-12 08:19:04 +00005693 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5694 if (NamedT.isNull())
5695 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005696
Richard Smith3f1b5d02011-05-05 21:57:07 +00005697 // C++0x [dcl.type.elab]p2:
5698 // If the identifier resolves to a typedef-name or the simple-template-id
5699 // resolves to an alias template specialization, the
5700 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005701 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5702 if (const TemplateSpecializationType *TST =
5703 NamedT->getAs<TemplateSpecializationType>()) {
5704 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005705 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5706 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005707 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005708 diag::err_tag_reference_non_tag)
5709 << Sema::NTK_TypeAliasTemplate;
Richard Smith0c4a34b2011-05-14 15:04:18 +00005710 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5711 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005712 }
5713 }
5714
John McCall550e0c22009-10-21 00:40:46 +00005715 QualType Result = TL.getType();
5716 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005717 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005718 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005719 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005720 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005721 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005722 if (Result.isNull())
5723 return QualType();
5724 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005725
Abramo Bagnara6150c882010-05-11 21:36:43 +00005726 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005727 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005728 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005729 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005730}
Mike Stump11289f42009-09-09 15:08:12 +00005731
5732template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005733QualType TreeTransform<Derived>::TransformAttributedType(
5734 TypeLocBuilder &TLB,
5735 AttributedTypeLoc TL) {
5736 const AttributedType *oldType = TL.getTypePtr();
5737 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5738 if (modifiedType.isNull())
5739 return QualType();
5740
5741 QualType result = TL.getType();
5742
5743 // FIXME: dependent operand expressions?
5744 if (getDerived().AlwaysRebuild() ||
5745 modifiedType != oldType->getModifiedType()) {
5746 // TODO: this is really lame; we should really be rebuilding the
5747 // equivalent type from first principles.
5748 QualType equivalentType
5749 = getDerived().TransformType(oldType->getEquivalentType());
5750 if (equivalentType.isNull())
5751 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005752
5753 // Check whether we can add nullability; it is only represented as
5754 // type sugar, and therefore cannot be diagnosed in any other way.
5755 if (auto nullability = oldType->getImmediateNullability()) {
5756 if (!modifiedType->canHaveNullability()) {
5757 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005758 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005759 return QualType();
5760 }
5761 }
5762
John McCall81904512011-01-06 01:58:22 +00005763 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5764 modifiedType,
5765 equivalentType);
5766 }
5767
5768 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5769 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5770 if (TL.hasAttrOperand())
5771 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5772 if (TL.hasAttrExprOperand())
5773 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5774 else if (TL.hasAttrEnumOperand())
5775 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5776
5777 return result;
5778}
5779
5780template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005781QualType
5782TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5783 ParenTypeLoc TL) {
5784 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5785 if (Inner.isNull())
5786 return QualType();
5787
5788 QualType Result = TL.getType();
5789 if (getDerived().AlwaysRebuild() ||
5790 Inner != TL.getInnerLoc().getType()) {
5791 Result = getDerived().RebuildParenType(Inner);
5792 if (Result.isNull())
5793 return QualType();
5794 }
5795
5796 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5797 NewTL.setLParenLoc(TL.getLParenLoc());
5798 NewTL.setRParenLoc(TL.getRParenLoc());
5799 return Result;
5800}
5801
5802template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005803QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005804 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005805 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005806
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005807 NestedNameSpecifierLoc QualifierLoc
5808 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5809 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005810 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005811
John McCallc392f372010-06-11 00:33:02 +00005812 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005813 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005814 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005815 QualifierLoc,
5816 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005817 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005818 if (Result.isNull())
5819 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005820
Abramo Bagnarad7548482010-05-19 21:37:53 +00005821 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5822 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005823 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5824
Abramo Bagnarad7548482010-05-19 21:37:53 +00005825 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005826 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005827 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005828 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005829 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005830 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005831 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005832 NewTL.setNameLoc(TL.getNameLoc());
5833 }
John McCall550e0c22009-10-21 00:40:46 +00005834 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005835}
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregord6ff3322009-08-04 16:50:30 +00005837template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005838QualType TreeTransform<Derived>::
5839 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005840 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005841 NestedNameSpecifierLoc QualifierLoc;
5842 if (TL.getQualifierLoc()) {
5843 QualifierLoc
5844 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5845 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005846 return QualType();
5847 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005848
John McCall31f82722010-11-12 08:19:04 +00005849 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005850 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005851}
5852
5853template<typename Derived>
5854QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005855TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5856 DependentTemplateSpecializationTypeLoc TL,
5857 NestedNameSpecifierLoc QualifierLoc) {
5858 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005859
Douglas Gregora7a795b2011-03-01 20:11:18 +00005860 TemplateArgumentListInfo NewTemplateArgs;
5861 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5862 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Douglas Gregora7a795b2011-03-01 20:11:18 +00005864 typedef TemplateArgumentLocContainerIterator<
5865 DependentTemplateSpecializationTypeLoc> ArgIterator;
5866 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5867 ArgIterator(TL, TL.getNumArgs()),
5868 NewTemplateArgs))
5869 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
Douglas Gregora7a795b2011-03-01 20:11:18 +00005871 QualType Result
5872 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5873 QualifierLoc,
5874 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005875 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005876 NewTemplateArgs);
5877 if (Result.isNull())
5878 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005879
Douglas Gregora7a795b2011-03-01 20:11:18 +00005880 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5881 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
Douglas Gregora7a795b2011-03-01 20:11:18 +00005883 // Copy information relevant to the template specialization.
5884 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005885 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005886 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005887 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005888 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5889 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005890 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005891 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
Douglas Gregora7a795b2011-03-01 20:11:18 +00005893 // Copy information relevant to the elaborated type.
5894 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005895 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005896 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005897 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5898 DependentTemplateSpecializationTypeLoc SpecTL
5899 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005900 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005901 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005902 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005903 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005904 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5905 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005906 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005907 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005908 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005909 TemplateSpecializationTypeLoc SpecTL
5910 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005911 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005912 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005913 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5914 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005915 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005916 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005917 }
5918 return Result;
5919}
5920
5921template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005922QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5923 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005924 QualType Pattern
5925 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005926 if (Pattern.isNull())
5927 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005928
5929 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005930 if (getDerived().AlwaysRebuild() ||
5931 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005932 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005933 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005934 TL.getEllipsisLoc(),
5935 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005936 if (Result.isNull())
5937 return QualType();
5938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005939
Douglas Gregor822d0302011-01-12 17:07:58 +00005940 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5941 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5942 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005943}
5944
5945template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005946QualType
5947TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005948 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005949 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005950 TLB.pushFullCopy(TL);
5951 return TL.getType();
5952}
5953
5954template<typename Derived>
5955QualType
Manman Rene6be26c2016-09-13 17:25:08 +00005956TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
5957 ObjCTypeParamTypeLoc TL) {
5958 const ObjCTypeParamType *T = TL.getTypePtr();
5959 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
5960 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
5961 if (!OTP)
5962 return QualType();
5963
5964 QualType Result = TL.getType();
5965 if (getDerived().AlwaysRebuild() ||
5966 OTP != T->getDecl()) {
5967 Result = getDerived().RebuildObjCTypeParamType(OTP,
5968 TL.getProtocolLAngleLoc(),
5969 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5970 TL.getNumProtocols()),
5971 TL.getProtocolLocs(),
5972 TL.getProtocolRAngleLoc());
5973 if (Result.isNull())
5974 return QualType();
5975 }
5976
5977 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
5978 if (TL.getNumProtocols()) {
5979 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5980 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5981 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
5982 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5983 }
5984 return Result;
5985}
5986
5987template<typename Derived>
5988QualType
John McCall8b07ec22010-05-15 11:32:37 +00005989TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005990 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005991 // Transform base type.
5992 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5993 if (BaseType.isNull())
5994 return QualType();
5995
5996 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5997
5998 // Transform type arguments.
5999 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6000 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6001 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6002 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6003 QualType TypeArg = TypeArgInfo->getType();
6004 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6005 AnyChanged = true;
6006
6007 // We have a pack expansion. Instantiate it.
6008 const auto *PackExpansion = PackExpansionLoc.getType()
6009 ->castAs<PackExpansionType>();
6010 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6011 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6012 Unexpanded);
6013 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6014
6015 // Determine whether the set of unexpanded parameter packs can
6016 // and should be expanded.
6017 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6018 bool Expand = false;
6019 bool RetainExpansion = false;
6020 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6021 if (getDerived().TryExpandParameterPacks(
6022 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6023 Unexpanded, Expand, RetainExpansion, NumExpansions))
6024 return QualType();
6025
6026 if (!Expand) {
6027 // We can't expand this pack expansion into separate arguments yet;
6028 // just substitute into the pattern and create a new pack expansion
6029 // type.
6030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6031
6032 TypeLocBuilder TypeArgBuilder;
6033 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6034 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6035 PatternLoc);
6036 if (NewPatternType.isNull())
6037 return QualType();
6038
6039 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6040 NewPatternType, NumExpansions);
6041 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6042 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6043 NewTypeArgInfos.push_back(
6044 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6045 continue;
6046 }
6047
6048 // Substitute into the pack expansion pattern for each slice of the
6049 // pack.
6050 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6051 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6052
6053 TypeLocBuilder TypeArgBuilder;
6054 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6055
6056 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6057 PatternLoc);
6058 if (NewTypeArg.isNull())
6059 return QualType();
6060
6061 NewTypeArgInfos.push_back(
6062 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6063 }
6064
6065 continue;
6066 }
6067
6068 TypeLocBuilder TypeArgBuilder;
6069 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6070 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6071 if (NewTypeArg.isNull())
6072 return QualType();
6073
6074 // If nothing changed, just keep the old TypeSourceInfo.
6075 if (NewTypeArg == TypeArg) {
6076 NewTypeArgInfos.push_back(TypeArgInfo);
6077 continue;
6078 }
6079
6080 NewTypeArgInfos.push_back(
6081 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6082 AnyChanged = true;
6083 }
6084
6085 QualType Result = TL.getType();
6086 if (getDerived().AlwaysRebuild() || AnyChanged) {
6087 // Rebuild the type.
6088 Result = getDerived().RebuildObjCObjectType(
6089 BaseType,
6090 TL.getLocStart(),
6091 TL.getTypeArgsLAngleLoc(),
6092 NewTypeArgInfos,
6093 TL.getTypeArgsRAngleLoc(),
6094 TL.getProtocolLAngleLoc(),
6095 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6096 TL.getNumProtocols()),
6097 TL.getProtocolLocs(),
6098 TL.getProtocolRAngleLoc());
6099
6100 if (Result.isNull())
6101 return QualType();
6102 }
6103
6104 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006105 NewT.setHasBaseTypeAsWritten(true);
6106 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6107 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6108 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6109 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6110 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6111 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6112 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6113 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6114 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006115}
Mike Stump11289f42009-09-09 15:08:12 +00006116
6117template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006118QualType
6119TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006120 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006121 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6122 if (PointeeType.isNull())
6123 return QualType();
6124
6125 QualType Result = TL.getType();
6126 if (getDerived().AlwaysRebuild() ||
6127 PointeeType != TL.getPointeeLoc().getType()) {
6128 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6129 TL.getStarLoc());
6130 if (Result.isNull())
6131 return QualType();
6132 }
6133
6134 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6135 NewT.setStarLoc(TL.getStarLoc());
6136 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006137}
6138
Douglas Gregord6ff3322009-08-04 16:50:30 +00006139//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006140// Statement transformation
6141//===----------------------------------------------------------------------===//
6142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006143StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006144TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006145 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006146}
6147
6148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006149StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006150TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6151 return getDerived().TransformCompoundStmt(S, false);
6152}
6153
6154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006155StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006156TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006158 Sema::CompoundScopeRAII CompoundScope(getSema());
6159
John McCall1ababa62010-08-27 19:56:05 +00006160 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006161 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006162 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006163 for (auto *B : S->body()) {
6164 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006165 if (Result.isInvalid()) {
6166 // Immediately fail if this was a DeclStmt, since it's very
6167 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006168 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006169 return StmtError();
6170
6171 // Otherwise, just keep processing substatements and fail later.
6172 SubStmtInvalid = true;
6173 continue;
6174 }
Mike Stump11289f42009-09-09 15:08:12 +00006175
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006176 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006177 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 }
Mike Stump11289f42009-09-09 15:08:12 +00006179
John McCall1ababa62010-08-27 19:56:05 +00006180 if (SubStmtInvalid)
6181 return StmtError();
6182
Douglas Gregorebe10102009-08-20 07:17:43 +00006183 if (!getDerived().AlwaysRebuild() &&
6184 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006185 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006186
6187 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006188 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006189 S->getRBracLoc(),
6190 IsStmtExpr);
6191}
Mike Stump11289f42009-09-09 15:08:12 +00006192
Douglas Gregorebe10102009-08-20 07:17:43 +00006193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006194StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006195TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006196 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006197 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006198 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6199 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006200
Eli Friedman06577382009-11-19 03:14:00 +00006201 // Transform the left-hand case value.
6202 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006203 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006204 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006205 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006206
Eli Friedman06577382009-11-19 03:14:00 +00006207 // Transform the right-hand case value (for the GNU case-range extension).
6208 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006209 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006210 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006211 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006212 }
Mike Stump11289f42009-09-09 15:08:12 +00006213
Douglas Gregorebe10102009-08-20 07:17:43 +00006214 // Build the case statement.
6215 // Case statements are always rebuilt so that they will attached to their
6216 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006217 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006218 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006219 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006220 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006221 S->getColonLoc());
6222 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006224
Douglas Gregorebe10102009-08-20 07:17:43 +00006225 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006226 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006227 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006229
Douglas Gregorebe10102009-08-20 07:17:43 +00006230 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006231 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006232}
6233
6234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006235StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006236TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006237 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006238 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006239 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006240 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006241
Douglas Gregorebe10102009-08-20 07:17:43 +00006242 // Default statements are always rebuilt
6243 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006244 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006245}
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregorebe10102009-08-20 07:17:43 +00006247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006248StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006249TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006250 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006251 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006252 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006253
Chris Lattnercab02a62011-02-17 20:34:02 +00006254 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6255 S->getDecl());
6256 if (!LD)
6257 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006258
6259
Douglas Gregorebe10102009-08-20 07:17:43 +00006260 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006261 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006262 cast<LabelDecl>(LD), SourceLocation(),
6263 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006264}
Mike Stump11289f42009-09-09 15:08:12 +00006265
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006266template <typename Derived>
6267const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6268 if (!R)
6269 return R;
6270
6271 switch (R->getKind()) {
6272// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6273#define ATTR(X)
6274#define PRAGMA_SPELLING_ATTR(X) \
6275 case attr::X: \
6276 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6277#include "clang/Basic/AttrList.inc"
6278 default:
6279 return R;
6280 }
6281}
6282
6283template <typename Derived>
6284StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6285 bool AttrsChanged = false;
6286 SmallVector<const Attr *, 1> Attrs;
6287
6288 // Visit attributes and keep track if any are transformed.
6289 for (const auto *I : S->getAttrs()) {
6290 const Attr *R = getDerived().TransformAttr(I);
6291 AttrsChanged |= (I != R);
6292 Attrs.push_back(R);
6293 }
6294
Richard Smithc202b282012-04-14 00:33:13 +00006295 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6296 if (SubStmt.isInvalid())
6297 return StmtError();
6298
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006299 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006300 return S;
6301
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006302 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006303 SubStmt.get());
6304}
6305
6306template<typename Derived>
6307StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006308TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006309 // Transform the initialization statement
6310 StmtResult Init = getDerived().TransformStmt(S->getInit());
6311 if (Init.isInvalid())
6312 return StmtError();
6313
Douglas Gregorebe10102009-08-20 07:17:43 +00006314 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006315 Sema::ConditionResult Cond = getDerived().TransformCondition(
6316 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006317 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6318 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006319 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006320 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
Richard Smithb130fe72016-06-23 19:16:49 +00006322 // If this is a constexpr if, determine which arm we should instantiate.
6323 llvm::Optional<bool> ConstexprConditionValue;
6324 if (S->isConstexpr())
6325 ConstexprConditionValue = Cond.getKnownValue();
6326
Douglas Gregorebe10102009-08-20 07:17:43 +00006327 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006328 StmtResult Then;
6329 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6330 Then = getDerived().TransformStmt(S->getThen());
6331 if (Then.isInvalid())
6332 return StmtError();
6333 } else {
6334 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6335 }
Mike Stump11289f42009-09-09 15:08:12 +00006336
Douglas Gregorebe10102009-08-20 07:17:43 +00006337 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006338 StmtResult Else;
6339 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6340 Else = getDerived().TransformStmt(S->getElse());
6341 if (Else.isInvalid())
6342 return StmtError();
6343 }
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregorebe10102009-08-20 07:17:43 +00006345 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006346 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006347 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006348 Then.get() == S->getThen() &&
6349 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006350 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006351
Richard Smithb130fe72016-06-23 19:16:49 +00006352 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006353 Init.get(), Then.get(), S->getElseLoc(),
6354 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006355}
6356
6357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006358StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006359TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006360 // Transform the initialization statement
6361 StmtResult Init = getDerived().TransformStmt(S->getInit());
6362 if (Init.isInvalid())
6363 return StmtError();
6364
Douglas Gregorebe10102009-08-20 07:17:43 +00006365 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006366 Sema::ConditionResult Cond = getDerived().TransformCondition(
6367 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6368 Sema::ConditionKind::Switch);
6369 if (Cond.isInvalid())
6370 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregorebe10102009-08-20 07:17:43 +00006372 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006373 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006374 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6375 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006376 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006378
Douglas Gregorebe10102009-08-20 07:17:43 +00006379 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006380 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006381 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006382 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregorebe10102009-08-20 07:17:43 +00006384 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006385 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6386 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006387}
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregorebe10102009-08-20 07:17:43 +00006389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006390StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006391TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006392 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006393 Sema::ConditionResult Cond = getDerived().TransformCondition(
6394 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6395 Sema::ConditionKind::Boolean);
6396 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006397 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006398
Douglas Gregorebe10102009-08-20 07:17:43 +00006399 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006400 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006401 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006402 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006403
Douglas Gregorebe10102009-08-20 07:17:43 +00006404 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006405 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006406 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006407 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006408
Richard Smith03a4aa32016-06-23 19:02:52 +00006409 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006410}
Mike Stump11289f42009-09-09 15:08:12 +00006411
Douglas Gregorebe10102009-08-20 07:17:43 +00006412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006413StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006414TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006415 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006416 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006417 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006418 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006419
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006420 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006421 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006422 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006424
Douglas Gregorebe10102009-08-20 07:17:43 +00006425 if (!getDerived().AlwaysRebuild() &&
6426 Cond.get() == S->getCond() &&
6427 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006428 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006429
John McCallb268a282010-08-23 23:25:46 +00006430 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6431 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006432 S->getRParenLoc());
6433}
Mike Stump11289f42009-09-09 15:08:12 +00006434
Douglas Gregorebe10102009-08-20 07:17:43 +00006435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006436StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006437TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006438 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006439 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006440 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006441 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006442
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006443 // In OpenMP loop region loop control variable must be captured and be
6444 // private. Perform analysis of first part (if any).
6445 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6446 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6447
Douglas Gregorebe10102009-08-20 07:17:43 +00006448 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006449 Sema::ConditionResult Cond = getDerived().TransformCondition(
6450 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6451 Sema::ConditionKind::Boolean);
6452 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006453 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006454
Douglas Gregorebe10102009-08-20 07:17:43 +00006455 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006456 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006457 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006458 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006459
Richard Smith945f8d32013-01-14 22:39:08 +00006460 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006461 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006462 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006463
Douglas Gregorebe10102009-08-20 07:17:43 +00006464 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006465 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006466 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006467 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006468
Douglas Gregorebe10102009-08-20 07:17:43 +00006469 if (!getDerived().AlwaysRebuild() &&
6470 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006471 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006472 Inc.get() == S->getInc() &&
6473 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006474 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006475
Douglas Gregorebe10102009-08-20 07:17:43 +00006476 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006477 Init.get(), Cond, FullInc,
6478 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006479}
6480
6481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006482StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006483TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006484 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6485 S->getLabel());
6486 if (!LD)
6487 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006488
Douglas Gregorebe10102009-08-20 07:17:43 +00006489 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006490 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006491 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006492}
6493
6494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006495StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006496TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006497 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006498 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006499 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006500 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006501
Douglas Gregorebe10102009-08-20 07:17:43 +00006502 if (!getDerived().AlwaysRebuild() &&
6503 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006504 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006505
6506 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006507 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006508}
6509
6510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006511StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006512TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006513 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006514}
Mike Stump11289f42009-09-09 15:08:12 +00006515
Douglas Gregorebe10102009-08-20 07:17:43 +00006516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006517StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006518TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006519 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006520}
Mike Stump11289f42009-09-09 15:08:12 +00006521
Douglas Gregorebe10102009-08-20 07:17:43 +00006522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006523StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006524TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006525 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6526 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006527 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006528 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006529
Mike Stump11289f42009-09-09 15:08:12 +00006530 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006531 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006532 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006533}
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregorebe10102009-08-20 07:17:43 +00006535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006536StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006537TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006538 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006539 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006540 for (auto *D : S->decls()) {
6541 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006542 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006543 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006544
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006545 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006546 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006547
Douglas Gregorebe10102009-08-20 07:17:43 +00006548 Decls.push_back(Transformed);
6549 }
Mike Stump11289f42009-09-09 15:08:12 +00006550
Douglas Gregorebe10102009-08-20 07:17:43 +00006551 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006552 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006553
Rafael Espindolaab417692013-07-09 12:05:01 +00006554 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006555}
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregorebe10102009-08-20 07:17:43 +00006557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006558StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006559TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006560
Benjamin Kramerf0623432012-08-23 22:51:59 +00006561 SmallVector<Expr*, 8> Constraints;
6562 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006563 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006564
John McCalldadc5752010-08-24 06:29:42 +00006565 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006566 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006567
6568 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006569
Anders Carlssonaaeef072010-01-24 05:50:09 +00006570 // Go through the outputs.
6571 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006572 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006573
Anders Carlssonaaeef072010-01-24 05:50:09 +00006574 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006575 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006576
Anders Carlssonaaeef072010-01-24 05:50:09 +00006577 // Transform the output expr.
6578 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006579 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006580 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Anders Carlssonaaeef072010-01-24 05:50:09 +00006583 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006584
John McCallb268a282010-08-23 23:25:46 +00006585 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006587
Anders Carlssonaaeef072010-01-24 05:50:09 +00006588 // Go through the inputs.
6589 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006590 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006591
Anders Carlssonaaeef072010-01-24 05:50:09 +00006592 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006593 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006594
Anders Carlssonaaeef072010-01-24 05:50:09 +00006595 // Transform the input expr.
6596 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006597 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006598 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006599 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006600
Anders Carlssonaaeef072010-01-24 05:50:09 +00006601 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006602
John McCallb268a282010-08-23 23:25:46 +00006603 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006604 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006605
Anders Carlssonaaeef072010-01-24 05:50:09 +00006606 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006607 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006608
6609 // Go through the clobbers.
6610 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006611 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006612
6613 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006614 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006615 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6616 S->isVolatile(), S->getNumOutputs(),
6617 S->getNumInputs(), Names.data(),
6618 Constraints, Exprs, AsmString.get(),
6619 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006620}
6621
Chad Rosier32503022012-06-11 20:47:18 +00006622template<typename Derived>
6623StmtResult
6624TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006625 ArrayRef<Token> AsmToks =
6626 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006627
John McCallf413f5e2013-05-03 00:10:13 +00006628 bool HadError = false, HadChange = false;
6629
6630 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6631 SmallVector<Expr*, 8> TransformedExprs;
6632 TransformedExprs.reserve(SrcExprs.size());
6633 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6634 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6635 if (!Result.isUsable()) {
6636 HadError = true;
6637 } else {
6638 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006639 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006640 }
6641 }
6642
6643 if (HadError) return StmtError();
6644 if (!HadChange && !getDerived().AlwaysRebuild())
6645 return Owned(S);
6646
Chad Rosierb6f46c12012-08-15 16:53:30 +00006647 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006648 AsmToks, S->getAsmString(),
6649 S->getNumOutputs(), S->getNumInputs(),
6650 S->getAllConstraints(), S->getClobbers(),
6651 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006652}
Douglas Gregorebe10102009-08-20 07:17:43 +00006653
Richard Smith9f690bd2015-10-27 06:02:45 +00006654// C++ Coroutines TS
6655
6656template<typename Derived>
6657StmtResult
6658TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6659 // The coroutine body should be re-formed by the caller if necessary.
Eric Fiselier709d1b32016-10-27 07:30:31 +00006660 // FIXME: The coroutine body is always rebuilt by ActOnFinishFunctionBody
Richard Smith9f690bd2015-10-27 06:02:45 +00006661 return getDerived().TransformStmt(S->getBody());
6662}
6663
6664template<typename Derived>
6665StmtResult
6666TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6667 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6668 /*NotCopyInit*/false);
6669 if (Result.isInvalid())
6670 return StmtError();
6671
6672 // Always rebuild; we don't know if this needs to be injected into a new
6673 // context or if the promise type has changed.
6674 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6675}
6676
6677template<typename Derived>
6678ExprResult
6679TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6680 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6681 /*NotCopyInit*/false);
6682 if (Result.isInvalid())
6683 return ExprError();
6684
6685 // Always rebuild; we don't know if this needs to be injected into a new
6686 // context or if the promise type has changed.
6687 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6688}
6689
6690template<typename Derived>
6691ExprResult
6692TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6693 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6694 /*NotCopyInit*/false);
6695 if (Result.isInvalid())
6696 return ExprError();
6697
6698 // Always rebuild; we don't know if this needs to be injected into a new
6699 // context or if the promise type has changed.
6700 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6701}
6702
6703// Objective-C Statements.
6704
Douglas Gregorebe10102009-08-20 07:17:43 +00006705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006706StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006707TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006708 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006709 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006710 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006711 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006712
Douglas Gregor96c79492010-04-23 22:50:49 +00006713 // Transform the @catch statements (if present).
6714 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006715 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006716 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006717 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006718 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006719 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006720 if (Catch.get() != S->getCatchStmt(I))
6721 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006722 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006724
Douglas Gregor306de2f2010-04-22 23:59:56 +00006725 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006726 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006727 if (S->getFinallyStmt()) {
6728 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6729 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006731 }
6732
6733 // If nothing changed, just retain this statement.
6734 if (!getDerived().AlwaysRebuild() &&
6735 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006736 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006737 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006738 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006739
Douglas Gregor306de2f2010-04-22 23:59:56 +00006740 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006741 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006742 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006743}
Mike Stump11289f42009-09-09 15:08:12 +00006744
Douglas Gregorebe10102009-08-20 07:17:43 +00006745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006746StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006747TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006748 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006749 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006750 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006751 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006752 if (FromVar->getTypeSourceInfo()) {
6753 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6754 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006755 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006756 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006757
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006758 QualType T;
6759 if (TSInfo)
6760 T = TSInfo->getType();
6761 else {
6762 T = getDerived().TransformType(FromVar->getType());
6763 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006764 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006765 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006766
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006767 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6768 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006769 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006770 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006771
John McCalldadc5752010-08-24 06:29:42 +00006772 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006773 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
6776 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006777 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006778 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006779}
Mike Stump11289f42009-09-09 15:08:12 +00006780
Douglas Gregorebe10102009-08-20 07:17:43 +00006781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006782StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006783TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006784 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006785 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006786 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006787 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006788
Douglas Gregor306de2f2010-04-22 23:59:56 +00006789 // If nothing changed, just retain this statement.
6790 if (!getDerived().AlwaysRebuild() &&
6791 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006792 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006793
6794 // Build a new statement.
6795 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006796 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006797}
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregorebe10102009-08-20 07:17:43 +00006799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006800StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006801TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006802 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006803 if (S->getThrowExpr()) {
6804 Operand = getDerived().TransformExpr(S->getThrowExpr());
6805 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006806 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006807 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006808
Douglas Gregor2900c162010-04-22 21:44:01 +00006809 if (!getDerived().AlwaysRebuild() &&
6810 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006811 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006812
John McCallb268a282010-08-23 23:25:46 +00006813 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006814}
Mike Stump11289f42009-09-09 15:08:12 +00006815
Douglas Gregorebe10102009-08-20 07:17:43 +00006816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006817StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006818TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006819 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006820 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006821 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006822 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006823 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006824 Object =
6825 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6826 Object.get());
6827 if (Object.isInvalid())
6828 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006829
Douglas Gregor6148de72010-04-22 22:01:21 +00006830 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006831 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006832 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006833 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006834
Douglas Gregor6148de72010-04-22 22:01:21 +00006835 // If nothing change, just retain the current statement.
6836 if (!getDerived().AlwaysRebuild() &&
6837 Object.get() == S->getSynchExpr() &&
6838 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006839 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006840
6841 // Build a new statement.
6842 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006843 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006844}
6845
6846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006847StmtResult
John McCall31168b02011-06-15 23:02:42 +00006848TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6849 ObjCAutoreleasePoolStmt *S) {
6850 // Transform the body.
6851 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6852 if (Body.isInvalid())
6853 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006854
John McCall31168b02011-06-15 23:02:42 +00006855 // If nothing changed, just retain this statement.
6856 if (!getDerived().AlwaysRebuild() &&
6857 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006858 return S;
John McCall31168b02011-06-15 23:02:42 +00006859
6860 // Build a new statement.
6861 return getDerived().RebuildObjCAutoreleasePoolStmt(
6862 S->getAtLoc(), Body.get());
6863}
6864
6865template<typename Derived>
6866StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006867TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006868 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006869 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006870 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006871 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006872 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006873
Douglas Gregorf68a5082010-04-22 23:10:45 +00006874 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006875 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006876 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006877 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006878
Douglas Gregorf68a5082010-04-22 23:10:45 +00006879 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006880 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006881 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006882 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006883
Douglas Gregorf68a5082010-04-22 23:10:45 +00006884 // If nothing changed, just retain this statement.
6885 if (!getDerived().AlwaysRebuild() &&
6886 Element.get() == S->getElement() &&
6887 Collection.get() == S->getCollection() &&
6888 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006889 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006890
Douglas Gregorf68a5082010-04-22 23:10:45 +00006891 // Build a new statement.
6892 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006893 Element.get(),
6894 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006895 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006896 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006897}
6898
David Majnemer5f7efef2013-10-15 09:50:08 +00006899template <typename Derived>
6900StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006901 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006902 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006903 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6904 TypeSourceInfo *T =
6905 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006906 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006907 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006908
David Majnemer5f7efef2013-10-15 09:50:08 +00006909 Var = getDerived().RebuildExceptionDecl(
6910 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6911 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006912 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006913 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006914 }
Mike Stump11289f42009-09-09 15:08:12 +00006915
Douglas Gregorebe10102009-08-20 07:17:43 +00006916 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006917 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006918 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006920
David Majnemer5f7efef2013-10-15 09:50:08 +00006921 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006922 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006923 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006924
David Majnemer5f7efef2013-10-15 09:50:08 +00006925 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006926}
Mike Stump11289f42009-09-09 15:08:12 +00006927
David Majnemer5f7efef2013-10-15 09:50:08 +00006928template <typename Derived>
6929StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006930 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006931 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006932 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006933 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006934
Douglas Gregorebe10102009-08-20 07:17:43 +00006935 // Transform the handlers.
6936 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006937 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006938 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006939 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006940 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006941 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregorebe10102009-08-20 07:17:43 +00006943 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006944 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006945 }
Mike Stump11289f42009-09-09 15:08:12 +00006946
David Majnemer5f7efef2013-10-15 09:50:08 +00006947 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006948 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006949 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006950
John McCallb268a282010-08-23 23:25:46 +00006951 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006952 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006953}
Mike Stump11289f42009-09-09 15:08:12 +00006954
Richard Smith02e85f32011-04-14 22:09:26 +00006955template<typename Derived>
6956StmtResult
6957TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6958 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6959 if (Range.isInvalid())
6960 return StmtError();
6961
Richard Smith01694c32016-03-20 10:33:40 +00006962 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6963 if (Begin.isInvalid())
6964 return StmtError();
6965 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6966 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006967 return StmtError();
6968
6969 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6970 if (Cond.isInvalid())
6971 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006972 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006973 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006974 if (Cond.isInvalid())
6975 return StmtError();
6976 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006977 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006978
6979 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6980 if (Inc.isInvalid())
6981 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006982 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006983 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006984
6985 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6986 if (LoopVar.isInvalid())
6987 return StmtError();
6988
6989 StmtResult NewStmt = S;
6990 if (getDerived().AlwaysRebuild() ||
6991 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006992 Begin.get() != S->getBeginStmt() ||
6993 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006994 Cond.get() != S->getCond() ||
6995 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006996 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006997 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006998 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006999 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007000 Begin.get(), End.get(),
7001 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007002 Inc.get(), LoopVar.get(),
7003 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007004 if (NewStmt.isInvalid())
7005 return StmtError();
7006 }
Richard Smith02e85f32011-04-14 22:09:26 +00007007
7008 StmtResult Body = getDerived().TransformStmt(S->getBody());
7009 if (Body.isInvalid())
7010 return StmtError();
7011
7012 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7013 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007014 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007015 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007016 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007017 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007018 Begin.get(), End.get(),
7019 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007020 Inc.get(), LoopVar.get(),
7021 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007022 if (NewStmt.isInvalid())
7023 return StmtError();
7024 }
Richard Smith02e85f32011-04-14 22:09:26 +00007025
7026 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007027 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007028
7029 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7030}
7031
John Wiegley1c0675e2011-04-28 01:08:34 +00007032template<typename Derived>
7033StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007034TreeTransform<Derived>::TransformMSDependentExistsStmt(
7035 MSDependentExistsStmt *S) {
7036 // Transform the nested-name-specifier, if any.
7037 NestedNameSpecifierLoc QualifierLoc;
7038 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007039 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007040 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7041 if (!QualifierLoc)
7042 return StmtError();
7043 }
7044
7045 // Transform the declaration name.
7046 DeclarationNameInfo NameInfo = S->getNameInfo();
7047 if (NameInfo.getName()) {
7048 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7049 if (!NameInfo.getName())
7050 return StmtError();
7051 }
7052
7053 // Check whether anything changed.
7054 if (!getDerived().AlwaysRebuild() &&
7055 QualifierLoc == S->getQualifierLoc() &&
7056 NameInfo.getName() == S->getNameInfo().getName())
7057 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007058
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007059 // Determine whether this name exists, if we can.
7060 CXXScopeSpec SS;
7061 SS.Adopt(QualifierLoc);
7062 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007063 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007064 case Sema::IER_Exists:
7065 if (S->isIfExists())
7066 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007067
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007068 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7069
7070 case Sema::IER_DoesNotExist:
7071 if (S->isIfNotExists())
7072 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007073
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007074 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007075
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007076 case Sema::IER_Dependent:
7077 Dependent = true;
7078 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007079
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007080 case Sema::IER_Error:
7081 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007083
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007084 // We need to continue with the instantiation, so do so now.
7085 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7086 if (SubStmt.isInvalid())
7087 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007088
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007089 // If we have resolved the name, just transform to the substatement.
7090 if (!Dependent)
7091 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007092
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007093 // The name is still dependent, so build a dependent expression again.
7094 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7095 S->isIfExists(),
7096 QualifierLoc,
7097 NameInfo,
7098 SubStmt.get());
7099}
7100
7101template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007102ExprResult
7103TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7104 NestedNameSpecifierLoc QualifierLoc;
7105 if (E->getQualifierLoc()) {
7106 QualifierLoc
7107 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7108 if (!QualifierLoc)
7109 return ExprError();
7110 }
7111
7112 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7113 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7114 if (!PD)
7115 return ExprError();
7116
7117 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7118 if (Base.isInvalid())
7119 return ExprError();
7120
7121 return new (SemaRef.getASTContext())
7122 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7123 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7124 QualifierLoc, E->getMemberLoc());
7125}
7126
David Majnemerfad8f482013-10-15 09:33:02 +00007127template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007128ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7129 MSPropertySubscriptExpr *E) {
7130 auto BaseRes = getDerived().TransformExpr(E->getBase());
7131 if (BaseRes.isInvalid())
7132 return ExprError();
7133 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7134 if (IdxRes.isInvalid())
7135 return ExprError();
7136
7137 if (!getDerived().AlwaysRebuild() &&
7138 BaseRes.get() == E->getBase() &&
7139 IdxRes.get() == E->getIdx())
7140 return E;
7141
7142 return getDerived().RebuildArraySubscriptExpr(
7143 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7144}
7145
7146template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007147StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007148 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007149 if (TryBlock.isInvalid())
7150 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007151
7152 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007153 if (Handler.isInvalid())
7154 return StmtError();
7155
David Majnemerfad8f482013-10-15 09:33:02 +00007156 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7157 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007158 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007159
Warren Huntf6be4cb2014-07-25 20:52:51 +00007160 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7161 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007162}
7163
David Majnemerfad8f482013-10-15 09:33:02 +00007164template <typename Derived>
7165StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007166 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007167 if (Block.isInvalid())
7168 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007169
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007170 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007171}
7172
David Majnemerfad8f482013-10-15 09:33:02 +00007173template <typename Derived>
7174StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007175 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007176 if (FilterExpr.isInvalid())
7177 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007178
David Majnemer7e755502013-10-15 09:30:14 +00007179 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007180 if (Block.isInvalid())
7181 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007182
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007183 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7184 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007185}
7186
David Majnemerfad8f482013-10-15 09:33:02 +00007187template <typename Derived>
7188StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7189 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007190 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7191 else
7192 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7193}
7194
Nico Weber9b982072014-07-07 00:12:30 +00007195template<typename Derived>
7196StmtResult
7197TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7198 return S;
7199}
7200
Alexander Musman64d33f12014-06-04 07:53:32 +00007201//===----------------------------------------------------------------------===//
7202// OpenMP directive transformation
7203//===----------------------------------------------------------------------===//
7204template <typename Derived>
7205StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7206 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007207
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007208 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007209 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007210 ArrayRef<OMPClause *> Clauses = D->clauses();
7211 TClauses.reserve(Clauses.size());
7212 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7213 I != E; ++I) {
7214 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007215 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007216 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007217 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007218 if (Clause)
7219 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007220 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007221 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007222 }
7223 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007224 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007225 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007226 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7227 /*CurScope=*/nullptr);
7228 StmtResult Body;
7229 {
7230 Sema::CompoundScopeRAII CompoundScope(getSema());
7231 Body = getDerived().TransformStmt(
7232 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7233 }
7234 AssociatedStmt =
7235 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007236 if (AssociatedStmt.isInvalid()) {
7237 return StmtError();
7238 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007239 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007240 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007241 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007242 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007243
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007244 // Transform directive name for 'omp critical' directive.
7245 DeclarationNameInfo DirName;
7246 if (D->getDirectiveKind() == OMPD_critical) {
7247 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7248 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7249 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007250 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7251 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7252 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007253 } else if (D->getDirectiveKind() == OMPD_cancel) {
7254 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007255 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007256
Alexander Musman64d33f12014-06-04 07:53:32 +00007257 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007258 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7259 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007260}
7261
Alexander Musman64d33f12014-06-04 07:53:32 +00007262template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007263StmtResult
7264TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7265 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007266 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7267 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007268 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7269 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7270 return Res;
7271}
7272
Alexander Musman64d33f12014-06-04 07:53:32 +00007273template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007274StmtResult
7275TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7276 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007277 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7278 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007279 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7280 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007281 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007282}
7283
Alexey Bataevf29276e2014-06-18 04:14:57 +00007284template <typename Derived>
7285StmtResult
7286TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7287 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007288 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7289 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007290 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7291 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7292 return Res;
7293}
7294
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007295template <typename Derived>
7296StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007297TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7298 DeclarationNameInfo DirName;
7299 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7300 D->getLocStart());
7301 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7302 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7303 return Res;
7304}
7305
7306template <typename Derived>
7307StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007308TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7309 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007310 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7311 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007312 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7313 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7314 return Res;
7315}
7316
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007317template <typename Derived>
7318StmtResult
7319TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7320 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007321 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7322 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007323 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7324 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7325 return Res;
7326}
7327
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007328template <typename Derived>
7329StmtResult
7330TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7331 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007332 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7333 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007334 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7335 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7336 return Res;
7337}
7338
Alexey Bataev4acb8592014-07-07 13:01:15 +00007339template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007340StmtResult
7341TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7342 DeclarationNameInfo DirName;
7343 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7344 D->getLocStart());
7345 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7346 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7347 return Res;
7348}
7349
7350template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007351StmtResult
7352TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7353 getDerived().getSema().StartOpenMPDSABlock(
7354 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7355 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7356 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7357 return Res;
7358}
7359
7360template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007361StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7362 OMPParallelForDirective *D) {
7363 DeclarationNameInfo DirName;
7364 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7365 nullptr, D->getLocStart());
7366 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7367 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7368 return Res;
7369}
7370
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007371template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007372StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7373 OMPParallelForSimdDirective *D) {
7374 DeclarationNameInfo DirName;
7375 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7376 nullptr, D->getLocStart());
7377 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7378 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7379 return Res;
7380}
7381
7382template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007383StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7384 OMPParallelSectionsDirective *D) {
7385 DeclarationNameInfo DirName;
7386 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7387 nullptr, D->getLocStart());
7388 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7389 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7390 return Res;
7391}
7392
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007393template <typename Derived>
7394StmtResult
7395TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7396 DeclarationNameInfo DirName;
7397 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7398 D->getLocStart());
7399 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7400 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7401 return Res;
7402}
7403
Alexey Bataev68446b72014-07-18 07:47:19 +00007404template <typename Derived>
7405StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7406 OMPTaskyieldDirective *D) {
7407 DeclarationNameInfo DirName;
7408 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7409 D->getLocStart());
7410 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7411 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7412 return Res;
7413}
7414
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007415template <typename Derived>
7416StmtResult
7417TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7418 DeclarationNameInfo DirName;
7419 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7420 D->getLocStart());
7421 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7422 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7423 return Res;
7424}
7425
Alexey Bataev2df347a2014-07-18 10:17:07 +00007426template <typename Derived>
7427StmtResult
7428TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7429 DeclarationNameInfo DirName;
7430 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7431 D->getLocStart());
7432 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7433 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7434 return Res;
7435}
7436
Alexey Bataev6125da92014-07-21 11:26:11 +00007437template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007438StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7439 OMPTaskgroupDirective *D) {
7440 DeclarationNameInfo DirName;
7441 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7442 D->getLocStart());
7443 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7444 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7445 return Res;
7446}
7447
7448template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007449StmtResult
7450TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7451 DeclarationNameInfo DirName;
7452 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7453 D->getLocStart());
7454 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7455 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7456 return Res;
7457}
7458
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007459template <typename Derived>
7460StmtResult
7461TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7462 DeclarationNameInfo DirName;
7463 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7464 D->getLocStart());
7465 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7466 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7467 return Res;
7468}
7469
Alexey Bataev0162e452014-07-22 10:10:35 +00007470template <typename Derived>
7471StmtResult
7472TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7473 DeclarationNameInfo DirName;
7474 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7475 D->getLocStart());
7476 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7477 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7478 return Res;
7479}
7480
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007481template <typename Derived>
7482StmtResult
7483TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7484 DeclarationNameInfo DirName;
7485 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7486 D->getLocStart());
7487 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7488 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7489 return Res;
7490}
7491
Alexey Bataev13314bf2014-10-09 04:18:56 +00007492template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007493StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7494 OMPTargetDataDirective *D) {
7495 DeclarationNameInfo DirName;
7496 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7497 D->getLocStart());
7498 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7499 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7500 return Res;
7501}
7502
7503template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007504StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7505 OMPTargetEnterDataDirective *D) {
7506 DeclarationNameInfo DirName;
7507 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7508 nullptr, D->getLocStart());
7509 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7510 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7511 return Res;
7512}
7513
7514template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007515StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7516 OMPTargetExitDataDirective *D) {
7517 DeclarationNameInfo DirName;
7518 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7519 nullptr, D->getLocStart());
7520 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7521 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7522 return Res;
7523}
7524
7525template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007526StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7527 OMPTargetParallelDirective *D) {
7528 DeclarationNameInfo DirName;
7529 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7530 nullptr, D->getLocStart());
7531 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7532 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7533 return Res;
7534}
7535
7536template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007537StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7538 OMPTargetParallelForDirective *D) {
7539 DeclarationNameInfo DirName;
7540 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7541 nullptr, D->getLocStart());
7542 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7543 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7544 return Res;
7545}
7546
7547template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007548StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7549 OMPTargetUpdateDirective *D) {
7550 DeclarationNameInfo DirName;
7551 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7552 nullptr, D->getLocStart());
7553 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7554 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7555 return Res;
7556}
7557
7558template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007559StmtResult
7560TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7561 DeclarationNameInfo DirName;
7562 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7563 D->getLocStart());
7564 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7565 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7566 return Res;
7567}
7568
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007569template <typename Derived>
7570StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7571 OMPCancellationPointDirective *D) {
7572 DeclarationNameInfo DirName;
7573 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7574 nullptr, D->getLocStart());
7575 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7576 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7577 return Res;
7578}
7579
Alexey Bataev80909872015-07-02 11:25:17 +00007580template <typename Derived>
7581StmtResult
7582TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7583 DeclarationNameInfo DirName;
7584 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7585 D->getLocStart());
7586 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7587 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7588 return Res;
7589}
7590
Alexey Bataev49f6e782015-12-01 04:18:41 +00007591template <typename Derived>
7592StmtResult
7593TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7594 DeclarationNameInfo DirName;
7595 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7596 D->getLocStart());
7597 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7598 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7599 return Res;
7600}
7601
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007602template <typename Derived>
7603StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7604 OMPTaskLoopSimdDirective *D) {
7605 DeclarationNameInfo DirName;
7606 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7607 nullptr, D->getLocStart());
7608 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7609 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7610 return Res;
7611}
7612
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007613template <typename Derived>
7614StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7615 OMPDistributeDirective *D) {
7616 DeclarationNameInfo DirName;
7617 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7618 D->getLocStart());
7619 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7620 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7621 return Res;
7622}
7623
Carlo Bertolli9925f152016-06-27 14:55:37 +00007624template <typename Derived>
7625StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7626 OMPDistributeParallelForDirective *D) {
7627 DeclarationNameInfo DirName;
7628 getDerived().getSema().StartOpenMPDSABlock(
7629 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7630 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7631 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7632 return Res;
7633}
7634
Kelvin Li4a39add2016-07-05 05:00:15 +00007635template <typename Derived>
7636StmtResult
7637TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7638 OMPDistributeParallelForSimdDirective *D) {
7639 DeclarationNameInfo DirName;
7640 getDerived().getSema().StartOpenMPDSABlock(
7641 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7642 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7643 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7644 return Res;
7645}
7646
Kelvin Li787f3fc2016-07-06 04:45:38 +00007647template <typename Derived>
7648StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7649 OMPDistributeSimdDirective *D) {
7650 DeclarationNameInfo DirName;
7651 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7652 nullptr, D->getLocStart());
7653 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7654 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7655 return Res;
7656}
7657
Kelvin Lia579b912016-07-14 02:54:56 +00007658template <typename Derived>
7659StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7660 OMPTargetParallelForSimdDirective *D) {
7661 DeclarationNameInfo DirName;
7662 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7663 DirName, nullptr,
7664 D->getLocStart());
7665 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7666 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7667 return Res;
7668}
7669
Kelvin Li986330c2016-07-20 22:57:10 +00007670template <typename Derived>
7671StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7672 OMPTargetSimdDirective *D) {
7673 DeclarationNameInfo DirName;
7674 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7675 D->getLocStart());
7676 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7677 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7678 return Res;
7679}
7680
Kelvin Li02532872016-08-05 14:37:37 +00007681template <typename Derived>
7682StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7683 OMPTeamsDistributeDirective *D) {
7684 DeclarationNameInfo DirName;
7685 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7686 nullptr, D->getLocStart());
7687 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7688 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7689 return Res;
7690}
7691
Kelvin Li4e325f72016-10-25 12:50:55 +00007692template <typename Derived>
7693StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
7694 OMPTeamsDistributeSimdDirective *D) {
7695 DeclarationNameInfo DirName;
7696 getDerived().getSema().StartOpenMPDSABlock(
7697 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7698 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7699 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7700 return Res;
7701}
7702
Alexander Musman64d33f12014-06-04 07:53:32 +00007703//===----------------------------------------------------------------------===//
7704// OpenMP clause transformation
7705//===----------------------------------------------------------------------===//
7706template <typename Derived>
7707OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007708 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7709 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007710 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007711 return getDerived().RebuildOMPIfClause(
7712 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7713 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007714}
7715
Alexander Musman64d33f12014-06-04 07:53:32 +00007716template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007717OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7718 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7719 if (Cond.isInvalid())
7720 return nullptr;
7721 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7722 C->getLParenLoc(), C->getLocEnd());
7723}
7724
7725template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007726OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007727TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7728 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7729 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007730 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007731 return getDerived().RebuildOMPNumThreadsClause(
7732 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007733}
7734
Alexey Bataev62c87d22014-03-21 04:51:18 +00007735template <typename Derived>
7736OMPClause *
7737TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7738 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7739 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007740 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007741 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007742 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007743}
7744
Alexander Musman8bd31e62014-05-27 15:12:19 +00007745template <typename Derived>
7746OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007747TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7748 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7749 if (E.isInvalid())
7750 return nullptr;
7751 return getDerived().RebuildOMPSimdlenClause(
7752 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7753}
7754
7755template <typename Derived>
7756OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007757TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7758 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7759 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007760 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007761 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007762 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007763}
7764
Alexander Musman64d33f12014-06-04 07:53:32 +00007765template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007766OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007767TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007768 return getDerived().RebuildOMPDefaultClause(
7769 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7770 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007771}
7772
Alexander Musman64d33f12014-06-04 07:53:32 +00007773template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007774OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007775TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007776 return getDerived().RebuildOMPProcBindClause(
7777 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7778 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007779}
7780
Alexander Musman64d33f12014-06-04 07:53:32 +00007781template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007782OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007783TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7784 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7785 if (E.isInvalid())
7786 return nullptr;
7787 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007788 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007789 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007790 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007791 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7792}
7793
7794template <typename Derived>
7795OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007796TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007797 ExprResult E;
7798 if (auto *Num = C->getNumForLoops()) {
7799 E = getDerived().TransformExpr(Num);
7800 if (E.isInvalid())
7801 return nullptr;
7802 }
7803 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7804 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007805}
7806
7807template <typename Derived>
7808OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007809TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7810 // No need to rebuild this clause, no template-dependent parameters.
7811 return C;
7812}
7813
7814template <typename Derived>
7815OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007816TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7817 // No need to rebuild this clause, no template-dependent parameters.
7818 return C;
7819}
7820
7821template <typename Derived>
7822OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007823TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7824 // No need to rebuild this clause, no template-dependent parameters.
7825 return C;
7826}
7827
7828template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007829OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7830 // No need to rebuild this clause, no template-dependent parameters.
7831 return C;
7832}
7833
7834template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007835OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7836 // No need to rebuild this clause, no template-dependent parameters.
7837 return C;
7838}
7839
7840template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007841OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007842TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7843 // No need to rebuild this clause, no template-dependent parameters.
7844 return C;
7845}
7846
7847template <typename Derived>
7848OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007849TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7850 // No need to rebuild this clause, no template-dependent parameters.
7851 return C;
7852}
7853
7854template <typename Derived>
7855OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007856TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7857 // No need to rebuild this clause, no template-dependent parameters.
7858 return C;
7859}
7860
7861template <typename Derived>
7862OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007863TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7864 // No need to rebuild this clause, no template-dependent parameters.
7865 return C;
7866}
7867
7868template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007869OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7870 // No need to rebuild this clause, no template-dependent parameters.
7871 return C;
7872}
7873
7874template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007875OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007876TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7877 // No need to rebuild this clause, no template-dependent parameters.
7878 return C;
7879}
7880
7881template <typename Derived>
7882OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007883TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007884 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007885 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007886 for (auto *VE : C->varlists()) {
7887 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007888 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007889 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007890 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007891 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007892 return getDerived().RebuildOMPPrivateClause(
7893 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007894}
7895
Alexander Musman64d33f12014-06-04 07:53:32 +00007896template <typename Derived>
7897OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7898 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007899 llvm::SmallVector<Expr *, 16> Vars;
7900 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007901 for (auto *VE : C->varlists()) {
7902 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007903 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007904 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007905 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007906 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007907 return getDerived().RebuildOMPFirstprivateClause(
7908 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007909}
7910
Alexander Musman64d33f12014-06-04 07:53:32 +00007911template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007912OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007913TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7914 llvm::SmallVector<Expr *, 16> Vars;
7915 Vars.reserve(C->varlist_size());
7916 for (auto *VE : C->varlists()) {
7917 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7918 if (EVar.isInvalid())
7919 return nullptr;
7920 Vars.push_back(EVar.get());
7921 }
7922 return getDerived().RebuildOMPLastprivateClause(
7923 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7924}
7925
7926template <typename Derived>
7927OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007928TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7929 llvm::SmallVector<Expr *, 16> Vars;
7930 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007931 for (auto *VE : C->varlists()) {
7932 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007933 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007934 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007935 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007936 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007937 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7938 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007939}
7940
Alexander Musman64d33f12014-06-04 07:53:32 +00007941template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007942OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007943TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7944 llvm::SmallVector<Expr *, 16> Vars;
7945 Vars.reserve(C->varlist_size());
7946 for (auto *VE : C->varlists()) {
7947 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7948 if (EVar.isInvalid())
7949 return nullptr;
7950 Vars.push_back(EVar.get());
7951 }
7952 CXXScopeSpec ReductionIdScopeSpec;
7953 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7954
7955 DeclarationNameInfo NameInfo = C->getNameInfo();
7956 if (NameInfo.getName()) {
7957 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7958 if (!NameInfo.getName())
7959 return nullptr;
7960 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007961 // Build a list of all UDR decls with the same names ranged by the Scopes.
7962 // The Scope boundary is a duplication of the previous decl.
7963 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7964 for (auto *E : C->reduction_ops()) {
7965 // Transform all the decls.
7966 if (E) {
7967 auto *ULE = cast<UnresolvedLookupExpr>(E);
7968 UnresolvedSet<8> Decls;
7969 for (auto *D : ULE->decls()) {
7970 NamedDecl *InstD =
7971 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7972 Decls.addDecl(InstD, InstD->getAccess());
7973 }
7974 UnresolvedReductions.push_back(
7975 UnresolvedLookupExpr::Create(
7976 SemaRef.Context, /*NamingClass=*/nullptr,
7977 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7978 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7979 Decls.begin(), Decls.end()));
7980 } else
7981 UnresolvedReductions.push_back(nullptr);
7982 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007983 return getDerived().RebuildOMPReductionClause(
7984 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007985 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007986}
7987
7988template <typename Derived>
7989OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007990TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7991 llvm::SmallVector<Expr *, 16> Vars;
7992 Vars.reserve(C->varlist_size());
7993 for (auto *VE : C->varlists()) {
7994 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7995 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007996 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007997 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007998 }
7999 ExprResult Step = getDerived().TransformExpr(C->getStep());
8000 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008001 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008002 return getDerived().RebuildOMPLinearClause(
8003 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8004 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008005}
8006
Alexander Musman64d33f12014-06-04 07:53:32 +00008007template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008008OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008009TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8010 llvm::SmallVector<Expr *, 16> Vars;
8011 Vars.reserve(C->varlist_size());
8012 for (auto *VE : C->varlists()) {
8013 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8014 if (EVar.isInvalid())
8015 return nullptr;
8016 Vars.push_back(EVar.get());
8017 }
8018 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8019 if (Alignment.isInvalid())
8020 return nullptr;
8021 return getDerived().RebuildOMPAlignedClause(
8022 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8023 C->getColonLoc(), C->getLocEnd());
8024}
8025
Alexander Musman64d33f12014-06-04 07:53:32 +00008026template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008027OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008028TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8029 llvm::SmallVector<Expr *, 16> Vars;
8030 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008031 for (auto *VE : C->varlists()) {
8032 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008033 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008034 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008035 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008036 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008037 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8038 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008039}
8040
Alexey Bataevbae9a792014-06-27 10:37:06 +00008041template <typename Derived>
8042OMPClause *
8043TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8044 llvm::SmallVector<Expr *, 16> Vars;
8045 Vars.reserve(C->varlist_size());
8046 for (auto *VE : C->varlists()) {
8047 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8048 if (EVar.isInvalid())
8049 return nullptr;
8050 Vars.push_back(EVar.get());
8051 }
8052 return getDerived().RebuildOMPCopyprivateClause(
8053 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8054}
8055
Alexey Bataev6125da92014-07-21 11:26:11 +00008056template <typename Derived>
8057OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8058 llvm::SmallVector<Expr *, 16> Vars;
8059 Vars.reserve(C->varlist_size());
8060 for (auto *VE : C->varlists()) {
8061 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8062 if (EVar.isInvalid())
8063 return nullptr;
8064 Vars.push_back(EVar.get());
8065 }
8066 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8067 C->getLParenLoc(), C->getLocEnd());
8068}
8069
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008070template <typename Derived>
8071OMPClause *
8072TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8073 llvm::SmallVector<Expr *, 16> Vars;
8074 Vars.reserve(C->varlist_size());
8075 for (auto *VE : C->varlists()) {
8076 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8077 if (EVar.isInvalid())
8078 return nullptr;
8079 Vars.push_back(EVar.get());
8080 }
8081 return getDerived().RebuildOMPDependClause(
8082 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8083 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8084}
8085
Michael Wonge710d542015-08-07 16:16:36 +00008086template <typename Derived>
8087OMPClause *
8088TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8089 ExprResult E = getDerived().TransformExpr(C->getDevice());
8090 if (E.isInvalid())
8091 return nullptr;
8092 return getDerived().RebuildOMPDeviceClause(
8093 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8094}
8095
Kelvin Li0bff7af2015-11-23 05:32:03 +00008096template <typename Derived>
8097OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8098 llvm::SmallVector<Expr *, 16> Vars;
8099 Vars.reserve(C->varlist_size());
8100 for (auto *VE : C->varlists()) {
8101 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8102 if (EVar.isInvalid())
8103 return nullptr;
8104 Vars.push_back(EVar.get());
8105 }
8106 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008107 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8108 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8109 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008110}
8111
Kelvin Li099bb8c2015-11-24 20:50:12 +00008112template <typename Derived>
8113OMPClause *
8114TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8115 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8116 if (E.isInvalid())
8117 return nullptr;
8118 return getDerived().RebuildOMPNumTeamsClause(
8119 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8120}
8121
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008122template <typename Derived>
8123OMPClause *
8124TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8125 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8126 if (E.isInvalid())
8127 return nullptr;
8128 return getDerived().RebuildOMPThreadLimitClause(
8129 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8130}
8131
Alexey Bataeva0569352015-12-01 10:17:31 +00008132template <typename Derived>
8133OMPClause *
8134TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8135 ExprResult E = getDerived().TransformExpr(C->getPriority());
8136 if (E.isInvalid())
8137 return nullptr;
8138 return getDerived().RebuildOMPPriorityClause(
8139 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8140}
8141
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008142template <typename Derived>
8143OMPClause *
8144TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8145 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8146 if (E.isInvalid())
8147 return nullptr;
8148 return getDerived().RebuildOMPGrainsizeClause(
8149 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8150}
8151
Alexey Bataev382967a2015-12-08 12:06:20 +00008152template <typename Derived>
8153OMPClause *
8154TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8155 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8156 if (E.isInvalid())
8157 return nullptr;
8158 return getDerived().RebuildOMPNumTasksClause(
8159 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8160}
8161
Alexey Bataev28c75412015-12-15 08:19:24 +00008162template <typename Derived>
8163OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8164 ExprResult E = getDerived().TransformExpr(C->getHint());
8165 if (E.isInvalid())
8166 return nullptr;
8167 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8168 C->getLParenLoc(), C->getLocEnd());
8169}
8170
Carlo Bertollib4adf552016-01-15 18:50:31 +00008171template <typename Derived>
8172OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8173 OMPDistScheduleClause *C) {
8174 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8175 if (E.isInvalid())
8176 return nullptr;
8177 return getDerived().RebuildOMPDistScheduleClause(
8178 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8179 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8180}
8181
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008182template <typename Derived>
8183OMPClause *
8184TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8185 return C;
8186}
8187
Samuel Antao661c0902016-05-26 17:39:58 +00008188template <typename Derived>
8189OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8190 llvm::SmallVector<Expr *, 16> Vars;
8191 Vars.reserve(C->varlist_size());
8192 for (auto *VE : C->varlists()) {
8193 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8194 if (EVar.isInvalid())
8195 return 0;
8196 Vars.push_back(EVar.get());
8197 }
8198 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8199 C->getLParenLoc(), C->getLocEnd());
8200}
8201
Samuel Antaoec172c62016-05-26 17:49:04 +00008202template <typename Derived>
8203OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8204 llvm::SmallVector<Expr *, 16> Vars;
8205 Vars.reserve(C->varlist_size());
8206 for (auto *VE : C->varlists()) {
8207 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8208 if (EVar.isInvalid())
8209 return 0;
8210 Vars.push_back(EVar.get());
8211 }
8212 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8213 C->getLParenLoc(), C->getLocEnd());
8214}
8215
Carlo Bertolli2404b172016-07-13 15:37:16 +00008216template <typename Derived>
8217OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8218 OMPUseDevicePtrClause *C) {
8219 llvm::SmallVector<Expr *, 16> Vars;
8220 Vars.reserve(C->varlist_size());
8221 for (auto *VE : C->varlists()) {
8222 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8223 if (EVar.isInvalid())
8224 return nullptr;
8225 Vars.push_back(EVar.get());
8226 }
8227 return getDerived().RebuildOMPUseDevicePtrClause(
8228 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8229}
8230
Carlo Bertolli70594e92016-07-13 17:16:49 +00008231template <typename Derived>
8232OMPClause *
8233TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8234 llvm::SmallVector<Expr *, 16> Vars;
8235 Vars.reserve(C->varlist_size());
8236 for (auto *VE : C->varlists()) {
8237 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8238 if (EVar.isInvalid())
8239 return nullptr;
8240 Vars.push_back(EVar.get());
8241 }
8242 return getDerived().RebuildOMPIsDevicePtrClause(
8243 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8244}
8245
Douglas Gregorebe10102009-08-20 07:17:43 +00008246//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008247// Expression transformation
8248//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008251TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008252 if (!E->isTypeDependent())
8253 return E;
8254
8255 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8256 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008257}
Mike Stump11289f42009-09-09 15:08:12 +00008258
8259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008260ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008261TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008262 NestedNameSpecifierLoc QualifierLoc;
8263 if (E->getQualifierLoc()) {
8264 QualifierLoc
8265 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8266 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008267 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008268 }
John McCallce546572009-12-08 09:08:17 +00008269
8270 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008271 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8272 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008273 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008275
John McCall815039a2010-08-17 21:27:17 +00008276 DeclarationNameInfo NameInfo = E->getNameInfo();
8277 if (NameInfo.getName()) {
8278 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8279 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008280 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008281 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008282
8283 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008284 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008285 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008286 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008287 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008288
8289 // Mark it referenced in the new context regardless.
8290 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008291 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008292
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008293 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008294 }
John McCallce546572009-12-08 09:08:17 +00008295
Craig Topperc3ec1492014-05-26 06:22:03 +00008296 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008297 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008298 TemplateArgs = &TransArgs;
8299 TransArgs.setLAngleLoc(E->getLAngleLoc());
8300 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008301 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8302 E->getNumTemplateArgs(),
8303 TransArgs))
8304 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008305 }
8306
Chad Rosier1dcde962012-08-08 18:46:20 +00008307 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008308 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008309}
Mike Stump11289f42009-09-09 15:08:12 +00008310
Douglas Gregora16548e2009-08-11 05:31:07 +00008311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008313TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008314 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008315}
Mike Stump11289f42009-09-09 15:08:12 +00008316
Douglas Gregora16548e2009-08-11 05:31:07 +00008317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008319TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008320 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008321}
Mike Stump11289f42009-09-09 15:08:12 +00008322
Douglas Gregora16548e2009-08-11 05:31:07 +00008323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008325TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008326 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008327}
Mike Stump11289f42009-09-09 15:08:12 +00008328
Douglas Gregora16548e2009-08-11 05:31:07 +00008329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008330ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008331TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008332 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008333}
Mike Stump11289f42009-09-09 15:08:12 +00008334
Douglas Gregora16548e2009-08-11 05:31:07 +00008335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008336ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008337TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008338 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008339}
8340
8341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008342ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008343TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008344 if (FunctionDecl *FD = E->getDirectCallee())
8345 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008346 return SemaRef.MaybeBindToTemporary(E);
8347}
8348
8349template<typename Derived>
8350ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008351TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8352 ExprResult ControllingExpr =
8353 getDerived().TransformExpr(E->getControllingExpr());
8354 if (ControllingExpr.isInvalid())
8355 return ExprError();
8356
Chris Lattner01cf8db2011-07-20 06:58:45 +00008357 SmallVector<Expr *, 4> AssocExprs;
8358 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008359 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8360 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8361 if (TS) {
8362 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8363 if (!AssocType)
8364 return ExprError();
8365 AssocTypes.push_back(AssocType);
8366 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008367 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008368 }
8369
8370 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8371 if (AssocExpr.isInvalid())
8372 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008373 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008374 }
8375
8376 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8377 E->getDefaultLoc(),
8378 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008379 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008380 AssocTypes,
8381 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008382}
8383
8384template<typename Derived>
8385ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008386TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008387 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008388 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008390
Douglas Gregora16548e2009-08-11 05:31:07 +00008391 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008392 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008393
John McCallb268a282010-08-23 23:25:46 +00008394 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008395 E->getRParen());
8396}
8397
Richard Smithdb2630f2012-10-21 03:28:35 +00008398/// \brief The operand of a unary address-of operator has special rules: it's
8399/// allowed to refer to a non-static member of a class even if there's no 'this'
8400/// object available.
8401template<typename Derived>
8402ExprResult
8403TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8404 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008405 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008406 else
8407 return getDerived().TransformExpr(E);
8408}
8409
Mike Stump11289f42009-09-09 15:08:12 +00008410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008412TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008413 ExprResult SubExpr;
8414 if (E->getOpcode() == UO_AddrOf)
8415 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8416 else
8417 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008418 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008419 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008420
Douglas Gregora16548e2009-08-11 05:31:07 +00008421 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008422 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008423
Douglas Gregora16548e2009-08-11 05:31:07 +00008424 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8425 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008426 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008427}
Mike Stump11289f42009-09-09 15:08:12 +00008428
Douglas Gregora16548e2009-08-11 05:31:07 +00008429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008430ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008431TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8432 // Transform the type.
8433 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8434 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008435 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008436
Douglas Gregor882211c2010-04-28 22:16:22 +00008437 // Transform all of the components into components similar to what the
8438 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008439 // FIXME: It would be slightly more efficient in the non-dependent case to
8440 // just map FieldDecls, rather than requiring the rebuilder to look for
8441 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008442 // template code that we don't care.
8443 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008444 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008445 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008446 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008447 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008448 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008449 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008450 Comp.LocStart = ON.getSourceRange().getBegin();
8451 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008452 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008453 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008454 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008455 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008456 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008457 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008458
Douglas Gregor882211c2010-04-28 22:16:22 +00008459 ExprChanged = ExprChanged || Index.get() != FromIndex;
8460 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008461 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008462 break;
8463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008464
James Y Knight7281c352015-12-29 22:31:18 +00008465 case OffsetOfNode::Field:
8466 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008467 Comp.isBrackets = false;
8468 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008469 if (!Comp.U.IdentInfo)
8470 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008471
Douglas Gregor882211c2010-04-28 22:16:22 +00008472 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008473
James Y Knight7281c352015-12-29 22:31:18 +00008474 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008475 // Will be recomputed during the rebuild.
8476 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008478
Douglas Gregor882211c2010-04-28 22:16:22 +00008479 Components.push_back(Comp);
8480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008481
Douglas Gregor882211c2010-04-28 22:16:22 +00008482 // If nothing changed, retain the existing expression.
8483 if (!getDerived().AlwaysRebuild() &&
8484 Type == E->getTypeSourceInfo() &&
8485 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008486 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008487
Douglas Gregor882211c2010-04-28 22:16:22 +00008488 // Build a new offsetof expression.
8489 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008490 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008491}
8492
8493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008494ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008495TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008496 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008497 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008498 return E;
John McCall8d69a212010-11-15 23:31:06 +00008499}
8500
8501template<typename Derived>
8502ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008503TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8504 return E;
8505}
8506
8507template<typename Derived>
8508ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008509TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008510 // Rebuild the syntactic form. The original syntactic form has
8511 // opaque-value expressions in it, so strip those away and rebuild
8512 // the result. This is a really awful way of doing this, but the
8513 // better solution (rebuilding the semantic expressions and
8514 // rebinding OVEs as necessary) doesn't work; we'd need
8515 // TreeTransform to not strip away implicit conversions.
8516 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8517 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008518 if (result.isInvalid()) return ExprError();
8519
8520 // If that gives us a pseudo-object result back, the pseudo-object
8521 // expression must have been an lvalue-to-rvalue conversion which we
8522 // should reapply.
8523 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008524 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008525
8526 return result;
8527}
8528
8529template<typename Derived>
8530ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008531TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8532 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008533 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008534 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008535
John McCallbcd03502009-12-07 02:54:59 +00008536 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008537 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008539
John McCall4c98fd82009-11-04 07:28:41 +00008540 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008541 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008542
Peter Collingbournee190dee2011-03-11 19:24:49 +00008543 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8544 E->getKind(),
8545 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008546 }
Mike Stump11289f42009-09-09 15:08:12 +00008547
Eli Friedmane4f22df2012-02-29 04:03:55 +00008548 // C++0x [expr.sizeof]p1:
8549 // The operand is either an expression, which is an unevaluated operand
8550 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008551 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8552 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008553
Reid Kleckner32506ed2014-06-12 23:03:48 +00008554 // Try to recover if we have something like sizeof(T::X) where X is a type.
8555 // Notably, there must be *exactly* one set of parens if X is a type.
8556 TypeSourceInfo *RecoveryTSI = nullptr;
8557 ExprResult SubExpr;
8558 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8559 if (auto *DRE =
8560 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8561 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8562 PE, DRE, false, &RecoveryTSI);
8563 else
8564 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8565
8566 if (RecoveryTSI) {
8567 return getDerived().RebuildUnaryExprOrTypeTrait(
8568 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8569 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008571
Eli Friedmane4f22df2012-02-29 04:03:55 +00008572 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008573 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008574
Peter Collingbournee190dee2011-03-11 19:24:49 +00008575 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8576 E->getOperatorLoc(),
8577 E->getKind(),
8578 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008579}
Mike Stump11289f42009-09-09 15:08:12 +00008580
Douglas Gregora16548e2009-08-11 05:31:07 +00008581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008583TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008584 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008585 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008587
John McCalldadc5752010-08-24 06:29:42 +00008588 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008589 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008591
8592
Douglas Gregora16548e2009-08-11 05:31:07 +00008593 if (!getDerived().AlwaysRebuild() &&
8594 LHS.get() == E->getLHS() &&
8595 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008596 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008597
John McCallb268a282010-08-23 23:25:46 +00008598 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008599 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008600 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008601 E->getRBracketLoc());
8602}
Mike Stump11289f42009-09-09 15:08:12 +00008603
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008604template <typename Derived>
8605ExprResult
8606TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8607 ExprResult Base = getDerived().TransformExpr(E->getBase());
8608 if (Base.isInvalid())
8609 return ExprError();
8610
8611 ExprResult LowerBound;
8612 if (E->getLowerBound()) {
8613 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8614 if (LowerBound.isInvalid())
8615 return ExprError();
8616 }
8617
8618 ExprResult Length;
8619 if (E->getLength()) {
8620 Length = getDerived().TransformExpr(E->getLength());
8621 if (Length.isInvalid())
8622 return ExprError();
8623 }
8624
8625 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8626 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8627 return E;
8628
8629 return getDerived().RebuildOMPArraySectionExpr(
8630 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8631 Length.get(), E->getRBracketLoc());
8632}
8633
Mike Stump11289f42009-09-09 15:08:12 +00008634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008635ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008636TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008637 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008638 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008640 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008641
8642 // Transform arguments.
8643 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008644 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008645 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008646 &ArgChanged))
8647 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008648
Douglas Gregora16548e2009-08-11 05:31:07 +00008649 if (!getDerived().AlwaysRebuild() &&
8650 Callee.get() == E->getCallee() &&
8651 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008652 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008653
Douglas Gregora16548e2009-08-11 05:31:07 +00008654 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008655 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008656 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008657 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008658 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008659 E->getRParenLoc());
8660}
Mike Stump11289f42009-09-09 15:08:12 +00008661
8662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008664TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008665 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008666 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008667 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008668
Douglas Gregorea972d32011-02-28 21:54:11 +00008669 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008670 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008671 QualifierLoc
8672 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008673
Douglas Gregorea972d32011-02-28 21:54:11 +00008674 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008675 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008676 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008677 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008678
Eli Friedman2cfcef62009-12-04 06:40:45 +00008679 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008680 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8681 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008684
John McCall16df1e52010-03-30 21:47:33 +00008685 NamedDecl *FoundDecl = E->getFoundDecl();
8686 if (FoundDecl == E->getMemberDecl()) {
8687 FoundDecl = Member;
8688 } else {
8689 FoundDecl = cast_or_null<NamedDecl>(
8690 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8691 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008692 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008693 }
8694
Douglas Gregora16548e2009-08-11 05:31:07 +00008695 if (!getDerived().AlwaysRebuild() &&
8696 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008697 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008698 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008699 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008700 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008701
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008702 // Mark it referenced in the new context regardless.
8703 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008704 SemaRef.MarkMemberReferenced(E);
8705
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008706 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008707 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008708
John McCall6b51f282009-11-23 01:53:49 +00008709 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008710 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008711 TransArgs.setLAngleLoc(E->getLAngleLoc());
8712 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008713 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8714 E->getNumTemplateArgs(),
8715 TransArgs))
8716 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008718
Douglas Gregora16548e2009-08-11 05:31:07 +00008719 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008720 SourceLocation FakeOperatorLoc =
8721 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008722
John McCall38836f02010-01-15 08:34:02 +00008723 // FIXME: to do this check properly, we will need to preserve the
8724 // first-qualifier-in-scope here, just in case we had a dependent
8725 // base (and therefore couldn't do the check) and a
8726 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008727 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008728
John McCallb268a282010-08-23 23:25:46 +00008729 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008730 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008731 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008732 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008733 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008734 Member,
John McCall16df1e52010-03-30 21:47:33 +00008735 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008736 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008737 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008738 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008739}
Mike Stump11289f42009-09-09 15:08:12 +00008740
Douglas Gregora16548e2009-08-11 05:31:07 +00008741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008743TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008744 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008745 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008747
John McCalldadc5752010-08-24 06:29:42 +00008748 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008749 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008751
Douglas Gregora16548e2009-08-11 05:31:07 +00008752 if (!getDerived().AlwaysRebuild() &&
8753 LHS.get() == E->getLHS() &&
8754 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008755 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008756
Lang Hames5de91cc2012-10-02 04:45:10 +00008757 Sema::FPContractStateRAII FPContractState(getSema());
8758 getSema().FPFeatures.fp_contract = E->isFPContractable();
8759
Douglas Gregora16548e2009-08-11 05:31:07 +00008760 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008761 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008762}
8763
Mike Stump11289f42009-09-09 15:08:12 +00008764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008765ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008766TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008767 CompoundAssignOperator *E) {
8768 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008769}
Mike Stump11289f42009-09-09 15:08:12 +00008770
Douglas Gregora16548e2009-08-11 05:31:07 +00008771template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008772ExprResult TreeTransform<Derived>::
8773TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8774 // Just rebuild the common and RHS expressions and see whether we
8775 // get any changes.
8776
8777 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8778 if (commonExpr.isInvalid())
8779 return ExprError();
8780
8781 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8782 if (rhs.isInvalid())
8783 return ExprError();
8784
8785 if (!getDerived().AlwaysRebuild() &&
8786 commonExpr.get() == e->getCommon() &&
8787 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008788 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008789
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008790 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008791 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008792 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008793 e->getColonLoc(),
8794 rhs.get());
8795}
8796
8797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008799TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008800 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008801 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008803
John McCalldadc5752010-08-24 06:29:42 +00008804 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008805 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008807
John McCalldadc5752010-08-24 06:29:42 +00008808 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008809 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008811
Douglas Gregora16548e2009-08-11 05:31:07 +00008812 if (!getDerived().AlwaysRebuild() &&
8813 Cond.get() == E->getCond() &&
8814 LHS.get() == E->getLHS() &&
8815 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008816 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008817
John McCallb268a282010-08-23 23:25:46 +00008818 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008819 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008820 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008821 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008822 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008823}
Mike Stump11289f42009-09-09 15:08:12 +00008824
8825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008826ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008827TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008828 // Implicit casts are eliminated during transformation, since they
8829 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008830 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008831}
Mike Stump11289f42009-09-09 15:08:12 +00008832
Douglas Gregora16548e2009-08-11 05:31:07 +00008833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008835TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008836 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8837 if (!Type)
8838 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008839
John McCalldadc5752010-08-24 06:29:42 +00008840 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008841 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008844
Douglas Gregora16548e2009-08-11 05:31:07 +00008845 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008846 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008847 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008848 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008849
John McCall97513962010-01-15 18:39:57 +00008850 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008851 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008852 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008853 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008854}
Mike Stump11289f42009-09-09 15:08:12 +00008855
Douglas Gregora16548e2009-08-11 05:31:07 +00008856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008858TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008859 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8860 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8861 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008863
John McCalldadc5752010-08-24 06:29:42 +00008864 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008865 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008867
Douglas Gregora16548e2009-08-11 05:31:07 +00008868 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008869 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008870 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008871 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008872
John McCall5d7aa7f2010-01-19 22:33:45 +00008873 // Note: the expression type doesn't necessarily match the
8874 // type-as-written, but that's okay, because it should always be
8875 // derivable from the initializer.
8876
John McCalle15bbff2010-01-18 19:35:47 +00008877 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008878 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008879 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008880}
Mike Stump11289f42009-09-09 15:08:12 +00008881
Douglas Gregora16548e2009-08-11 05:31:07 +00008882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008883ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008884TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008885 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008886 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008887 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008888
Douglas Gregora16548e2009-08-11 05:31:07 +00008889 if (!getDerived().AlwaysRebuild() &&
8890 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008891 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008892
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008894 SourceLocation FakeOperatorLoc =
8895 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008896 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008897 E->getAccessorLoc(),
8898 E->getAccessor());
8899}
Mike Stump11289f42009-09-09 15:08:12 +00008900
Douglas Gregora16548e2009-08-11 05:31:07 +00008901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008902ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008903TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008904 if (InitListExpr *Syntactic = E->getSyntacticForm())
8905 E = Syntactic;
8906
Douglas Gregora16548e2009-08-11 05:31:07 +00008907 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008908
Benjamin Kramerf0623432012-08-23 22:51:59 +00008909 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008910 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008911 Inits, &InitChanged))
8912 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008913
Richard Smith520449d2015-02-05 06:15:50 +00008914 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8915 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8916 // in some cases. We can't reuse it in general, because the syntactic and
8917 // semantic forms are linked, and we can't know that semantic form will
8918 // match even if the syntactic form does.
8919 }
Mike Stump11289f42009-09-09 15:08:12 +00008920
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008921 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008922 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008923}
Mike Stump11289f42009-09-09 15:08:12 +00008924
Douglas Gregora16548e2009-08-11 05:31:07 +00008925template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008926ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008927TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008928 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008929
Douglas Gregorebe10102009-08-20 07:17:43 +00008930 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008931 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008932 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008934
Douglas Gregorebe10102009-08-20 07:17:43 +00008935 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008936 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008937 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008938 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8939 if (D.isFieldDesignator()) {
8940 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8941 D.getDotLoc(),
8942 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00008943 if (D.getField()) {
8944 FieldDecl *Field = cast_or_null<FieldDecl>(
8945 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
8946 if (Field != D.getField())
8947 // Rebuild the expression when the transformed FieldDecl is
8948 // different to the already assigned FieldDecl.
8949 ExprChanged = true;
8950 } else {
8951 // Ensure that the designator expression is rebuilt when there isn't
8952 // a resolved FieldDecl in the designator as we don't want to assign
8953 // a FieldDecl to a pattern designator that will be instantiated again.
8954 ExprChanged = true;
8955 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008956 continue;
8957 }
Mike Stump11289f42009-09-09 15:08:12 +00008958
David Majnemerf7e36092016-06-23 00:15:04 +00008959 if (D.isArrayDesignator()) {
8960 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008961 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008963
David Majnemerf7e36092016-06-23 00:15:04 +00008964 Desig.AddDesignator(
8965 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008966
David Majnemerf7e36092016-06-23 00:15:04 +00008967 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008968 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008969 continue;
8970 }
Mike Stump11289f42009-09-09 15:08:12 +00008971
David Majnemerf7e36092016-06-23 00:15:04 +00008972 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008973 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008974 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008975 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008977
David Majnemerf7e36092016-06-23 00:15:04 +00008978 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008979 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008981
8982 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008983 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008984 D.getLBracketLoc(),
8985 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008986
David Majnemerf7e36092016-06-23 00:15:04 +00008987 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8988 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008989
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008990 ArrayExprs.push_back(Start.get());
8991 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008992 }
Mike Stump11289f42009-09-09 15:08:12 +00008993
Douglas Gregora16548e2009-08-11 05:31:07 +00008994 if (!getDerived().AlwaysRebuild() &&
8995 Init.get() == E->getInit() &&
8996 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008997 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008998
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008999 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009000 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009001 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009002}
Mike Stump11289f42009-09-09 15:08:12 +00009003
Yunzhong Gaocb779302015-06-10 00:27:52 +00009004// Seems that if TransformInitListExpr() only works on the syntactic form of an
9005// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9006template<typename Derived>
9007ExprResult
9008TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9009 DesignatedInitUpdateExpr *E) {
9010 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9011 "initializer");
9012 return ExprError();
9013}
9014
9015template<typename Derived>
9016ExprResult
9017TreeTransform<Derived>::TransformNoInitExpr(
9018 NoInitExpr *E) {
9019 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9020 return ExprError();
9021}
9022
Douglas Gregora16548e2009-08-11 05:31:07 +00009023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009024ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009025TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009026 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009027 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009028
Douglas Gregor3da3c062009-10-28 00:29:27 +00009029 // FIXME: Will we ever have proper type location here? Will we actually
9030 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009031 QualType T = getDerived().TransformType(E->getType());
9032 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009033 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009034
Douglas Gregora16548e2009-08-11 05:31:07 +00009035 if (!getDerived().AlwaysRebuild() &&
9036 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009037 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009038
Douglas Gregora16548e2009-08-11 05:31:07 +00009039 return getDerived().RebuildImplicitValueInitExpr(T);
9040}
Mike Stump11289f42009-09-09 15:08:12 +00009041
Douglas Gregora16548e2009-08-11 05:31:07 +00009042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009044TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009045 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9046 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009048
John McCalldadc5752010-08-24 06:29:42 +00009049 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009050 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009052
Douglas Gregora16548e2009-08-11 05:31:07 +00009053 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009054 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009056 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009057
John McCallb268a282010-08-23 23:25:46 +00009058 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009059 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009060}
9061
9062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009063ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009064TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009065 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009066 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009067 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9068 &ArgumentChanged))
9069 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009070
Douglas Gregora16548e2009-08-11 05:31:07 +00009071 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009072 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009073 E->getRParenLoc());
9074}
Mike Stump11289f42009-09-09 15:08:12 +00009075
Douglas Gregora16548e2009-08-11 05:31:07 +00009076/// \brief Transform an address-of-label expression.
9077///
9078/// By default, the transformation of an address-of-label expression always
9079/// rebuilds the expression, so that the label identifier can be resolved to
9080/// the corresponding label statement by semantic analysis.
9081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009082ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009083TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009084 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9085 E->getLabel());
9086 if (!LD)
9087 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009088
Douglas Gregora16548e2009-08-11 05:31:07 +00009089 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009090 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009091}
Mike Stump11289f42009-09-09 15:08:12 +00009092
9093template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009095TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009096 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009097 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009098 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009099 if (SubStmt.isInvalid()) {
9100 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009101 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009102 }
Mike Stump11289f42009-09-09 15:08:12 +00009103
Douglas Gregora16548e2009-08-11 05:31:07 +00009104 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009105 SubStmt.get() == E->getSubStmt()) {
9106 // Calling this an 'error' is unintuitive, but it does the right thing.
9107 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009108 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009109 }
Mike Stump11289f42009-09-09 15:08:12 +00009110
9111 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009112 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009113 E->getRParenLoc());
9114}
Mike Stump11289f42009-09-09 15:08:12 +00009115
Douglas Gregora16548e2009-08-11 05:31:07 +00009116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009118TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009119 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009120 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009122
John McCalldadc5752010-08-24 06:29:42 +00009123 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009126
John McCalldadc5752010-08-24 06:29:42 +00009127 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009128 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009130
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 if (!getDerived().AlwaysRebuild() &&
9132 Cond.get() == E->getCond() &&
9133 LHS.get() == E->getLHS() &&
9134 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009135 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009136
Douglas Gregora16548e2009-08-11 05:31:07 +00009137 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009138 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009139 E->getRParenLoc());
9140}
Mike Stump11289f42009-09-09 15:08:12 +00009141
Douglas Gregora16548e2009-08-11 05:31:07 +00009142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009144TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009145 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009146}
9147
9148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009150TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009151 switch (E->getOperator()) {
9152 case OO_New:
9153 case OO_Delete:
9154 case OO_Array_New:
9155 case OO_Array_Delete:
9156 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009157
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009158 case OO_Call: {
9159 // This is a call to an object's operator().
9160 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9161
9162 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009163 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009164 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009165 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009166
9167 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009168 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9169 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009170
9171 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009172 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009173 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009174 Args))
9175 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009176
John McCallb268a282010-08-23 23:25:46 +00009177 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009178 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009179 E->getLocEnd());
9180 }
9181
9182#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9183 case OO_##Name:
9184#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9185#include "clang/Basic/OperatorKinds.def"
9186 case OO_Subscript:
9187 // Handled below.
9188 break;
9189
9190 case OO_Conditional:
9191 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009192
9193 case OO_None:
9194 case NUM_OVERLOADED_OPERATORS:
9195 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009196 }
9197
John McCalldadc5752010-08-24 06:29:42 +00009198 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009199 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009200 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009201
Richard Smithdb2630f2012-10-21 03:28:35 +00009202 ExprResult First;
9203 if (E->getOperator() == OO_Amp)
9204 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9205 else
9206 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009207 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009208 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009209
John McCalldadc5752010-08-24 06:29:42 +00009210 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009211 if (E->getNumArgs() == 2) {
9212 Second = getDerived().TransformExpr(E->getArg(1));
9213 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009214 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009215 }
Mike Stump11289f42009-09-09 15:08:12 +00009216
Douglas Gregora16548e2009-08-11 05:31:07 +00009217 if (!getDerived().AlwaysRebuild() &&
9218 Callee.get() == E->getCallee() &&
9219 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009220 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009221 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009222
Lang Hames5de91cc2012-10-02 04:45:10 +00009223 Sema::FPContractStateRAII FPContractState(getSema());
9224 getSema().FPFeatures.fp_contract = E->isFPContractable();
9225
Douglas Gregora16548e2009-08-11 05:31:07 +00009226 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9227 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009228 Callee.get(),
9229 First.get(),
9230 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009231}
Mike Stump11289f42009-09-09 15:08:12 +00009232
Douglas Gregora16548e2009-08-11 05:31:07 +00009233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009235TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9236 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009237}
Mike Stump11289f42009-09-09 15:08:12 +00009238
Douglas Gregora16548e2009-08-11 05:31:07 +00009239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009240ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009241TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9242 // Transform the callee.
9243 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9244 if (Callee.isInvalid())
9245 return ExprError();
9246
9247 // Transform exec config.
9248 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9249 if (EC.isInvalid())
9250 return ExprError();
9251
9252 // Transform arguments.
9253 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009254 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009255 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009256 &ArgChanged))
9257 return ExprError();
9258
9259 if (!getDerived().AlwaysRebuild() &&
9260 Callee.get() == E->getCallee() &&
9261 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009262 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009263
9264 // FIXME: Wrong source location information for the '('.
9265 SourceLocation FakeLParenLoc
9266 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9267 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009268 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009269 E->getRParenLoc(), EC.get());
9270}
9271
9272template<typename Derived>
9273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009274TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009275 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9276 if (!Type)
9277 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009278
John McCalldadc5752010-08-24 06:29:42 +00009279 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009280 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009281 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009283
Douglas Gregora16548e2009-08-11 05:31:07 +00009284 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009285 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009286 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009287 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009288 return getDerived().RebuildCXXNamedCastExpr(
9289 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9290 Type, E->getAngleBrackets().getEnd(),
9291 // FIXME. this should be '(' location
9292 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009293}
Mike Stump11289f42009-09-09 15:08:12 +00009294
Douglas Gregora16548e2009-08-11 05:31:07 +00009295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009297TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9298 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009299}
Mike Stump11289f42009-09-09 15:08:12 +00009300
9301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009303TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9304 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009305}
9306
Douglas Gregora16548e2009-08-11 05:31:07 +00009307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009308ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009309TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009310 CXXReinterpretCastExpr *E) {
9311 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009312}
Mike Stump11289f42009-09-09 15:08:12 +00009313
Douglas Gregora16548e2009-08-11 05:31:07 +00009314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009316TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9317 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009318}
Mike Stump11289f42009-09-09 15:08:12 +00009319
Douglas Gregora16548e2009-08-11 05:31:07 +00009320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009321ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009322TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009323 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009324 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9325 if (!Type)
9326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009327
John McCalldadc5752010-08-24 06:29:42 +00009328 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009329 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009330 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009331 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009332
Douglas Gregora16548e2009-08-11 05:31:07 +00009333 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009334 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009335 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009336 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009337
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009338 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009339 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009340 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009341 E->getRParenLoc());
9342}
Mike Stump11289f42009-09-09 15:08:12 +00009343
Douglas Gregora16548e2009-08-11 05:31:07 +00009344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009346TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009347 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009348 TypeSourceInfo *TInfo
9349 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9350 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009352
Douglas Gregora16548e2009-08-11 05:31:07 +00009353 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009354 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009355 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009356
Douglas Gregor9da64192010-04-26 22:37:10 +00009357 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9358 E->getLocStart(),
9359 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009360 E->getLocEnd());
9361 }
Mike Stump11289f42009-09-09 15:08:12 +00009362
Eli Friedman456f0182012-01-20 01:26:23 +00009363 // We don't know whether the subexpression is potentially evaluated until
9364 // after we perform semantic analysis. We speculatively assume it is
9365 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009366 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009367 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9368 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009369
John McCalldadc5752010-08-24 06:29:42 +00009370 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009371 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009373
Douglas Gregora16548e2009-08-11 05:31:07 +00009374 if (!getDerived().AlwaysRebuild() &&
9375 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009376 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009377
Douglas Gregor9da64192010-04-26 22:37:10 +00009378 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9379 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009380 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009381 E->getLocEnd());
9382}
9383
9384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009385ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009386TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9387 if (E->isTypeOperand()) {
9388 TypeSourceInfo *TInfo
9389 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9390 if (!TInfo)
9391 return ExprError();
9392
9393 if (!getDerived().AlwaysRebuild() &&
9394 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009395 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009396
Douglas Gregor69735112011-03-06 17:40:41 +00009397 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009398 E->getLocStart(),
9399 TInfo,
9400 E->getLocEnd());
9401 }
9402
Francois Pichet9f4f2072010-09-08 12:20:18 +00009403 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9404
9405 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9406 if (SubExpr.isInvalid())
9407 return ExprError();
9408
9409 if (!getDerived().AlwaysRebuild() &&
9410 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009411 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009412
9413 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9414 E->getLocStart(),
9415 SubExpr.get(),
9416 E->getLocEnd());
9417}
9418
9419template<typename Derived>
9420ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009421TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009422 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009423}
Mike Stump11289f42009-09-09 15:08:12 +00009424
Douglas Gregora16548e2009-08-11 05:31:07 +00009425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009426ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009427TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009428 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009429 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009430}
Mike Stump11289f42009-09-09 15:08:12 +00009431
Douglas Gregora16548e2009-08-11 05:31:07 +00009432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009434TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009435 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009436
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009437 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9438 // Make sure that we capture 'this'.
9439 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009440 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009442
Douglas Gregorb15af892010-01-07 23:12:05 +00009443 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009444}
Mike Stump11289f42009-09-09 15:08:12 +00009445
Douglas Gregora16548e2009-08-11 05:31:07 +00009446template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009447ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009448TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009449 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009450 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009452
Douglas Gregora16548e2009-08-11 05:31:07 +00009453 if (!getDerived().AlwaysRebuild() &&
9454 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009455 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009456
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009457 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9458 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009459}
Mike Stump11289f42009-09-09 15:08:12 +00009460
Douglas Gregora16548e2009-08-11 05:31:07 +00009461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009463TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009464 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009465 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9466 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009467 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009468 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009469
Chandler Carruth794da4c2010-02-08 06:42:49 +00009470 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009471 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009472 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009473
Douglas Gregor033f6752009-12-23 23:03:06 +00009474 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009475}
Mike Stump11289f42009-09-09 15:08:12 +00009476
Douglas Gregora16548e2009-08-11 05:31:07 +00009477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009478ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009479TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9480 FieldDecl *Field
9481 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9482 E->getField()));
9483 if (!Field)
9484 return ExprError();
9485
9486 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009487 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009488
9489 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9490}
9491
9492template<typename Derived>
9493ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009494TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9495 CXXScalarValueInitExpr *E) {
9496 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9497 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009498 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009499
Douglas Gregora16548e2009-08-11 05:31:07 +00009500 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009501 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009502 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009503
Chad Rosier1dcde962012-08-08 18:46:20 +00009504 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009505 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009506 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009507}
Mike Stump11289f42009-09-09 15:08:12 +00009508
Douglas Gregora16548e2009-08-11 05:31:07 +00009509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009510ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009511TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009512 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009513 TypeSourceInfo *AllocTypeInfo
9514 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9515 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009517
Douglas Gregora16548e2009-08-11 05:31:07 +00009518 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009519 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009520 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009521 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009522
Douglas Gregora16548e2009-08-11 05:31:07 +00009523 // Transform the placement arguments (if any).
9524 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009525 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009526 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009527 E->getNumPlacementArgs(), true,
9528 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009529 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009530
Sebastian Redl6047f072012-02-16 12:22:20 +00009531 // Transform the initializer (if any).
9532 Expr *OldInit = E->getInitializer();
9533 ExprResult NewInit;
9534 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009535 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009536 if (NewInit.isInvalid())
9537 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009538
Sebastian Redl6047f072012-02-16 12:22:20 +00009539 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009540 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009541 if (E->getOperatorNew()) {
9542 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009543 getDerived().TransformDecl(E->getLocStart(),
9544 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009545 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009546 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009547 }
9548
Craig Topperc3ec1492014-05-26 06:22:03 +00009549 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009550 if (E->getOperatorDelete()) {
9551 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009552 getDerived().TransformDecl(E->getLocStart(),
9553 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009554 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009555 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009556 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009557
Douglas Gregora16548e2009-08-11 05:31:07 +00009558 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009559 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009560 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009561 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009562 OperatorNew == E->getOperatorNew() &&
9563 OperatorDelete == E->getOperatorDelete() &&
9564 !ArgumentChanged) {
9565 // Mark any declarations we need as referenced.
9566 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009567 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009568 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009569 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009570 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009571
Sebastian Redl6047f072012-02-16 12:22:20 +00009572 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009573 QualType ElementType
9574 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9575 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9576 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9577 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009578 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009579 }
9580 }
9581 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009582
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009583 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009584 }
Mike Stump11289f42009-09-09 15:08:12 +00009585
Douglas Gregor0744ef62010-09-07 21:49:58 +00009586 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009587 if (!ArraySize.get()) {
9588 // If no array size was specified, but the new expression was
9589 // instantiated with an array type (e.g., "new T" where T is
9590 // instantiated with "int[4]"), extract the outer bound from the
9591 // array type as our array size. We do this with constant and
9592 // dependently-sized array types.
9593 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9594 if (!ArrayT) {
9595 // Do nothing
9596 } else if (const ConstantArrayType *ConsArrayT
9597 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009598 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9599 SemaRef.Context.getSizeType(),
9600 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009601 AllocType = ConsArrayT->getElementType();
9602 } else if (const DependentSizedArrayType *DepArrayT
9603 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9604 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009605 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009606 AllocType = DepArrayT->getElementType();
9607 }
9608 }
9609 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009610
Douglas Gregora16548e2009-08-11 05:31:07 +00009611 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9612 E->isGlobalNew(),
9613 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009614 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009615 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009616 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009617 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009618 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009619 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009620 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009621 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009622}
Mike Stump11289f42009-09-09 15:08:12 +00009623
Douglas Gregora16548e2009-08-11 05:31:07 +00009624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009626TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009627 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009628 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009630
Douglas Gregord2d9da02010-02-26 00:38:10 +00009631 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009632 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009633 if (E->getOperatorDelete()) {
9634 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009635 getDerived().TransformDecl(E->getLocStart(),
9636 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009637 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009638 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009640
Douglas Gregora16548e2009-08-11 05:31:07 +00009641 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009642 Operand.get() == E->getArgument() &&
9643 OperatorDelete == E->getOperatorDelete()) {
9644 // Mark any declarations we need as referenced.
9645 // FIXME: instantiation-specific.
9646 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009647 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009648
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009649 if (!E->getArgument()->isTypeDependent()) {
9650 QualType Destroyed = SemaRef.Context.getBaseElementType(
9651 E->getDestroyedType());
9652 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9653 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009654 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009655 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009656 }
9657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009658
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009659 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009660 }
Mike Stump11289f42009-09-09 15:08:12 +00009661
Douglas Gregora16548e2009-08-11 05:31:07 +00009662 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9663 E->isGlobalDelete(),
9664 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009665 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009666}
Mike Stump11289f42009-09-09 15:08:12 +00009667
Douglas Gregora16548e2009-08-11 05:31:07 +00009668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009669ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009670TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009671 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009672 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009673 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009674 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009675
John McCallba7bf592010-08-24 05:47:05 +00009676 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009677 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009678 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009679 E->getOperatorLoc(),
9680 E->isArrow()? tok::arrow : tok::period,
9681 ObjectTypePtr,
9682 MayBePseudoDestructor);
9683 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009684 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009685
John McCallba7bf592010-08-24 05:47:05 +00009686 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009687 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9688 if (QualifierLoc) {
9689 QualifierLoc
9690 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9691 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009692 return ExprError();
9693 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009694 CXXScopeSpec SS;
9695 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009696
Douglas Gregor678f90d2010-02-25 01:56:36 +00009697 PseudoDestructorTypeStorage Destroyed;
9698 if (E->getDestroyedTypeInfo()) {
9699 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009700 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009701 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009702 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009703 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009704 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009705 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009706 // We aren't likely to be able to resolve the identifier down to a type
9707 // now anyway, so just retain the identifier.
9708 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9709 E->getDestroyedTypeLoc());
9710 } else {
9711 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009712 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009713 *E->getDestroyedTypeIdentifier(),
9714 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009715 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009716 SS, ObjectTypePtr,
9717 false);
9718 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009719 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009720
Douglas Gregor678f90d2010-02-25 01:56:36 +00009721 Destroyed
9722 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9723 E->getDestroyedTypeLoc());
9724 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009725
Craig Topperc3ec1492014-05-26 06:22:03 +00009726 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009727 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009728 CXXScopeSpec EmptySS;
9729 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009730 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009731 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009732 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009734
John McCallb268a282010-08-23 23:25:46 +00009735 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009736 E->getOperatorLoc(),
9737 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009738 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009739 ScopeTypeInfo,
9740 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009741 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009742 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009743}
Mike Stump11289f42009-09-09 15:08:12 +00009744
Douglas Gregorad8a3362009-09-04 17:36:40 +00009745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009746ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009747TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009748 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009749 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9750 Sema::LookupOrdinaryName);
9751
9752 // Transform all the decls.
9753 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9754 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009755 NamedDecl *InstD = static_cast<NamedDecl*>(
9756 getDerived().TransformDecl(Old->getNameLoc(),
9757 *I));
John McCall84d87672009-12-10 09:41:52 +00009758 if (!InstD) {
9759 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9760 // This can happen because of dependent hiding.
9761 if (isa<UsingShadowDecl>(*I))
9762 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009763 else {
9764 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009765 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009766 }
John McCall84d87672009-12-10 09:41:52 +00009767 }
John McCalle66edc12009-11-24 19:00:30 +00009768
9769 // Expand using declarations.
9770 if (isa<UsingDecl>(InstD)) {
9771 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009772 for (auto *I : UD->shadows())
9773 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009774 continue;
9775 }
9776
9777 R.addDecl(InstD);
9778 }
9779
9780 // Resolve a kind, but don't do any further analysis. If it's
9781 // ambiguous, the callee needs to deal with it.
9782 R.resolveKind();
9783
9784 // Rebuild the nested-name qualifier, if present.
9785 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009786 if (Old->getQualifierLoc()) {
9787 NestedNameSpecifierLoc QualifierLoc
9788 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9789 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009790 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009791
Douglas Gregor0da1d432011-02-28 20:01:57 +00009792 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009793 }
9794
Douglas Gregor9262f472010-04-27 18:19:34 +00009795 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009796 CXXRecordDecl *NamingClass
9797 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9798 Old->getNameLoc(),
9799 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009800 if (!NamingClass) {
9801 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009802 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009804
Douglas Gregorda7be082010-04-27 16:10:10 +00009805 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009806 }
9807
Abramo Bagnara7945c982012-01-27 09:46:47 +00009808 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9809
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009810 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009811 // it's a normal declaration name or member reference.
9812 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9813 NamedDecl *D = R.getAsSingle<NamedDecl>();
9814 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9815 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9816 // give a good diagnostic.
9817 if (D && D->isCXXInstanceMember()) {
9818 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9819 /*TemplateArgs=*/nullptr,
9820 /*Scope=*/nullptr);
9821 }
9822
John McCalle66edc12009-11-24 19:00:30 +00009823 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009824 }
John McCalle66edc12009-11-24 19:00:30 +00009825
9826 // If we have template arguments, rebuild them, then rebuild the
9827 // templateid expression.
9828 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009829 if (Old->hasExplicitTemplateArgs() &&
9830 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009831 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009832 TransArgs)) {
9833 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009834 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009835 }
John McCalle66edc12009-11-24 19:00:30 +00009836
Abramo Bagnara7945c982012-01-27 09:46:47 +00009837 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009838 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009839}
Mike Stump11289f42009-09-09 15:08:12 +00009840
Douglas Gregora16548e2009-08-11 05:31:07 +00009841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009842ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009843TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9844 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009845 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009846 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9847 TypeSourceInfo *From = E->getArg(I);
9848 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009849 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009850 TypeLocBuilder TLB;
9851 TLB.reserve(FromTL.getFullDataSize());
9852 QualType To = getDerived().TransformType(TLB, FromTL);
9853 if (To.isNull())
9854 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009855
Douglas Gregor29c42f22012-02-24 07:38:34 +00009856 if (To == From->getType())
9857 Args.push_back(From);
9858 else {
9859 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9860 ArgChanged = true;
9861 }
9862 continue;
9863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009864
Douglas Gregor29c42f22012-02-24 07:38:34 +00009865 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009866
Douglas Gregor29c42f22012-02-24 07:38:34 +00009867 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009868 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009869 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9870 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9871 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009872
Douglas Gregor29c42f22012-02-24 07:38:34 +00009873 // Determine whether the set of unexpanded parameter packs can and should
9874 // be expanded.
9875 bool Expand = true;
9876 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009877 Optional<unsigned> OrigNumExpansions =
9878 ExpansionTL.getTypePtr()->getNumExpansions();
9879 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009880 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9881 PatternTL.getSourceRange(),
9882 Unexpanded,
9883 Expand, RetainExpansion,
9884 NumExpansions))
9885 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009886
Douglas Gregor29c42f22012-02-24 07:38:34 +00009887 if (!Expand) {
9888 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009889 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009890 // expansion.
9891 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009892
Douglas Gregor29c42f22012-02-24 07:38:34 +00009893 TypeLocBuilder TLB;
9894 TLB.reserve(From->getTypeLoc().getFullDataSize());
9895
9896 QualType To = getDerived().TransformType(TLB, PatternTL);
9897 if (To.isNull())
9898 return ExprError();
9899
Chad Rosier1dcde962012-08-08 18:46:20 +00009900 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009901 PatternTL.getSourceRange(),
9902 ExpansionTL.getEllipsisLoc(),
9903 NumExpansions);
9904 if (To.isNull())
9905 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009906
Douglas Gregor29c42f22012-02-24 07:38:34 +00009907 PackExpansionTypeLoc ToExpansionTL
9908 = TLB.push<PackExpansionTypeLoc>(To);
9909 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9910 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9911 continue;
9912 }
9913
9914 // Expand the pack expansion by substituting for each argument in the
9915 // pack(s).
9916 for (unsigned I = 0; I != *NumExpansions; ++I) {
9917 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9918 TypeLocBuilder TLB;
9919 TLB.reserve(PatternTL.getFullDataSize());
9920 QualType To = getDerived().TransformType(TLB, PatternTL);
9921 if (To.isNull())
9922 return ExprError();
9923
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009924 if (To->containsUnexpandedParameterPack()) {
9925 To = getDerived().RebuildPackExpansionType(To,
9926 PatternTL.getSourceRange(),
9927 ExpansionTL.getEllipsisLoc(),
9928 NumExpansions);
9929 if (To.isNull())
9930 return ExprError();
9931
9932 PackExpansionTypeLoc ToExpansionTL
9933 = TLB.push<PackExpansionTypeLoc>(To);
9934 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9935 }
9936
Douglas Gregor29c42f22012-02-24 07:38:34 +00009937 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009939
Douglas Gregor29c42f22012-02-24 07:38:34 +00009940 if (!RetainExpansion)
9941 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009942
Douglas Gregor29c42f22012-02-24 07:38:34 +00009943 // If we're supposed to retain a pack expansion, do so by temporarily
9944 // forgetting the partially-substituted parameter pack.
9945 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9946
9947 TypeLocBuilder TLB;
9948 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009949
Douglas Gregor29c42f22012-02-24 07:38:34 +00009950 QualType To = getDerived().TransformType(TLB, PatternTL);
9951 if (To.isNull())
9952 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009953
9954 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009955 PatternTL.getSourceRange(),
9956 ExpansionTL.getEllipsisLoc(),
9957 NumExpansions);
9958 if (To.isNull())
9959 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009960
Douglas Gregor29c42f22012-02-24 07:38:34 +00009961 PackExpansionTypeLoc ToExpansionTL
9962 = TLB.push<PackExpansionTypeLoc>(To);
9963 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9964 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009966
Douglas Gregor29c42f22012-02-24 07:38:34 +00009967 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009968 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009969
9970 return getDerived().RebuildTypeTrait(E->getTrait(),
9971 E->getLocStart(),
9972 Args,
9973 E->getLocEnd());
9974}
9975
9976template<typename Derived>
9977ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009978TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9979 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9980 if (!T)
9981 return ExprError();
9982
9983 if (!getDerived().AlwaysRebuild() &&
9984 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009985 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009986
9987 ExprResult SubExpr;
9988 {
9989 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9990 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9991 if (SubExpr.isInvalid())
9992 return ExprError();
9993
9994 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009995 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009996 }
9997
9998 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9999 E->getLocStart(),
10000 T,
10001 SubExpr.get(),
10002 E->getLocEnd());
10003}
10004
10005template<typename Derived>
10006ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010007TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10008 ExprResult SubExpr;
10009 {
10010 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10011 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10012 if (SubExpr.isInvalid())
10013 return ExprError();
10014
10015 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010016 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010017 }
10018
10019 return getDerived().RebuildExpressionTrait(
10020 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10021}
10022
Reid Kleckner32506ed2014-06-12 23:03:48 +000010023template <typename Derived>
10024ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10025 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10026 TypeSourceInfo **RecoveryTSI) {
10027 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10028 DRE, AddrTaken, RecoveryTSI);
10029
10030 // Propagate both errors and recovered types, which return ExprEmpty.
10031 if (!NewDRE.isUsable())
10032 return NewDRE;
10033
10034 // We got an expr, wrap it up in parens.
10035 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10036 return PE;
10037 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10038 PE->getRParen());
10039}
10040
10041template <typename Derived>
10042ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10043 DependentScopeDeclRefExpr *E) {
10044 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10045 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010046}
10047
10048template<typename Derived>
10049ExprResult
10050TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10051 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010052 bool IsAddressOfOperand,
10053 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010054 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010055 NestedNameSpecifierLoc QualifierLoc
10056 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10057 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010058 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010059 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010060
John McCall31f82722010-11-12 08:19:04 +000010061 // TODO: If this is a conversion-function-id, verify that the
10062 // destination type name (if present) resolves the same way after
10063 // instantiation as it did in the local scope.
10064
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010065 DeclarationNameInfo NameInfo
10066 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10067 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010069
John McCalle66edc12009-11-24 19:00:30 +000010070 if (!E->hasExplicitTemplateArgs()) {
10071 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010072 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010073 // Note: it is sufficient to compare the Name component of NameInfo:
10074 // if name has not changed, DNLoc has not changed either.
10075 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010076 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010077
Reid Kleckner32506ed2014-06-12 23:03:48 +000010078 return getDerived().RebuildDependentScopeDeclRefExpr(
10079 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10080 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010081 }
John McCall6b51f282009-11-23 01:53:49 +000010082
10083 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010084 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10085 E->getNumTemplateArgs(),
10086 TransArgs))
10087 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010088
Reid Kleckner32506ed2014-06-12 23:03:48 +000010089 return getDerived().RebuildDependentScopeDeclRefExpr(
10090 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10091 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010092}
10093
10094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010096TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010097 // CXXConstructExprs other than for list-initialization and
10098 // CXXTemporaryObjectExpr are always implicit, so when we have
10099 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010100 if ((E->getNumArgs() == 1 ||
10101 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010102 (!getDerived().DropCallArgument(E->getArg(0))) &&
10103 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010104 return getDerived().TransformExpr(E->getArg(0));
10105
Douglas Gregora16548e2009-08-11 05:31:07 +000010106 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10107
10108 QualType T = getDerived().TransformType(E->getType());
10109 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010110 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010111
10112 CXXConstructorDecl *Constructor
10113 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010114 getDerived().TransformDecl(E->getLocStart(),
10115 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010116 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010118
Douglas Gregora16548e2009-08-11 05:31:07 +000010119 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010120 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010121 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010122 &ArgumentChanged))
10123 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010124
Douglas Gregora16548e2009-08-11 05:31:07 +000010125 if (!getDerived().AlwaysRebuild() &&
10126 T == E->getType() &&
10127 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010128 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010129 // Mark the constructor as referenced.
10130 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010131 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010132 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010133 }
Mike Stump11289f42009-09-09 15:08:12 +000010134
Douglas Gregordb121ba2009-12-14 16:27:04 +000010135 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010136 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010137 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010138 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010139 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010140 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010141 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010142 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010143 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010144}
Mike Stump11289f42009-09-09 15:08:12 +000010145
Richard Smith5179eb72016-06-28 19:03:57 +000010146template<typename Derived>
10147ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10148 CXXInheritedCtorInitExpr *E) {
10149 QualType T = getDerived().TransformType(E->getType());
10150 if (T.isNull())
10151 return ExprError();
10152
10153 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10154 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10155 if (!Constructor)
10156 return ExprError();
10157
10158 if (!getDerived().AlwaysRebuild() &&
10159 T == E->getType() &&
10160 Constructor == E->getConstructor()) {
10161 // Mark the constructor as referenced.
10162 // FIXME: Instantiation-specific
10163 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10164 return E;
10165 }
10166
10167 return getDerived().RebuildCXXInheritedCtorInitExpr(
10168 T, E->getLocation(), Constructor,
10169 E->constructsVBase(), E->inheritedFromVBase());
10170}
10171
Douglas Gregora16548e2009-08-11 05:31:07 +000010172/// \brief Transform a C++ temporary-binding expression.
10173///
Douglas Gregor363b1512009-12-24 18:51:59 +000010174/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10175/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010177ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010178TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010179 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010180}
Mike Stump11289f42009-09-09 15:08:12 +000010181
John McCall5d413782010-12-06 08:20:24 +000010182/// \brief Transform a C++ expression that contains cleanups that should
10183/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010184///
John McCall5d413782010-12-06 08:20:24 +000010185/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010186/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010188ExprResult
John McCall5d413782010-12-06 08:20:24 +000010189TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010190 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010191}
Mike Stump11289f42009-09-09 15:08:12 +000010192
Douglas Gregora16548e2009-08-11 05:31:07 +000010193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010194ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010195TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010196 CXXTemporaryObjectExpr *E) {
10197 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10198 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010200
Douglas Gregora16548e2009-08-11 05:31:07 +000010201 CXXConstructorDecl *Constructor
10202 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010203 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010204 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010205 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010207
Douglas Gregora16548e2009-08-11 05:31:07 +000010208 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010209 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010210 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010211 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010212 &ArgumentChanged))
10213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010214
Douglas Gregora16548e2009-08-11 05:31:07 +000010215 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010216 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010217 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010218 !ArgumentChanged) {
10219 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010220 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010221 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010222 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010223
Richard Smithd59b8322012-12-19 01:39:02 +000010224 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010225 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10226 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010227 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010228 E->getLocEnd());
10229}
Mike Stump11289f42009-09-09 15:08:12 +000010230
Douglas Gregora16548e2009-08-11 05:31:07 +000010231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010232ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010233TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010234 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010235 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010236 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010237 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10238 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010239 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010240 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010241 CEnd = E->capture_end();
10242 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010243 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010244 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010245 EnterExpressionEvaluationContext EEEC(getSema(),
10246 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010247 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10248 C->getCapturedVar()->getInit(),
10249 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010250
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010251 if (NewExprInitResult.isInvalid())
10252 return ExprError();
10253 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010254
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010255 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010256 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010257 getSema().buildLambdaInitCaptureInitialization(
10258 C->getLocation(), OldVD->getType()->isReferenceType(),
10259 OldVD->getIdentifier(),
10260 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010261 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010262 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10263 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010264 }
10265
Faisal Vali2cba1332013-10-23 06:44:28 +000010266 // Transform the template parameters, and add them to the current
10267 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010268 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010269 E->getTemplateParameterList());
10270
Richard Smith01014ce2014-11-20 23:53:14 +000010271 // Transform the type of the original lambda's call operator.
10272 // The transformation MUST be done in the CurrentInstantiationScope since
10273 // it introduces a mapping of the original to the newly created
10274 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010275 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010276 {
10277 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10278 FunctionProtoTypeLoc OldCallOpFPTL =
10279 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010280
10281 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010282 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010283 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010284 QualType NewCallOpType = TransformFunctionProtoType(
10285 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010286 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10287 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10288 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010289 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010290 if (NewCallOpType.isNull())
10291 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010292 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10293 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010294 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010295
Richard Smithc38498f2015-04-27 21:27:54 +000010296 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10297 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10298 LSI->GLTemplateParameterList = TPL;
10299
Eli Friedmand564afb2012-09-19 01:18:11 +000010300 // Create the local class that will describe the lambda.
10301 CXXRecordDecl *Class
10302 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010303 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010304 /*KnownDependent=*/false,
10305 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010306 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10307
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010308 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010309 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10310 Class, E->getIntroducerRange(), NewCallOpTSI,
10311 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010312 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10313 E->getCallOperator()->isConstexpr());
10314
Faisal Vali2cba1332013-10-23 06:44:28 +000010315 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010316
Faisal Vali2cba1332013-10-23 06:44:28 +000010317 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010318 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010319
Douglas Gregorb4328232012-02-14 00:00:48 +000010320 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010321 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010322 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010323
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010324 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010325 getSema().buildLambdaScope(LSI, NewCallOperator,
10326 E->getIntroducerRange(),
10327 E->getCaptureDefault(),
10328 E->getCaptureDefaultLoc(),
10329 E->hasExplicitParameters(),
10330 E->hasExplicitResultType(),
10331 E->isMutable());
10332
10333 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010334
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010335 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010336 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010337 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010338 CEnd = E->capture_end();
10339 C != CEnd; ++C) {
10340 // When we hit the first implicit capture, tell Sema that we've finished
10341 // the list of explicit captures.
10342 if (!FinishedExplicitCaptures && C->isImplicit()) {
10343 getSema().finishLambdaExplicitCaptures(LSI);
10344 FinishedExplicitCaptures = true;
10345 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010346
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010347 // Capturing 'this' is trivial.
10348 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010349 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10350 /*BuildAndDiagnose*/ true, nullptr,
10351 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010352 continue;
10353 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010354 // Captured expression will be recaptured during captured variables
10355 // rebuilding.
10356 if (C->capturesVLAType())
10357 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010358
Richard Smithba71c082013-05-16 06:20:58 +000010359 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010360 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010361 InitCaptureInfoTy InitExprTypePair =
10362 InitCaptureExprsAndTypes[C - E->capture_begin()];
10363 ExprResult Init = InitExprTypePair.first;
10364 QualType InitQualType = InitExprTypePair.second;
10365 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010366 Invalid = true;
10367 continue;
10368 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010369 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010370 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010371 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10372 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010373 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010374 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010375 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010376 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010377 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010378 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010379 continue;
10380 }
10381
10382 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10383
Douglas Gregor3e308b12012-02-14 19:27:52 +000010384 // Determine the capture kind for Sema.
10385 Sema::TryCaptureKind Kind
10386 = C->isImplicit()? Sema::TryCapture_Implicit
10387 : C->getCaptureKind() == LCK_ByCopy
10388 ? Sema::TryCapture_ExplicitByVal
10389 : Sema::TryCapture_ExplicitByRef;
10390 SourceLocation EllipsisLoc;
10391 if (C->isPackExpansion()) {
10392 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10393 bool ShouldExpand = false;
10394 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010395 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010396 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10397 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010398 Unexpanded,
10399 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010400 NumExpansions)) {
10401 Invalid = true;
10402 continue;
10403 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010404
Douglas Gregor3e308b12012-02-14 19:27:52 +000010405 if (ShouldExpand) {
10406 // The transform has determined that we should perform an expansion;
10407 // transform and capture each of the arguments.
10408 // expansion of the pattern. Do so.
10409 VarDecl *Pack = C->getCapturedVar();
10410 for (unsigned I = 0; I != *NumExpansions; ++I) {
10411 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10412 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010413 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010414 Pack));
10415 if (!CapturedVar) {
10416 Invalid = true;
10417 continue;
10418 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010419
Douglas Gregor3e308b12012-02-14 19:27:52 +000010420 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010421 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10422 }
Richard Smith9467be42014-06-06 17:33:35 +000010423
10424 // FIXME: Retain a pack expansion if RetainExpansion is true.
10425
Douglas Gregor3e308b12012-02-14 19:27:52 +000010426 continue;
10427 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010428
Douglas Gregor3e308b12012-02-14 19:27:52 +000010429 EllipsisLoc = C->getEllipsisLoc();
10430 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010431
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010432 // Transform the captured variable.
10433 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010434 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010435 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010436 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010437 Invalid = true;
10438 continue;
10439 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010440
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010441 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010442 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10443 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010444 }
10445 if (!FinishedExplicitCaptures)
10446 getSema().finishLambdaExplicitCaptures(LSI);
10447
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010448 // Enter a new evaluation context to insulate the lambda from any
10449 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010450 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010451
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010452 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010453 StmtResult Body =
10454 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10455
10456 // ActOnLambda* will pop the function scope for us.
10457 FuncScopeCleanup.disable();
10458
Douglas Gregorb4328232012-02-14 00:00:48 +000010459 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010460 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010461 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010462 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010463 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010464 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010465
Richard Smithc38498f2015-04-27 21:27:54 +000010466 // Copy the LSI before ActOnFinishFunctionBody removes it.
10467 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10468 // the call operator.
10469 auto LSICopy = *LSI;
10470 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10471 /*IsInstantiation*/ true);
10472 SavedContext.pop();
10473
10474 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10475 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010476}
10477
10478template<typename Derived>
10479ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010480TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010481 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010482 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10483 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010484 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010485
Douglas Gregora16548e2009-08-11 05:31:07 +000010486 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010487 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010488 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010489 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010490 &ArgumentChanged))
10491 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010492
Douglas Gregora16548e2009-08-11 05:31:07 +000010493 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010494 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010495 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010496 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010497
Douglas Gregora16548e2009-08-11 05:31:07 +000010498 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010499 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010500 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010501 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010502 E->getRParenLoc());
10503}
Mike Stump11289f42009-09-09 15:08:12 +000010504
Douglas Gregora16548e2009-08-11 05:31:07 +000010505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010506ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010507TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010508 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010509 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010510 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010511 Expr *OldBase;
10512 QualType BaseType;
10513 QualType ObjectType;
10514 if (!E->isImplicitAccess()) {
10515 OldBase = E->getBase();
10516 Base = getDerived().TransformExpr(OldBase);
10517 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010518 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010519
John McCall2d74de92009-12-01 22:10:20 +000010520 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010521 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010522 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010523 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010524 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010525 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010526 ObjectTy,
10527 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010528 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010529 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010530
John McCallba7bf592010-08-24 05:47:05 +000010531 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010532 BaseType = ((Expr*) Base.get())->getType();
10533 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010534 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010535 BaseType = getDerived().TransformType(E->getBaseType());
10536 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10537 }
Mike Stump11289f42009-09-09 15:08:12 +000010538
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010539 // Transform the first part of the nested-name-specifier that qualifies
10540 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010541 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010542 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010543 E->getFirstQualifierFoundInScope(),
10544 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010545
Douglas Gregore16af532011-02-28 18:50:33 +000010546 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010547 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010548 QualifierLoc
10549 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10550 ObjectType,
10551 FirstQualifierInScope);
10552 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010553 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010554 }
Mike Stump11289f42009-09-09 15:08:12 +000010555
Abramo Bagnara7945c982012-01-27 09:46:47 +000010556 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10557
John McCall31f82722010-11-12 08:19:04 +000010558 // TODO: If this is a conversion-function-id, verify that the
10559 // destination type name (if present) resolves the same way after
10560 // instantiation as it did in the local scope.
10561
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010562 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010563 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010564 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010566
John McCall2d74de92009-12-01 22:10:20 +000010567 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010568 // This is a reference to a member without an explicitly-specified
10569 // template argument list. Optimize for this common case.
10570 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010571 Base.get() == OldBase &&
10572 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010573 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010574 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010575 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010576 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010577
John McCallb268a282010-08-23 23:25:46 +000010578 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010579 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010580 E->isArrow(),
10581 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010582 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010583 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010584 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010585 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010586 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010587 }
10588
John McCall6b51f282009-11-23 01:53:49 +000010589 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010590 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10591 E->getNumTemplateArgs(),
10592 TransArgs))
10593 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010594
John McCallb268a282010-08-23 23:25:46 +000010595 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010596 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010597 E->isArrow(),
10598 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010599 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010600 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010601 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010602 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010603 &TransArgs);
10604}
10605
10606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010607ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010608TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010609 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010610 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010611 QualType BaseType;
10612 if (!Old->isImplicitAccess()) {
10613 Base = getDerived().TransformExpr(Old->getBase());
10614 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010615 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010616 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010617 Old->isArrow());
10618 if (Base.isInvalid())
10619 return ExprError();
10620 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010621 } else {
10622 BaseType = getDerived().TransformType(Old->getBaseType());
10623 }
John McCall10eae182009-11-30 22:42:35 +000010624
Douglas Gregor0da1d432011-02-28 20:01:57 +000010625 NestedNameSpecifierLoc QualifierLoc;
10626 if (Old->getQualifierLoc()) {
10627 QualifierLoc
10628 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10629 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010630 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010631 }
10632
Abramo Bagnara7945c982012-01-27 09:46:47 +000010633 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10634
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010635 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010636 Sema::LookupOrdinaryName);
10637
10638 // Transform all the decls.
10639 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10640 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010641 NamedDecl *InstD = static_cast<NamedDecl*>(
10642 getDerived().TransformDecl(Old->getMemberLoc(),
10643 *I));
John McCall84d87672009-12-10 09:41:52 +000010644 if (!InstD) {
10645 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10646 // This can happen because of dependent hiding.
10647 if (isa<UsingShadowDecl>(*I))
10648 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010649 else {
10650 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010651 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010652 }
John McCall84d87672009-12-10 09:41:52 +000010653 }
John McCall10eae182009-11-30 22:42:35 +000010654
10655 // Expand using declarations.
10656 if (isa<UsingDecl>(InstD)) {
10657 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010658 for (auto *I : UD->shadows())
10659 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010660 continue;
10661 }
10662
10663 R.addDecl(InstD);
10664 }
10665
10666 R.resolveKind();
10667
Douglas Gregor9262f472010-04-27 18:19:34 +000010668 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010669 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010670 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010671 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010672 Old->getMemberLoc(),
10673 Old->getNamingClass()));
10674 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010675 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010676
Douglas Gregorda7be082010-04-27 16:10:10 +000010677 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010678 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010679
John McCall10eae182009-11-30 22:42:35 +000010680 TemplateArgumentListInfo TransArgs;
10681 if (Old->hasExplicitTemplateArgs()) {
10682 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10683 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010684 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10685 Old->getNumTemplateArgs(),
10686 TransArgs))
10687 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010688 }
John McCall38836f02010-01-15 08:34:02 +000010689
10690 // FIXME: to do this check properly, we will need to preserve the
10691 // first-qualifier-in-scope here, just in case we had a dependent
10692 // base (and therefore couldn't do the check) and a
10693 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010694 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010695
John McCallb268a282010-08-23 23:25:46 +000010696 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010697 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010698 Old->getOperatorLoc(),
10699 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010700 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010701 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010702 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010703 R,
10704 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010705 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010706}
10707
10708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010709ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010710TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010711 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010712 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10713 if (SubExpr.isInvalid())
10714 return ExprError();
10715
10716 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010717 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010718
10719 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10720}
10721
10722template<typename Derived>
10723ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010724TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010725 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10726 if (Pattern.isInvalid())
10727 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010728
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010729 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010730 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010731
Douglas Gregorb8840002011-01-14 21:20:45 +000010732 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10733 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010734}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010735
10736template<typename Derived>
10737ExprResult
10738TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10739 // If E is not value-dependent, then nothing will change when we transform it.
10740 // Note: This is an instantiation-centric view.
10741 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010742 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010743
Richard Smithd784e682015-09-23 21:41:42 +000010744 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010745
Richard Smithd784e682015-09-23 21:41:42 +000010746 ArrayRef<TemplateArgument> PackArgs;
10747 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010748
Richard Smithd784e682015-09-23 21:41:42 +000010749 // Find the argument list to transform.
10750 if (E->isPartiallySubstituted()) {
10751 PackArgs = E->getPartialArguments();
10752 } else if (E->isValueDependent()) {
10753 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10754 bool ShouldExpand = false;
10755 bool RetainExpansion = false;
10756 Optional<unsigned> NumExpansions;
10757 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10758 Unexpanded,
10759 ShouldExpand, RetainExpansion,
10760 NumExpansions))
10761 return ExprError();
10762
10763 // If we need to expand the pack, build a template argument from it and
10764 // expand that.
10765 if (ShouldExpand) {
10766 auto *Pack = E->getPack();
10767 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10768 ArgStorage = getSema().Context.getPackExpansionType(
10769 getSema().Context.getTypeDeclType(TTPD), None);
10770 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10771 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10772 } else {
10773 auto *VD = cast<ValueDecl>(Pack);
10774 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10775 VK_RValue, E->getPackLoc());
10776 if (DRE.isInvalid())
10777 return ExprError();
10778 ArgStorage = new (getSema().Context) PackExpansionExpr(
10779 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10780 }
10781 PackArgs = ArgStorage;
10782 }
10783 }
10784
10785 // If we're not expanding the pack, just transform the decl.
10786 if (!PackArgs.size()) {
10787 auto *Pack = cast_or_null<NamedDecl>(
10788 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010789 if (!Pack)
10790 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010791 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10792 E->getPackLoc(),
10793 E->getRParenLoc(), None, None);
10794 }
10795
Richard Smithc5452ed2016-10-19 22:18:42 +000010796 // Try to compute the result without performing a partial substitution.
10797 Optional<unsigned> Result = 0;
10798 for (const TemplateArgument &Arg : PackArgs) {
10799 if (!Arg.isPackExpansion()) {
10800 Result = *Result + 1;
10801 continue;
10802 }
10803
10804 TemplateArgumentLoc ArgLoc;
10805 InventTemplateArgumentLoc(Arg, ArgLoc);
10806
10807 // Find the pattern of the pack expansion.
10808 SourceLocation Ellipsis;
10809 Optional<unsigned> OrigNumExpansions;
10810 TemplateArgumentLoc Pattern =
10811 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
10812 OrigNumExpansions);
10813
10814 // Substitute under the pack expansion. Do not expand the pack (yet).
10815 TemplateArgumentLoc OutPattern;
10816 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10817 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
10818 /*Uneval*/ true))
10819 return true;
10820
10821 // See if we can determine the number of arguments from the result.
10822 Optional<unsigned> NumExpansions =
10823 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
10824 if (!NumExpansions) {
10825 // No: we must be in an alias template expansion, and we're going to need
10826 // to actually expand the packs.
10827 Result = None;
10828 break;
10829 }
10830
10831 Result = *Result + *NumExpansions;
10832 }
10833
10834 // Common case: we could determine the number of expansions without
10835 // substituting.
10836 if (Result)
10837 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10838 E->getPackLoc(),
10839 E->getRParenLoc(), *Result, None);
10840
Richard Smithd784e682015-09-23 21:41:42 +000010841 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10842 E->getPackLoc());
10843 {
10844 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10845 typedef TemplateArgumentLocInventIterator<
10846 Derived, const TemplateArgument*> PackLocIterator;
10847 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10848 PackLocIterator(*this, PackArgs.end()),
10849 TransformedPackArgs, /*Uneval*/true))
10850 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010851 }
10852
Richard Smithc5452ed2016-10-19 22:18:42 +000010853 // Check whether we managed to fully-expand the pack.
10854 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000010855 SmallVector<TemplateArgument, 8> Args;
10856 bool PartialSubstitution = false;
10857 for (auto &Loc : TransformedPackArgs.arguments()) {
10858 Args.push_back(Loc.getArgument());
10859 if (Loc.getArgument().isPackExpansion())
10860 PartialSubstitution = true;
10861 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010862
Richard Smithd784e682015-09-23 21:41:42 +000010863 if (PartialSubstitution)
10864 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10865 E->getPackLoc(),
10866 E->getRParenLoc(), None, Args);
10867
10868 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010869 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010870 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010871}
10872
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010873template<typename Derived>
10874ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010875TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10876 SubstNonTypeTemplateParmPackExpr *E) {
10877 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010878 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010879}
10880
10881template<typename Derived>
10882ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010883TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10884 SubstNonTypeTemplateParmExpr *E) {
10885 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010886 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010887}
10888
10889template<typename Derived>
10890ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010891TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10892 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010893 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010894}
10895
10896template<typename Derived>
10897ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010898TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10899 MaterializeTemporaryExpr *E) {
10900 return getDerived().TransformExpr(E->GetTemporaryExpr());
10901}
Chad Rosier1dcde962012-08-08 18:46:20 +000010902
Douglas Gregorfe314812011-06-21 17:03:29 +000010903template<typename Derived>
10904ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010905TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10906 Expr *Pattern = E->getPattern();
10907
10908 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10909 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10910 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10911
10912 // Determine whether the set of unexpanded parameter packs can and should
10913 // be expanded.
10914 bool Expand = true;
10915 bool RetainExpansion = false;
10916 Optional<unsigned> NumExpansions;
10917 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10918 Pattern->getSourceRange(),
10919 Unexpanded,
10920 Expand, RetainExpansion,
10921 NumExpansions))
10922 return true;
10923
10924 if (!Expand) {
10925 // Do not expand any packs here, just transform and rebuild a fold
10926 // expression.
10927 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10928
10929 ExprResult LHS =
10930 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10931 if (LHS.isInvalid())
10932 return true;
10933
10934 ExprResult RHS =
10935 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10936 if (RHS.isInvalid())
10937 return true;
10938
10939 if (!getDerived().AlwaysRebuild() &&
10940 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10941 return E;
10942
10943 return getDerived().RebuildCXXFoldExpr(
10944 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10945 RHS.get(), E->getLocEnd());
10946 }
10947
10948 // The transform has determined that we should perform an elementwise
10949 // expansion of the pattern. Do so.
10950 ExprResult Result = getDerived().TransformExpr(E->getInit());
10951 if (Result.isInvalid())
10952 return true;
10953 bool LeftFold = E->isLeftFold();
10954
10955 // If we're retaining an expansion for a right fold, it is the innermost
10956 // component and takes the init (if any).
10957 if (!LeftFold && RetainExpansion) {
10958 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10959
10960 ExprResult Out = getDerived().TransformExpr(Pattern);
10961 if (Out.isInvalid())
10962 return true;
10963
10964 Result = getDerived().RebuildCXXFoldExpr(
10965 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10966 Result.get(), E->getLocEnd());
10967 if (Result.isInvalid())
10968 return true;
10969 }
10970
10971 for (unsigned I = 0; I != *NumExpansions; ++I) {
10972 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10973 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10974 ExprResult Out = getDerived().TransformExpr(Pattern);
10975 if (Out.isInvalid())
10976 return true;
10977
10978 if (Out.get()->containsUnexpandedParameterPack()) {
10979 // We still have a pack; retain a pack expansion for this slice.
10980 Result = getDerived().RebuildCXXFoldExpr(
10981 E->getLocStart(),
10982 LeftFold ? Result.get() : Out.get(),
10983 E->getOperator(), E->getEllipsisLoc(),
10984 LeftFold ? Out.get() : Result.get(),
10985 E->getLocEnd());
10986 } else if (Result.isUsable()) {
10987 // We've got down to a single element; build a binary operator.
10988 Result = getDerived().RebuildBinaryOperator(
10989 E->getEllipsisLoc(), E->getOperator(),
10990 LeftFold ? Result.get() : Out.get(),
10991 LeftFold ? Out.get() : Result.get());
10992 } else
10993 Result = Out;
10994
10995 if (Result.isInvalid())
10996 return true;
10997 }
10998
10999 // If we're retaining an expansion for a left fold, it is the outermost
11000 // component and takes the complete expansion so far as its init (if any).
11001 if (LeftFold && RetainExpansion) {
11002 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11003
11004 ExprResult Out = getDerived().TransformExpr(Pattern);
11005 if (Out.isInvalid())
11006 return true;
11007
11008 Result = getDerived().RebuildCXXFoldExpr(
11009 E->getLocStart(), Result.get(),
11010 E->getOperator(), E->getEllipsisLoc(),
11011 Out.get(), E->getLocEnd());
11012 if (Result.isInvalid())
11013 return true;
11014 }
11015
11016 // If we had no init and an empty pack, and we're not retaining an expansion,
11017 // then produce a fallback value or error.
11018 if (Result.isUnset())
11019 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11020 E->getOperator());
11021
11022 return Result;
11023}
11024
11025template<typename Derived>
11026ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011027TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11028 CXXStdInitializerListExpr *E) {
11029 return getDerived().TransformExpr(E->getSubExpr());
11030}
11031
11032template<typename Derived>
11033ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011034TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011035 return SemaRef.MaybeBindToTemporary(E);
11036}
11037
11038template<typename Derived>
11039ExprResult
11040TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011041 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011042}
11043
11044template<typename Derived>
11045ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011046TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11047 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11048 if (SubExpr.isInvalid())
11049 return ExprError();
11050
11051 if (!getDerived().AlwaysRebuild() &&
11052 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011053 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011054
11055 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011056}
11057
11058template<typename Derived>
11059ExprResult
11060TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11061 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011062 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011063 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011064 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011065 /*IsCall=*/false, Elements, &ArgChanged))
11066 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011067
Ted Kremeneke65b0862012-03-06 20:05:56 +000011068 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11069 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011070
Ted Kremeneke65b0862012-03-06 20:05:56 +000011071 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11072 Elements.data(),
11073 Elements.size());
11074}
11075
11076template<typename Derived>
11077ExprResult
11078TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011079 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011080 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011081 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011082 bool ArgChanged = false;
11083 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11084 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011085
Ted Kremeneke65b0862012-03-06 20:05:56 +000011086 if (OrigElement.isPackExpansion()) {
11087 // This key/value element is a pack expansion.
11088 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11089 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11090 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11091 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11092
11093 // Determine whether the set of unexpanded parameter packs can
11094 // and should be expanded.
11095 bool Expand = true;
11096 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011097 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11098 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011099 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11100 OrigElement.Value->getLocEnd());
11101 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11102 PatternRange,
11103 Unexpanded,
11104 Expand, RetainExpansion,
11105 NumExpansions))
11106 return ExprError();
11107
11108 if (!Expand) {
11109 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011110 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011111 // expansion.
11112 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11113 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11114 if (Key.isInvalid())
11115 return ExprError();
11116
11117 if (Key.get() != OrigElement.Key)
11118 ArgChanged = true;
11119
11120 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11121 if (Value.isInvalid())
11122 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011123
Ted Kremeneke65b0862012-03-06 20:05:56 +000011124 if (Value.get() != OrigElement.Value)
11125 ArgChanged = true;
11126
Chad Rosier1dcde962012-08-08 18:46:20 +000011127 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011128 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11129 };
11130 Elements.push_back(Expansion);
11131 continue;
11132 }
11133
11134 // Record right away that the argument was changed. This needs
11135 // to happen even if the array expands to nothing.
11136 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011137
Ted Kremeneke65b0862012-03-06 20:05:56 +000011138 // The transform has determined that we should perform an elementwise
11139 // expansion of the pattern. Do so.
11140 for (unsigned I = 0; I != *NumExpansions; ++I) {
11141 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11142 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11143 if (Key.isInvalid())
11144 return ExprError();
11145
11146 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11147 if (Value.isInvalid())
11148 return ExprError();
11149
Chad Rosier1dcde962012-08-08 18:46:20 +000011150 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011151 Key.get(), Value.get(), SourceLocation(), NumExpansions
11152 };
11153
11154 // If any unexpanded parameter packs remain, we still have a
11155 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011156 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011157 if (Key.get()->containsUnexpandedParameterPack() ||
11158 Value.get()->containsUnexpandedParameterPack())
11159 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011160
Ted Kremeneke65b0862012-03-06 20:05:56 +000011161 Elements.push_back(Element);
11162 }
11163
Richard Smith9467be42014-06-06 17:33:35 +000011164 // FIXME: Retain a pack expansion if RetainExpansion is true.
11165
Ted Kremeneke65b0862012-03-06 20:05:56 +000011166 // We've finished with this pack expansion.
11167 continue;
11168 }
11169
11170 // Transform and check key.
11171 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11172 if (Key.isInvalid())
11173 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011174
Ted Kremeneke65b0862012-03-06 20:05:56 +000011175 if (Key.get() != OrigElement.Key)
11176 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011177
Ted Kremeneke65b0862012-03-06 20:05:56 +000011178 // Transform and check value.
11179 ExprResult Value
11180 = getDerived().TransformExpr(OrigElement.Value);
11181 if (Value.isInvalid())
11182 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011183
Ted Kremeneke65b0862012-03-06 20:05:56 +000011184 if (Value.get() != OrigElement.Value)
11185 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011186
11187 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011188 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011189 };
11190 Elements.push_back(Element);
11191 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011192
Ted Kremeneke65b0862012-03-06 20:05:56 +000011193 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11194 return SemaRef.MaybeBindToTemporary(E);
11195
11196 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011197 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011198}
11199
Mike Stump11289f42009-09-09 15:08:12 +000011200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011202TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011203 TypeSourceInfo *EncodedTypeInfo
11204 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11205 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011207
Douglas Gregora16548e2009-08-11 05:31:07 +000011208 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011209 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011210 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011211
11212 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011213 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011214 E->getRParenLoc());
11215}
Mike Stump11289f42009-09-09 15:08:12 +000011216
Douglas Gregora16548e2009-08-11 05:31:07 +000011217template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011218ExprResult TreeTransform<Derived>::
11219TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011220 // This is a kind of implicit conversion, and it needs to get dropped
11221 // and recomputed for the same general reasons that ImplicitCastExprs
11222 // do, as well a more specific one: this expression is only valid when
11223 // it appears *immediately* as an argument expression.
11224 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011225}
11226
11227template<typename Derived>
11228ExprResult TreeTransform<Derived>::
11229TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011230 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011231 = getDerived().TransformType(E->getTypeInfoAsWritten());
11232 if (!TSInfo)
11233 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011234
John McCall31168b02011-06-15 23:02:42 +000011235 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011236 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011237 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011238
John McCall31168b02011-06-15 23:02:42 +000011239 if (!getDerived().AlwaysRebuild() &&
11240 TSInfo == E->getTypeInfoAsWritten() &&
11241 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011242 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011243
John McCall31168b02011-06-15 23:02:42 +000011244 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011245 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011246 Result.get());
11247}
11248
Erik Pilkington29099de2016-07-16 00:35:23 +000011249template <typename Derived>
11250ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11251 ObjCAvailabilityCheckExpr *E) {
11252 return E;
11253}
11254
John McCall31168b02011-06-15 23:02:42 +000011255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011257TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011258 // Transform arguments.
11259 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011260 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011261 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011262 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011263 &ArgChanged))
11264 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011265
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011266 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11267 // Class message: transform the receiver type.
11268 TypeSourceInfo *ReceiverTypeInfo
11269 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11270 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011271 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011272
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011273 // If nothing changed, just retain the existing message send.
11274 if (!getDerived().AlwaysRebuild() &&
11275 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011276 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011277
11278 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011279 SmallVector<SourceLocation, 16> SelLocs;
11280 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011281 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11282 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011283 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011284 E->getMethodDecl(),
11285 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011286 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011287 E->getRightLoc());
11288 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011289 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11290 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011291 if (!E->getMethodDecl())
11292 return ExprError();
11293
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011294 // Build a new class message send to 'super'.
11295 SmallVector<SourceLocation, 16> SelLocs;
11296 E->getSelectorLocs(SelLocs);
11297 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11298 E->getSelector(),
11299 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011300 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011301 E->getMethodDecl(),
11302 E->getLeftLoc(),
11303 Args,
11304 E->getRightLoc());
11305 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011306
11307 // Instance message: transform the receiver
11308 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11309 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011310 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011311 = getDerived().TransformExpr(E->getInstanceReceiver());
11312 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011313 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011314
11315 // If nothing changed, just retain the existing message send.
11316 if (!getDerived().AlwaysRebuild() &&
11317 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011318 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011319
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011320 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011321 SmallVector<SourceLocation, 16> SelLocs;
11322 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011323 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011324 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011325 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011326 E->getMethodDecl(),
11327 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011328 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011329 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011330}
11331
Mike Stump11289f42009-09-09 15:08:12 +000011332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011334TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011335 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011336}
11337
Mike Stump11289f42009-09-09 15:08:12 +000011338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011340TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011341 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011342}
11343
Mike Stump11289f42009-09-09 15:08:12 +000011344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011346TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011347 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011348 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011349 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011350 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011351
11352 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011353
Douglas Gregord51d90d2010-04-26 20:11:03 +000011354 // If nothing changed, just retain the existing expression.
11355 if (!getDerived().AlwaysRebuild() &&
11356 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011357 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011358
John McCallb268a282010-08-23 23:25:46 +000011359 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011360 E->getLocation(),
11361 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011362}
11363
Mike Stump11289f42009-09-09 15:08:12 +000011364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011366TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011367 // 'super' and types never change. Property never changes. Just
11368 // retain the existing expression.
11369 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011370 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011371
Douglas Gregor9faee212010-04-26 20:47:02 +000011372 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011373 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011374 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011375 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011376
Douglas Gregor9faee212010-04-26 20:47:02 +000011377 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011378
Douglas Gregor9faee212010-04-26 20:47:02 +000011379 // If nothing changed, just retain the existing expression.
11380 if (!getDerived().AlwaysRebuild() &&
11381 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011382 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011383
John McCallb7bd14f2010-12-02 01:19:52 +000011384 if (E->isExplicitProperty())
11385 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11386 E->getExplicitProperty(),
11387 E->getLocation());
11388
11389 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011390 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011391 E->getImplicitPropertyGetter(),
11392 E->getImplicitPropertySetter(),
11393 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011394}
11395
Mike Stump11289f42009-09-09 15:08:12 +000011396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011397ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011398TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11399 // Transform the base expression.
11400 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11401 if (Base.isInvalid())
11402 return ExprError();
11403
11404 // Transform the key expression.
11405 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11406 if (Key.isInvalid())
11407 return ExprError();
11408
11409 // If nothing changed, just retain the existing expression.
11410 if (!getDerived().AlwaysRebuild() &&
11411 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011412 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011413
Chad Rosier1dcde962012-08-08 18:46:20 +000011414 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011415 Base.get(), Key.get(),
11416 E->getAtIndexMethodDecl(),
11417 E->setAtIndexMethodDecl());
11418}
11419
11420template<typename Derived>
11421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011422TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011423 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011424 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011425 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011426 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011427
Douglas Gregord51d90d2010-04-26 20:11:03 +000011428 // If nothing changed, just retain the existing expression.
11429 if (!getDerived().AlwaysRebuild() &&
11430 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011431 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011432
John McCallb268a282010-08-23 23:25:46 +000011433 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011434 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011435 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011436}
11437
Mike Stump11289f42009-09-09 15:08:12 +000011438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011440TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011441 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011442 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011443 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011444 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011445 SubExprs, &ArgumentChanged))
11446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011447
Douglas Gregora16548e2009-08-11 05:31:07 +000011448 if (!getDerived().AlwaysRebuild() &&
11449 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011450 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011451
Douglas Gregora16548e2009-08-11 05:31:07 +000011452 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011453 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011454 E->getRParenLoc());
11455}
11456
Mike Stump11289f42009-09-09 15:08:12 +000011457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011458ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011459TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11460 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11461 if (SrcExpr.isInvalid())
11462 return ExprError();
11463
11464 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11465 if (!Type)
11466 return ExprError();
11467
11468 if (!getDerived().AlwaysRebuild() &&
11469 Type == E->getTypeSourceInfo() &&
11470 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011471 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011472
11473 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11474 SrcExpr.get(), Type,
11475 E->getRParenLoc());
11476}
11477
11478template<typename Derived>
11479ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011480TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011481 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011482
Craig Topperc3ec1492014-05-26 06:22:03 +000011483 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011484 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11485
11486 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011487 blockScope->TheDecl->setBlockMissingReturnType(
11488 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011489
Chris Lattner01cf8db2011-07-20 06:58:45 +000011490 SmallVector<ParmVarDecl*, 4> params;
11491 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011492
John McCallc8e321d2016-03-01 02:09:25 +000011493 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11494
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011495 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011496 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011497 if (getDerived().TransformFunctionTypeParams(
11498 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11499 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11500 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011501 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011502 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011503 }
John McCall490112f2011-02-04 18:33:18 +000011504
Eli Friedman34b49062012-01-26 03:00:14 +000011505 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011506 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011507
John McCallc8e321d2016-03-01 02:09:25 +000011508 auto epi = exprFunctionType->getExtProtoInfo();
11509 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11510
Jordan Rose5c382722013-03-08 21:51:21 +000011511 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011512 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011513 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011514
11515 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011516 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011517 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011518
11519 if (!oldBlock->blockMissingReturnType()) {
11520 blockScope->HasImplicitReturnType = false;
11521 blockScope->ReturnType = exprResultType;
11522 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011523
John McCall3882ace2011-01-05 12:14:39 +000011524 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011525 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011526 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011527 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011528 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011529 }
John McCall3882ace2011-01-05 12:14:39 +000011530
John McCall490112f2011-02-04 18:33:18 +000011531#ifndef NDEBUG
11532 // In builds with assertions, make sure that we captured everything we
11533 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011534 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011535 for (const auto &I : oldBlock->captures()) {
11536 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011537
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011538 // Ignore parameter packs.
11539 if (isa<ParmVarDecl>(oldCapture) &&
11540 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11541 continue;
John McCall490112f2011-02-04 18:33:18 +000011542
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011543 VarDecl *newCapture =
11544 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11545 oldCapture));
11546 assert(blockScope->CaptureMap.count(newCapture));
11547 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011548 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011549 }
11550#endif
11551
11552 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011553 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011554}
11555
Mike Stump11289f42009-09-09 15:08:12 +000011556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011557ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011558TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011559 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011560}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011561
11562template<typename Derived>
11563ExprResult
11564TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011565 QualType RetTy = getDerived().TransformType(E->getType());
11566 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011567 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011568 SubExprs.reserve(E->getNumSubExprs());
11569 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11570 SubExprs, &ArgumentChanged))
11571 return ExprError();
11572
11573 if (!getDerived().AlwaysRebuild() &&
11574 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011575 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011576
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011577 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011578 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011579}
Chad Rosier1dcde962012-08-08 18:46:20 +000011580
Douglas Gregora16548e2009-08-11 05:31:07 +000011581//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011582// Type reconstruction
11583//===----------------------------------------------------------------------===//
11584
Mike Stump11289f42009-09-09 15:08:12 +000011585template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011586QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11587 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011588 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011589 getDerived().getBaseEntity());
11590}
11591
Mike Stump11289f42009-09-09 15:08:12 +000011592template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011593QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11594 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011595 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011596 getDerived().getBaseEntity());
11597}
11598
Mike Stump11289f42009-09-09 15:08:12 +000011599template<typename Derived>
11600QualType
John McCall70dd5f62009-10-30 00:06:24 +000011601TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11602 bool WrittenAsLValue,
11603 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011604 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011605 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011606}
11607
11608template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011609QualType
John McCall70dd5f62009-10-30 00:06:24 +000011610TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11611 QualType ClassType,
11612 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011613 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11614 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011615}
11616
11617template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000011618QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11619 const ObjCTypeParamDecl *Decl,
11620 SourceLocation ProtocolLAngleLoc,
11621 ArrayRef<ObjCProtocolDecl *> Protocols,
11622 ArrayRef<SourceLocation> ProtocolLocs,
11623 SourceLocation ProtocolRAngleLoc) {
11624 return SemaRef.BuildObjCTypeParamType(Decl,
11625 ProtocolLAngleLoc, Protocols,
11626 ProtocolLocs, ProtocolRAngleLoc,
11627 /*FailOnError=*/true);
11628}
11629
11630template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011631QualType TreeTransform<Derived>::RebuildObjCObjectType(
11632 QualType BaseType,
11633 SourceLocation Loc,
11634 SourceLocation TypeArgsLAngleLoc,
11635 ArrayRef<TypeSourceInfo *> TypeArgs,
11636 SourceLocation TypeArgsRAngleLoc,
11637 SourceLocation ProtocolLAngleLoc,
11638 ArrayRef<ObjCProtocolDecl *> Protocols,
11639 ArrayRef<SourceLocation> ProtocolLocs,
11640 SourceLocation ProtocolRAngleLoc) {
11641 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11642 TypeArgs, TypeArgsRAngleLoc,
11643 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11644 ProtocolRAngleLoc,
11645 /*FailOnError=*/true);
11646}
11647
11648template<typename Derived>
11649QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11650 QualType PointeeType,
11651 SourceLocation Star) {
11652 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11653}
11654
11655template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011656QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011657TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11658 ArrayType::ArraySizeModifier SizeMod,
11659 const llvm::APInt *Size,
11660 Expr *SizeExpr,
11661 unsigned IndexTypeQuals,
11662 SourceRange BracketsRange) {
11663 if (SizeExpr || !Size)
11664 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11665 IndexTypeQuals, BracketsRange,
11666 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011667
11668 QualType Types[] = {
11669 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11670 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11671 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011672 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011673 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011674 QualType SizeType;
11675 for (unsigned I = 0; I != NumTypes; ++I)
11676 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11677 SizeType = Types[I];
11678 break;
11679 }
Mike Stump11289f42009-09-09 15:08:12 +000011680
Eli Friedman9562f392012-01-25 23:20:27 +000011681 // Note that we can return a VariableArrayType here in the case where
11682 // the element type was a dependent VariableArrayType.
11683 IntegerLiteral *ArraySize
11684 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11685 /*FIXME*/BracketsRange.getBegin());
11686 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011687 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011688 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011689}
Mike Stump11289f42009-09-09 15:08:12 +000011690
Douglas Gregord6ff3322009-08-04 16:50:30 +000011691template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011692QualType
11693TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011694 ArrayType::ArraySizeModifier SizeMod,
11695 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011696 unsigned IndexTypeQuals,
11697 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011698 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011699 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011700}
11701
11702template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011703QualType
Mike Stump11289f42009-09-09 15:08:12 +000011704TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011705 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011706 unsigned IndexTypeQuals,
11707 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011708 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011709 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011710}
Mike Stump11289f42009-09-09 15:08:12 +000011711
Douglas Gregord6ff3322009-08-04 16:50:30 +000011712template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011713QualType
11714TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011715 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011716 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011717 unsigned IndexTypeQuals,
11718 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011719 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011720 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011721 IndexTypeQuals, BracketsRange);
11722}
11723
11724template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011725QualType
11726TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011727 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011728 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011729 unsigned IndexTypeQuals,
11730 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011731 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011732 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011733 IndexTypeQuals, BracketsRange);
11734}
11735
11736template<typename Derived>
11737QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011738 unsigned NumElements,
11739 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011740 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011741 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011742}
Mike Stump11289f42009-09-09 15:08:12 +000011743
Douglas Gregord6ff3322009-08-04 16:50:30 +000011744template<typename Derived>
11745QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11746 unsigned NumElements,
11747 SourceLocation AttributeLoc) {
11748 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11749 NumElements, true);
11750 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011751 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11752 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011753 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011754}
Mike Stump11289f42009-09-09 15:08:12 +000011755
Douglas Gregord6ff3322009-08-04 16:50:30 +000011756template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011757QualType
11758TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011759 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011760 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011761 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011762}
Mike Stump11289f42009-09-09 15:08:12 +000011763
Douglas Gregord6ff3322009-08-04 16:50:30 +000011764template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011765QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11766 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011767 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011768 const FunctionProtoType::ExtProtoInfo &EPI) {
11769 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011770 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011771 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011772 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011773}
Mike Stump11289f42009-09-09 15:08:12 +000011774
Douglas Gregord6ff3322009-08-04 16:50:30 +000011775template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011776QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11777 return SemaRef.Context.getFunctionNoProtoType(T);
11778}
11779
11780template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011781QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11782 assert(D && "no decl found");
11783 if (D->isInvalidDecl()) return QualType();
11784
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011785 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011786 TypeDecl *Ty;
11787 if (isa<UsingDecl>(D)) {
11788 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011789 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011790 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11791
11792 // A valid resolved using typename decl points to exactly one type decl.
11793 assert(++Using->shadow_begin() == Using->shadow_end());
11794 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011795
John McCallb96ec562009-12-04 22:46:56 +000011796 } else {
11797 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11798 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11799 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11800 }
11801
11802 return SemaRef.Context.getTypeDeclType(Ty);
11803}
11804
11805template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011806QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11807 SourceLocation Loc) {
11808 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011809}
11810
11811template<typename Derived>
11812QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11813 return SemaRef.Context.getTypeOfType(Underlying);
11814}
11815
11816template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011817QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11818 SourceLocation Loc) {
11819 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011820}
11821
11822template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011823QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11824 UnaryTransformType::UTTKind UKind,
11825 SourceLocation Loc) {
11826 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11827}
11828
11829template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011830QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011831 TemplateName Template,
11832 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011833 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011834 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011835}
Mike Stump11289f42009-09-09 15:08:12 +000011836
Douglas Gregor1135c352009-08-06 05:28:30 +000011837template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011838QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11839 SourceLocation KWLoc) {
11840 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11841}
11842
11843template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011844QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000011845 SourceLocation KWLoc,
11846 bool isReadPipe) {
11847 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
11848 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000011849}
11850
11851template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011852TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011853TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011854 bool TemplateKW,
11855 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011856 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011857 Template);
11858}
11859
11860template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011861TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011862TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11863 const IdentifierInfo &Name,
11864 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011865 QualType ObjectType,
11866 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011867 UnqualifiedId TemplateName;
11868 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011869 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011870 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011871 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011872 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011873 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011874 /*EnteringContext=*/false,
11875 Template);
John McCall31f82722010-11-12 08:19:04 +000011876 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011877}
Mike Stump11289f42009-09-09 15:08:12 +000011878
Douglas Gregora16548e2009-08-11 05:31:07 +000011879template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011880TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011881TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011882 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011883 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011884 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011885 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011886 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011887 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011888 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011889 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011890 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011891 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011892 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011893 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011894 /*EnteringContext=*/false,
11895 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011896 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011897}
Chad Rosier1dcde962012-08-08 18:46:20 +000011898
Douglas Gregor71395fa2009-11-04 00:56:37 +000011899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011900ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011901TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11902 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011903 Expr *OrigCallee,
11904 Expr *First,
11905 Expr *Second) {
11906 Expr *Callee = OrigCallee->IgnoreParenCasts();
11907 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011908
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011909 if (First->getObjectKind() == OK_ObjCProperty) {
11910 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11911 if (BinaryOperator::isAssignmentOp(Opc))
11912 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11913 First, Second);
11914 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11915 if (Result.isInvalid())
11916 return ExprError();
11917 First = Result.get();
11918 }
11919
11920 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11921 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11922 if (Result.isInvalid())
11923 return ExprError();
11924 Second = Result.get();
11925 }
11926
Douglas Gregora16548e2009-08-11 05:31:07 +000011927 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011928 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011929 if (!First->getType()->isOverloadableType() &&
11930 !Second->getType()->isOverloadableType())
11931 return getSema().CreateBuiltinArraySubscriptExpr(First,
11932 Callee->getLocStart(),
11933 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011934 } else if (Op == OO_Arrow) {
11935 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011936 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11937 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011938 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011939 // The argument is not of overloadable type, so try to create a
11940 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011941 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011942 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011943
John McCallb268a282010-08-23 23:25:46 +000011944 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011945 }
11946 } else {
John McCallb268a282010-08-23 23:25:46 +000011947 if (!First->getType()->isOverloadableType() &&
11948 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011949 // Neither of the arguments is an overloadable type, so try to
11950 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011951 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011952 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011953 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011954 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011956
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011957 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011958 }
11959 }
Mike Stump11289f42009-09-09 15:08:12 +000011960
11961 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011962 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011963 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011964
John McCallb268a282010-08-23 23:25:46 +000011965 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011966 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011967 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011968 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011969 // If we've resolved this to a particular non-member function, just call
11970 // that function. If we resolved it to a member function,
11971 // CreateOverloaded* will find that function for us.
11972 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11973 if (!isa<CXXMethodDecl>(ND))
11974 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011975 }
Mike Stump11289f42009-09-09 15:08:12 +000011976
Douglas Gregora16548e2009-08-11 05:31:07 +000011977 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011978 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011979 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011980
Douglas Gregora16548e2009-08-11 05:31:07 +000011981 // Create the overloaded operator invocation for unary operators.
11982 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011983 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011984 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011985 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011986 }
Mike Stump11289f42009-09-09 15:08:12 +000011987
Douglas Gregore9d62932011-07-15 16:25:15 +000011988 if (Op == OO_Subscript) {
11989 SourceLocation LBrace;
11990 SourceLocation RBrace;
11991
11992 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011993 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011994 LBrace = SourceLocation::getFromRawEncoding(
11995 NameLoc.CXXOperatorName.BeginOpNameLoc);
11996 RBrace = SourceLocation::getFromRawEncoding(
11997 NameLoc.CXXOperatorName.EndOpNameLoc);
11998 } else {
11999 LBrace = Callee->getLocStart();
12000 RBrace = OpLoc;
12001 }
12002
12003 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12004 First, Second);
12005 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012006
Douglas Gregora16548e2009-08-11 05:31:07 +000012007 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012008 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012009 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012010 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12011 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012013
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012014 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012015}
Mike Stump11289f42009-09-09 15:08:12 +000012016
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012017template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012018ExprResult
John McCallb268a282010-08-23 23:25:46 +000012019TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012020 SourceLocation OperatorLoc,
12021 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012022 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012023 TypeSourceInfo *ScopeType,
12024 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012025 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012026 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012027 QualType BaseType = Base->getType();
12028 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012029 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012030 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012031 !BaseType->getAs<PointerType>()->getPointeeType()
12032 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012033 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012034 return SemaRef.BuildPseudoDestructorExpr(
12035 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12036 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012037 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012038
Douglas Gregor678f90d2010-02-25 01:56:36 +000012039 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012040 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12041 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12042 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12043 NameInfo.setNamedTypeInfo(DestroyedType);
12044
Richard Smith8e4a3862012-05-15 06:15:11 +000012045 // The scope type is now known to be a valid nested name specifier
12046 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012047 if (ScopeType) {
12048 if (!ScopeType->getType()->getAs<TagType>()) {
12049 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12050 diag::err_expected_class_or_namespace)
12051 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12052 return ExprError();
12053 }
12054 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12055 CCLoc);
12056 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012057
Abramo Bagnara7945c982012-01-27 09:46:47 +000012058 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012059 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012060 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012061 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012062 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012063 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012064 /*TemplateArgs*/ nullptr,
12065 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012066}
12067
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012068template<typename Derived>
12069StmtResult
12070TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012071 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012072 CapturedDecl *CD = S->getCapturedDecl();
12073 unsigned NumParams = CD->getNumParams();
12074 unsigned ContextParamPos = CD->getContextParamPosition();
12075 SmallVector<Sema::CapturedParamNameType, 4> Params;
12076 for (unsigned I = 0; I < NumParams; ++I) {
12077 if (I != ContextParamPos) {
12078 Params.push_back(
12079 std::make_pair(
12080 CD->getParam(I)->getName(),
12081 getDerived().TransformType(CD->getParam(I)->getType())));
12082 } else {
12083 Params.push_back(std::make_pair(StringRef(), QualType()));
12084 }
12085 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012086 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012087 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012088 StmtResult Body;
12089 {
12090 Sema::CompoundScopeRAII CompoundScope(getSema());
12091 Body = getDerived().TransformStmt(S->getCapturedStmt());
12092 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012093
12094 if (Body.isInvalid()) {
12095 getSema().ActOnCapturedRegionError();
12096 return StmtError();
12097 }
12098
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012099 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012100}
12101
Douglas Gregord6ff3322009-08-04 16:50:30 +000012102} // end namespace clang
12103
Hans Wennborg59dbe862015-09-29 20:56:43 +000012104#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H