blob: 3ab6019f0ec31b9ebf0bc96e3960d87f1b18052e [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
Richard Smith151c4562016-12-20 21:35:28 +0000460 /// Transform the set of declarations in an OverloadExpr.
461 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
462 LookupResult &R);
463
Douglas Gregor14454802011-02-25 02:25:35 +0000464 /// \brief Transform the given nested-name-specifier with source-location
465 /// information.
466 ///
467 /// By default, transforms all of the types and declarations within the
468 /// nested-name-specifier. Subclasses may override this function to provide
469 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 NestedNameSpecifierLoc
471 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
472 QualType ObjectType = QualType(),
473 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000474
Douglas Gregorf816bd72009-09-03 22:13:48 +0000475 /// \brief Transform the given declaration name.
476 ///
477 /// By default, transforms the types of conversion function, constructor,
478 /// and destructor names and then (if needed) rebuilds the declaration name.
479 /// Identifiers and selectors are returned unmodified. Sublcasses may
480 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000481 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000482 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000483
Douglas Gregord6ff3322009-08-04 16:50:30 +0000484 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000485 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000486 /// \param SS The nested-name-specifier that qualifies the template
487 /// name. This nested-name-specifier must already have been transformed.
488 ///
489 /// \param Name The template name to transform.
490 ///
491 /// \param NameLoc The source location of the template name.
492 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000493 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000494 /// access expression, this is the type of the object whose member template
495 /// is being referenced.
496 ///
497 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
498 /// also refers to a name within the current (lexical) scope, this is the
499 /// declaration it refers to.
500 ///
501 /// By default, transforms the template name by transforming the declarations
502 /// and nested-name-specifiers that occur within the template name.
503 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000504 TemplateName
505 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
506 SourceLocation NameLoc,
507 QualType ObjectType = QualType(),
508 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000509
Douglas Gregord6ff3322009-08-04 16:50:30 +0000510 /// \brief Transform the given template argument.
511 ///
Mike Stump11289f42009-09-09 15:08:12 +0000512 /// By default, this operation transforms the type, expression, or
513 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000514 /// new template argument from the transformed result. Subclasses may
515 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000516 ///
517 /// Returns true if there was an error.
518 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000519 TemplateArgumentLoc &Output,
520 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000521
Douglas Gregor62e06f22010-12-20 17:31:10 +0000522 /// \brief Transform the given set of template arguments.
523 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000524 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000525 /// in the input set using \c TransformTemplateArgument(), and appends
526 /// the transformed arguments to the output list.
527 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 /// Note that this overload of \c TransformTemplateArguments() is merely
529 /// a convenience function. Subclasses that wish to override this behavior
530 /// should override the iterator-based member template version.
531 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000532 /// \param Inputs The set of template arguments to be transformed.
533 ///
534 /// \param NumInputs The number of template arguments in \p Inputs.
535 ///
536 /// \param Outputs The set of transformed template arguments output by this
537 /// routine.
538 ///
539 /// Returns true if an error occurred.
540 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
541 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000542 TemplateArgumentListInfo &Outputs,
543 bool Uneval = false) {
544 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
545 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547
548 /// \brief Transform the given set of template arguments.
549 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000550 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000551 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000554 /// \param First An iterator to the first template argument.
555 ///
556 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000557 ///
558 /// \param Outputs The set of transformed template arguments output by this
559 /// routine.
560 ///
561 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000562 template<typename InputIterator>
563 bool TransformTemplateArguments(InputIterator First,
564 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000565 TemplateArgumentListInfo &Outputs,
566 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000567
John McCall0ad16662009-10-29 08:12:44 +0000568 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
569 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
570 TemplateArgumentLoc &ArgLoc);
571
John McCallbcd03502009-12-07 02:54:59 +0000572 /// \brief Fakes up a TypeSourceInfo for a type.
573 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
574 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000575 getDerived().getBaseLocation());
576 }
Mike Stump11289f42009-09-09 15:08:12 +0000577
John McCall550e0c22009-10-21 00:40:46 +0000578#define ABSTRACT_TYPELOC(CLASS, PARENT)
579#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000580 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000581#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582
Richard Smith2e321552014-11-12 02:00:47 +0000583 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000584 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
585 FunctionProtoTypeLoc TL,
586 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000587 unsigned ThisTypeQuals,
588 Fn TransformExceptionSpec);
589
590 bool TransformExceptionSpec(SourceLocation Loc,
591 FunctionProtoType::ExceptionSpecInfo &ESI,
592 SmallVectorImpl<QualType> &Exceptions,
593 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000594
David Majnemerfad8f482013-10-15 09:33:02 +0000595 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000596
Chad Rosier1dcde962012-08-08 18:46:20 +0000597 QualType
John McCall31f82722010-11-12 08:19:04 +0000598 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
599 TemplateSpecializationTypeLoc TL,
600 TemplateName Template);
601
Chad Rosier1dcde962012-08-08 18:46:20 +0000602 QualType
John McCall31f82722010-11-12 08:19:04 +0000603 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
604 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000605 TemplateName Template,
606 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000607
Nico Weberc153d242014-07-28 00:02:09 +0000608 QualType TransformDependentTemplateSpecializationType(
609 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
610 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000611
John McCall58f10c32010-03-11 09:03:00 +0000612 /// \brief Transforms the parameters of a function type into the
613 /// given vectors.
614 ///
615 /// The result vectors should be kept in sync; null entries in the
616 /// variables vector are acceptable.
617 ///
618 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000619 bool TransformFunctionTypeParams(
620 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
621 const QualType *ParamTypes,
622 const FunctionProtoType::ExtParameterInfo *ParamInfos,
623 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
624 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000625
626 /// \brief Transforms a single function-type parameter. Return null
627 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000628 ///
629 /// \param indexAdjustment - A number to add to the parameter's
630 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000631 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000632 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000633 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000634 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000635
John McCall31f82722010-11-12 08:19:04 +0000636 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000637
John McCalldadc5752010-08-24 06:29:42 +0000638 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
639 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000640
Faisal Vali2cba1332013-10-23 06:44:28 +0000641 TemplateParameterList *TransformTemplateParameterList(
642 TemplateParameterList *TPL) {
643 return TPL;
644 }
645
Richard Smithdb2630f2012-10-21 03:28:35 +0000646 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000647
Richard Smithdb2630f2012-10-21 03:28:35 +0000648 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000649 bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
652 ExprResult TransformParenDependentScopeDeclRefExpr(
653 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
654 TypeSourceInfo **RecoveryTSI);
655
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000656 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000657
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000658// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
659// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000660#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000661 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000662 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000663#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000664 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000665 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000666#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000667#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000668
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000669#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000670 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000671 OMPClause *Transform ## Class(Class *S);
672#include "clang/Basic/OpenMPKinds.def"
673
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 /// \brief Build a new pointer type given its pointee type.
675 ///
676 /// By default, performs semantic analysis when building the pointer type.
677 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000678 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679
680 /// \brief Build a new block pointer type given its pointee type.
681 ///
Mike Stump11289f42009-09-09 15:08:12 +0000682 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000684 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685
John McCall70dd5f62009-10-30 00:06:24 +0000686 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
John McCall70dd5f62009-10-30 00:06:24 +0000688 /// By default, performs semantic analysis when building the
689 /// reference type. Subclasses may override this routine to provide
690 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 ///
John McCall70dd5f62009-10-30 00:06:24 +0000692 /// \param LValue whether the type was written with an lvalue sigil
693 /// or an rvalue sigil.
694 QualType RebuildReferenceType(QualType ReferentType,
695 bool LValue,
696 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000697
Douglas Gregord6ff3322009-08-04 16:50:30 +0000698 /// \brief Build a new member pointer type given the pointee type and the
699 /// class type it refers into.
700 ///
701 /// By default, performs semantic analysis when building the member pointer
702 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000703 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
704 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000705
Manman Rene6be26c2016-09-13 17:25:08 +0000706 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
707 SourceLocation ProtocolLAngleLoc,
708 ArrayRef<ObjCProtocolDecl *> Protocols,
709 ArrayRef<SourceLocation> ProtocolLocs,
710 SourceLocation ProtocolRAngleLoc);
711
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000712 /// \brief Build an Objective-C object type.
713 ///
714 /// By default, performs semantic analysis when building the object type.
715 /// Subclasses may override this routine to provide different behavior.
716 QualType RebuildObjCObjectType(QualType BaseType,
717 SourceLocation Loc,
718 SourceLocation TypeArgsLAngleLoc,
719 ArrayRef<TypeSourceInfo *> TypeArgs,
720 SourceLocation TypeArgsRAngleLoc,
721 SourceLocation ProtocolLAngleLoc,
722 ArrayRef<ObjCProtocolDecl *> Protocols,
723 ArrayRef<SourceLocation> ProtocolLocs,
724 SourceLocation ProtocolRAngleLoc);
725
726 /// \brief Build a new Objective-C object pointer type given the pointee type.
727 ///
728 /// By default, directly builds the pointer type, with no additional semantic
729 /// analysis.
730 QualType RebuildObjCObjectPointerType(QualType PointeeType,
731 SourceLocation Star);
732
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// \brief Build a new array type given the element type, size
734 /// modifier, size of the array (if known), size expression, and index type
735 /// qualifiers.
736 ///
737 /// By default, performs semantic analysis when building the array type.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 QualType RebuildArrayType(QualType ElementType,
741 ArrayType::ArraySizeModifier SizeMod,
742 const llvm::APInt *Size,
743 Expr *SizeExpr,
744 unsigned IndexTypeQuals,
745 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 /// \brief Build a new constant array type given the element type, size
748 /// modifier, (known) size of the array, and index type qualifiers.
749 ///
750 /// By default, performs semantic analysis when building the array type.
751 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000752 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753 ArrayType::ArraySizeModifier SizeMod,
754 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000755 unsigned IndexTypeQuals,
756 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 /// \brief Build a new incomplete array type given the element type, size
759 /// modifier, and index type qualifiers.
760 ///
761 /// By default, performs semantic analysis when building the array type.
762 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000763 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000765 unsigned IndexTypeQuals,
766 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000767
Mike Stump11289f42009-09-09 15:08:12 +0000768 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000769 /// size modifier, size expression, and index type qualifiers.
770 ///
771 /// By default, performs semantic analysis when building the array type.
772 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000773 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000774 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000775 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 unsigned IndexTypeQuals,
777 SourceRange BracketsRange);
778
Mike Stump11289f42009-09-09 15:08:12 +0000779 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780 /// size modifier, size expression, and index type qualifiers.
781 ///
782 /// By default, performs semantic analysis when building the array type.
783 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000784 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000786 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 unsigned IndexTypeQuals,
788 SourceRange BracketsRange);
789
790 /// \brief Build a new vector type given the element type and
791 /// number of elements.
792 ///
793 /// By default, performs semantic analysis when building the vector type.
794 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000795 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000796 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000797
Douglas Gregord6ff3322009-08-04 16:50:30 +0000798 /// \brief Build a new extended vector type given the element type and
799 /// number of elements.
800 ///
801 /// By default, performs semantic analysis when building the vector type.
802 /// Subclasses may override this routine to provide different behavior.
803 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
804 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000805
806 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 /// given the element type and number of elements.
808 ///
809 /// By default, performs semantic analysis when building the vector type.
810 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000811 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000812 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000814
Douglas Gregord6ff3322009-08-04 16:50:30 +0000815 /// \brief Build a new function type.
816 ///
817 /// By default, performs semantic analysis when building the function type.
818 /// Subclasses may override this routine to provide different behavior.
819 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000820 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000821 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000822
John McCall550e0c22009-10-21 00:40:46 +0000823 /// \brief Build a new unprototyped function type.
824 QualType RebuildFunctionNoProtoType(QualType ResultType);
825
John McCallb96ec562009-12-04 22:46:56 +0000826 /// \brief Rebuild an unresolved typename type, given the decl that
827 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000828 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000829
Douglas Gregord6ff3322009-08-04 16:50:30 +0000830 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000831 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000832 return SemaRef.Context.getTypeDeclType(Typedef);
833 }
834
835 /// \brief Build a new class/struct/union type.
836 QualType RebuildRecordType(RecordDecl *Record) {
837 return SemaRef.Context.getTypeDeclType(Record);
838 }
839
840 /// \brief Build a new Enum type.
841 QualType RebuildEnumType(EnumDecl *Enum) {
842 return SemaRef.Context.getTypeDeclType(Enum);
843 }
John McCallfcc33b02009-09-05 00:15:47 +0000844
Mike Stump11289f42009-09-09 15:08:12 +0000845 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000846 ///
847 /// By default, performs semantic analysis when building the typeof type.
848 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000849 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000850
Mike Stump11289f42009-09-09 15:08:12 +0000851 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000852 ///
853 /// By default, builds a new TypeOfType with the given underlying type.
854 QualType RebuildTypeOfType(QualType Underlying);
855
Alexis Hunte852b102011-05-24 22:41:36 +0000856 /// \brief Build a new unary transform type.
857 QualType RebuildUnaryTransformType(QualType BaseType,
858 UnaryTransformType::UTTKind UKind,
859 SourceLocation Loc);
860
Richard Smith74aeef52013-04-26 16:15:35 +0000861 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000862 ///
863 /// By default, performs semantic analysis when building the decltype type.
864 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000865 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000866
Richard Smith74aeef52013-04-26 16:15:35 +0000867 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000868 ///
869 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000870 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000871 // Note, IsDependent is always false here: we implicitly convert an 'auto'
872 // which has been deduced to a dependent type into an undeduced 'auto', so
873 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000874 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000875 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new template specialization type.
879 ///
880 /// By default, performs semantic analysis when building the template
881 /// specialization type. Subclasses may override this routine to provide
882 /// different behavior.
883 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000884 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000885 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000886
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000887 /// \brief Build a new parenthesized type.
888 ///
889 /// By default, builds a new ParenType type from the inner type.
890 /// Subclasses may override this routine to provide different behavior.
891 QualType RebuildParenType(QualType InnerType) {
892 return SemaRef.Context.getParenType(InnerType);
893 }
894
Douglas Gregord6ff3322009-08-04 16:50:30 +0000895 /// \brief Build a new qualified name type.
896 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000897 /// By default, builds a new ElaboratedType type from the keyword,
898 /// the nested-name-specifier and the named type.
899 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000900 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
901 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000902 NestedNameSpecifierLoc QualifierLoc,
903 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000904 return SemaRef.Context.getElaboratedType(Keyword,
905 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000906 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000907 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000908
909 /// \brief Build a new typename type that refers to a template-id.
910 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000911 /// By default, builds a new DependentNameType type from the
912 /// nested-name-specifier and the given type. Subclasses may override
913 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000914 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000915 ElaboratedTypeKeyword Keyword,
916 NestedNameSpecifierLoc QualifierLoc,
917 const IdentifierInfo *Name,
918 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000919 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000920 // Rebuild the template name.
921 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000922 CXXScopeSpec SS;
923 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000924 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
926 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
Douglas Gregora7a795b2011-03-01 20:11:18 +0000928 if (InstName.isNull())
929 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregora7a795b2011-03-01 20:11:18 +0000931 // If it's still dependent, make a dependent specialization.
932 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000933 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
934 QualifierLoc.getNestedNameSpecifier(),
935 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000936 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000937
Douglas Gregora7a795b2011-03-01 20:11:18 +0000938 // Otherwise, make an elaborated type wrapping a non-dependent
939 // specialization.
940 QualType T =
941 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
942 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000943
Craig Topperc3ec1492014-05-26 06:22:03 +0000944 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000945 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000946
947 return SemaRef.Context.getElaboratedType(Keyword,
948 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000949 T);
950 }
951
Douglas Gregord6ff3322009-08-04 16:50:30 +0000952 /// \brief Build a new typename type that refers to an identifier.
953 ///
954 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000955 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000956 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000957 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000958 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000959 NestedNameSpecifierLoc QualifierLoc,
960 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000961 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000962 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000963 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000965 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 // If the name is still dependent, just build a new dependent name type.
967 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000968 return SemaRef.Context.getDependentNameType(Keyword,
969 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000970 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000971 }
972
Abramo Bagnara6150c882010-05-11 21:36:43 +0000973 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000974 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000975 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000976
977 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
978
Abramo Bagnarad7548482010-05-19 21:37:53 +0000979 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000980 // into a non-dependent elaborated-type-specifier. Find the tag we're
981 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000982 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000983 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
984 if (!DC)
985 return QualType();
986
John McCallbf8c5192010-05-27 06:40:31 +0000987 if (SemaRef.RequireCompleteDeclContext(SS, DC))
988 return QualType();
989
Craig Topperc3ec1492014-05-26 06:22:03 +0000990 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000991 SemaRef.LookupQualifiedName(Result, DC);
992 switch (Result.getResultKind()) {
993 case LookupResult::NotFound:
994 case LookupResult::NotFoundInCurrentInstantiation:
995 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000996
Douglas Gregore677daf2010-03-31 22:19:08 +0000997 case LookupResult::Found:
998 Tag = Result.getAsSingle<TagDecl>();
999 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001000
Douglas Gregore677daf2010-03-31 22:19:08 +00001001 case LookupResult::FoundOverloaded:
1002 case LookupResult::FoundUnresolvedValue:
1003 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001004
Douglas Gregore677daf2010-03-31 22:19:08 +00001005 case LookupResult::Ambiguous:
1006 // Let the LookupResult structure handle ambiguities.
1007 return QualType();
1008 }
1009
1010 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001011 // Check where the name exists but isn't a tag type and use that to emit
1012 // better diagnostics.
1013 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1014 SemaRef.LookupQualifiedName(Result, DC);
1015 switch (Result.getResultKind()) {
1016 case LookupResult::Found:
1017 case LookupResult::FoundOverloaded:
1018 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001019 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001020 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1021 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1022 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001023 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1024 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001025 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001026 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001027 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001028 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001029 break;
1030 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001031 return QualType();
1032 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001033
Richard Trieucaa33d32011-06-10 03:11:26 +00001034 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001035 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001036 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001037 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1038 return QualType();
1039 }
1040
1041 // Build the elaborated-type-specifier type.
1042 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001043 return SemaRef.Context.getElaboratedType(Keyword,
1044 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001045 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001046 }
Mike Stump11289f42009-09-09 15:08:12 +00001047
Douglas Gregor822d0302011-01-12 17:07:58 +00001048 /// \brief Build a new pack expansion type.
1049 ///
1050 /// By default, builds a new PackExpansionType type from the given pattern.
1051 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001052 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001053 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001054 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001055 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001056 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1057 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001058 }
1059
Eli Friedman0dfb8892011-10-06 23:00:33 +00001060 /// \brief Build a new atomic type given its value type.
1061 ///
1062 /// By default, performs semantic analysis when building the atomic type.
1063 /// Subclasses may override this routine to provide different behavior.
1064 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1065
Xiuli Pan9c14e282016-01-09 12:53:17 +00001066 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001067 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1068 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001069
Douglas Gregor71dc5092009-08-06 06:41:21 +00001070 /// \brief Build a new template name given a nested name specifier, a flag
1071 /// indicating whether the "template" keyword was provided, and the template
1072 /// that the template name refers to.
1073 ///
1074 /// By default, builds the new template name directly. Subclasses may override
1075 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001076 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001077 bool TemplateKW,
1078 TemplateDecl *Template);
1079
Douglas Gregor71dc5092009-08-06 06:41:21 +00001080 /// \brief Build a new template name given a nested name specifier and the
1081 /// name that is referred to as a template.
1082 ///
1083 /// By default, performs semantic analysis to determine whether the name can
1084 /// be resolved to a specific template, then builds the appropriate kind of
1085 /// template name. Subclasses may override this routine to provide different
1086 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001087 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1088 const IdentifierInfo &Name,
1089 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001090 QualType ObjectType,
1091 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregor71395fa2009-11-04 00:56:37 +00001093 /// \brief Build a new template name given a nested name specifier and the
1094 /// overloaded operator name that is referred to as a template.
1095 ///
1096 /// By default, performs semantic analysis to determine whether the name can
1097 /// be resolved to a specific template, then builds the appropriate kind of
1098 /// template name. Subclasses may override this routine to provide different
1099 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001100 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001101 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001102 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001103 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001104
1105 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001106 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001107 ///
1108 /// By default, performs semantic analysis to determine whether the name can
1109 /// be resolved to a specific template, then builds the appropriate kind of
1110 /// template name. Subclasses may override this routine to provide different
1111 /// behavior.
1112 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1113 const TemplateArgument &ArgPack) {
1114 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1115 }
1116
Douglas Gregorebe10102009-08-20 07:17:43 +00001117 /// \brief Build a new compound statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001121 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 MultiStmtArg Statements,
1123 SourceLocation RBraceLoc,
1124 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001125 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 IsStmtExpr);
1127 }
1128
1129 /// \brief Build a new case statement.
1130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001133 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001134 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001137 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001138 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 ColonLoc);
1140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 /// \brief Attach the body to a new case statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001147 getSema().ActOnCaseStmtBody(S, Body);
1148 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 /// \brief Build a new default statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001155 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001156 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001157 Stmt *SubStmt) {
1158 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001159 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 }
Mike Stump11289f42009-09-09 15:08:12 +00001161
Douglas Gregorebe10102009-08-20 07:17:43 +00001162 /// \brief Build a new label statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001166 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1167 SourceLocation ColonLoc, Stmt *SubStmt) {
1168 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001169 }
Mike Stump11289f42009-09-09 15:08:12 +00001170
Richard Smithc202b282012-04-14 00:33:13 +00001171 /// \brief Build a new label statement.
1172 ///
1173 /// By default, performs semantic analysis to build the new statement.
1174 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001175 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1176 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001177 Stmt *SubStmt) {
1178 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1179 }
1180
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 /// \brief Build a new "if" statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001185 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001186 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001187 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001188 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001189 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Start building a new switch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001196 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001197 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001198 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 }
Mike Stump11289f42009-09-09 15:08:12 +00001200
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 /// \brief Attach the body to the switch statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001205 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001206 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001207 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
1209
1210 /// \brief Build a new while statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001214 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1215 Sema::ConditionResult Cond, Stmt *Body) {
1216 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 /// \brief Build a new do-while statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001223 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001224 SourceLocation WhileLoc, SourceLocation LParenLoc,
1225 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001226 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1227 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
1229
1230 /// \brief Build a new for statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001234 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001235 Stmt *Init, Sema::ConditionResult Cond,
1236 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1237 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001238 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001239 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregorebe10102009-08-20 07:17:43 +00001242 /// \brief Build a new goto statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001246 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1247 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001248 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 }
1250
1251 /// \brief Build a new indirect goto statement.
1252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001255 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001256 SourceLocation StarLoc,
1257 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001258 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Douglas Gregorebe10102009-08-20 07:17:43 +00001261 /// \brief Build a new return statement.
1262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001265 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001266 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Douglas Gregorebe10102009-08-20 07:17:43 +00001269 /// \brief Build a new declaration statement.
1270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001273 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001274 SourceLocation StartLoc, SourceLocation EndLoc) {
1275 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001276 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001277 }
Mike Stump11289f42009-09-09 15:08:12 +00001278
Anders Carlssonaaeef072010-01-24 05:50:09 +00001279 /// \brief Build a new inline asm statement.
1280 ///
1281 /// By default, performs semantic analysis to build the new statement.
1282 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001283 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1284 bool IsVolatile, unsigned NumOutputs,
1285 unsigned NumInputs, IdentifierInfo **Names,
1286 MultiExprArg Constraints, MultiExprArg Exprs,
1287 Expr *AsmString, MultiExprArg Clobbers,
1288 SourceLocation RParenLoc) {
1289 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1290 NumInputs, Names, Constraints, Exprs,
1291 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001292 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001293
Chad Rosier32503022012-06-11 20:47:18 +00001294 /// \brief Build a new MS style inline asm statement.
1295 ///
1296 /// By default, performs semantic analysis to build the new statement.
1297 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001298 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001299 ArrayRef<Token> AsmToks,
1300 StringRef AsmString,
1301 unsigned NumOutputs, unsigned NumInputs,
1302 ArrayRef<StringRef> Constraints,
1303 ArrayRef<StringRef> Clobbers,
1304 ArrayRef<Expr*> Exprs,
1305 SourceLocation EndLoc) {
1306 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1307 NumOutputs, NumInputs,
1308 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001309 }
1310
Richard Smith9f690bd2015-10-27 06:02:45 +00001311 /// \brief Build a new co_return statement.
1312 ///
1313 /// By default, performs semantic analysis to build the new statement.
1314 /// Subclasses may override this routine to provide different behavior.
1315 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1316 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1317 }
1318
1319 /// \brief Build a new co_await expression.
1320 ///
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1324 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1325 }
1326
1327 /// \brief Build a new co_yield expression.
1328 ///
1329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
1331 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1332 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1333 }
1334
James Dennett2a4d13c2012-06-15 07:13:21 +00001335 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001340 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001341 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001342 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001343 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001344 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001345 }
1346
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001347 /// \brief Rebuild an Objective-C exception declaration.
1348 ///
1349 /// By default, performs semantic analysis to build the new declaration.
1350 /// Subclasses may override this routine to provide different behavior.
1351 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1352 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001353 return getSema().BuildObjCExceptionDecl(TInfo, T,
1354 ExceptionDecl->getInnerLocStart(),
1355 ExceptionDecl->getLocation(),
1356 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001358
James Dennett2a4d13c2012-06-15 07:13:21 +00001359 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001363 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001364 SourceLocation RParenLoc,
1365 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001366 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001367 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001368 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001370
James Dennett2a4d13c2012-06-15 07:13:21 +00001371 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001375 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001376 Stmt *Body) {
1377 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001379
James Dennett2a4d13c2012-06-15 07:13:21 +00001380 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001381 ///
1382 /// By default, performs semantic analysis to build the new statement.
1383 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001384 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001385 Expr *Operand) {
1386 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001388
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001389 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001390 ///
1391 /// By default, performs semantic analysis to build the new statement.
1392 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001393 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001394 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001395 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001396 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001397 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001398 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001399 return getSema().ActOnOpenMPExecutableDirective(
1400 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001401 }
1402
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001403 /// \brief Build a new OpenMP 'if' clause.
1404 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001405 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001406 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001407 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1408 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001409 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001410 SourceLocation NameModifierLoc,
1411 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001412 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001413 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1414 LParenLoc, NameModifierLoc, ColonLoc,
1415 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001416 }
1417
Alexey Bataev3778b602014-07-17 07:32:53 +00001418 /// \brief Build a new OpenMP 'final' clause.
1419 ///
1420 /// By default, performs semantic analysis to build the new OpenMP clause.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1423 SourceLocation LParenLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1426 EndLoc);
1427 }
1428
Alexey Bataev568a8332014-03-06 06:15:19 +00001429 /// \brief Build a new OpenMP 'num_threads' clause.
1430 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001431 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1438 LParenLoc, EndLoc);
1439 }
1440
Alexey Bataev62c87d22014-03-21 04:51:18 +00001441 /// \brief Build a new OpenMP 'safelen' clause.
1442 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001443 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1446 SourceLocation LParenLoc,
1447 SourceLocation EndLoc) {
1448 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1449 }
1450
Alexey Bataev66b15b52015-08-21 11:14:16 +00001451 /// \brief Build a new OpenMP 'simdlen' clause.
1452 ///
1453 /// By default, performs semantic analysis to build the new OpenMP clause.
1454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1456 SourceLocation LParenLoc,
1457 SourceLocation EndLoc) {
1458 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1459 }
1460
Alexander Musman8bd31e62014-05-27 15:12:19 +00001461 /// \brief Build a new OpenMP 'collapse' clause.
1462 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001463 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001464 /// Subclasses may override this routine to provide different behavior.
1465 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1466 SourceLocation LParenLoc,
1467 SourceLocation EndLoc) {
1468 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1469 EndLoc);
1470 }
1471
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001472 /// \brief Build a new OpenMP 'default' clause.
1473 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001474 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001475 /// Subclasses may override this routine to provide different behavior.
1476 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1477 SourceLocation KindKwLoc,
1478 SourceLocation StartLoc,
1479 SourceLocation LParenLoc,
1480 SourceLocation EndLoc) {
1481 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1482 StartLoc, LParenLoc, EndLoc);
1483 }
1484
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001485 /// \brief Build a new OpenMP 'proc_bind' clause.
1486 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001487 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001488 /// Subclasses may override this routine to provide different behavior.
1489 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1490 SourceLocation KindKwLoc,
1491 SourceLocation StartLoc,
1492 SourceLocation LParenLoc,
1493 SourceLocation EndLoc) {
1494 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1495 StartLoc, LParenLoc, EndLoc);
1496 }
1497
Alexey Bataev56dafe82014-06-20 07:16:17 +00001498 /// \brief Build a new OpenMP 'schedule' clause.
1499 ///
1500 /// By default, performs semantic analysis to build the new OpenMP clause.
1501 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001502 OMPClause *RebuildOMPScheduleClause(
1503 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1504 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1505 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1506 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001507 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001508 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1509 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001510 }
1511
Alexey Bataev10e775f2015-07-30 11:36:16 +00001512 /// \brief Build a new OpenMP 'ordered' clause.
1513 ///
1514 /// By default, performs semantic analysis to build the new OpenMP clause.
1515 /// Subclasses may override this routine to provide different behavior.
1516 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1517 SourceLocation EndLoc,
1518 SourceLocation LParenLoc, Expr *Num) {
1519 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1520 }
1521
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001522 /// \brief Build a new OpenMP 'private' clause.
1523 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001524 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001525 /// Subclasses may override this routine to provide different behavior.
1526 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1527 SourceLocation StartLoc,
1528 SourceLocation LParenLoc,
1529 SourceLocation EndLoc) {
1530 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1531 EndLoc);
1532 }
1533
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001534 /// \brief Build a new OpenMP 'firstprivate' clause.
1535 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001536 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001537 /// Subclasses may override this routine to provide different behavior.
1538 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1539 SourceLocation StartLoc,
1540 SourceLocation LParenLoc,
1541 SourceLocation EndLoc) {
1542 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1543 EndLoc);
1544 }
1545
Alexander Musman1bb328c2014-06-04 13:06:39 +00001546 /// \brief Build a new OpenMP 'lastprivate' clause.
1547 ///
1548 /// By default, performs semantic analysis to build the new OpenMP clause.
1549 /// Subclasses may override this routine to provide different behavior.
1550 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1551 SourceLocation StartLoc,
1552 SourceLocation LParenLoc,
1553 SourceLocation EndLoc) {
1554 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1555 EndLoc);
1556 }
1557
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001558 /// \brief Build a new OpenMP 'shared' clause.
1559 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001560 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001561 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001562 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1563 SourceLocation StartLoc,
1564 SourceLocation LParenLoc,
1565 SourceLocation EndLoc) {
1566 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1567 EndLoc);
1568 }
1569
Alexey Bataevc5e02582014-06-16 07:08:35 +00001570 /// \brief Build a new OpenMP 'reduction' clause.
1571 ///
1572 /// By default, performs semantic analysis to build the new statement.
1573 /// Subclasses may override this routine to provide different behavior.
1574 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1575 SourceLocation StartLoc,
1576 SourceLocation LParenLoc,
1577 SourceLocation ColonLoc,
1578 SourceLocation EndLoc,
1579 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001580 const DeclarationNameInfo &ReductionId,
1581 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001582 return getSema().ActOnOpenMPReductionClause(
1583 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001584 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001585 }
1586
Alexander Musman8dba6642014-04-22 13:09:42 +00001587 /// \brief Build a new OpenMP 'linear' clause.
1588 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001589 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001590 /// Subclasses may override this routine to provide different behavior.
1591 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1592 SourceLocation StartLoc,
1593 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001594 OpenMPLinearClauseKind Modifier,
1595 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001596 SourceLocation ColonLoc,
1597 SourceLocation EndLoc) {
1598 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001599 Modifier, ModifierLoc, ColonLoc,
1600 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001601 }
1602
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001603 /// \brief Build a new OpenMP 'aligned' clause.
1604 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001605 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001606 /// Subclasses may override this routine to provide different behavior.
1607 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1608 SourceLocation StartLoc,
1609 SourceLocation LParenLoc,
1610 SourceLocation ColonLoc,
1611 SourceLocation EndLoc) {
1612 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1613 LParenLoc, ColonLoc, EndLoc);
1614 }
1615
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001616 /// \brief Build a new OpenMP 'copyin' clause.
1617 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001618 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001619 /// Subclasses may override this routine to provide different behavior.
1620 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1621 SourceLocation StartLoc,
1622 SourceLocation LParenLoc,
1623 SourceLocation EndLoc) {
1624 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1625 EndLoc);
1626 }
1627
Alexey Bataevbae9a792014-06-27 10:37:06 +00001628 /// \brief Build a new OpenMP 'copyprivate' clause.
1629 ///
1630 /// By default, performs semantic analysis to build the new OpenMP clause.
1631 /// Subclasses may override this routine to provide different behavior.
1632 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1633 SourceLocation StartLoc,
1634 SourceLocation LParenLoc,
1635 SourceLocation EndLoc) {
1636 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1637 EndLoc);
1638 }
1639
Alexey Bataev6125da92014-07-21 11:26:11 +00001640 /// \brief Build a new OpenMP 'flush' pseudo clause.
1641 ///
1642 /// By default, performs semantic analysis to build the new OpenMP clause.
1643 /// Subclasses may override this routine to provide different behavior.
1644 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1645 SourceLocation StartLoc,
1646 SourceLocation LParenLoc,
1647 SourceLocation EndLoc) {
1648 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1649 EndLoc);
1650 }
1651
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001652 /// \brief Build a new OpenMP 'depend' pseudo clause.
1653 ///
1654 /// By default, performs semantic analysis to build the new OpenMP clause.
1655 /// Subclasses may override this routine to provide different behavior.
1656 OMPClause *
1657 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1658 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1659 SourceLocation StartLoc, SourceLocation LParenLoc,
1660 SourceLocation EndLoc) {
1661 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1662 StartLoc, LParenLoc, EndLoc);
1663 }
1664
Michael Wonge710d542015-08-07 16:16:36 +00001665 /// \brief Build a new OpenMP 'device' clause.
1666 ///
1667 /// By default, performs semantic analysis to build the new statement.
1668 /// Subclasses may override this routine to provide different behavior.
1669 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1670 SourceLocation LParenLoc,
1671 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001672 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001673 EndLoc);
1674 }
1675
Kelvin Li0bff7af2015-11-23 05:32:03 +00001676 /// \brief Build a new OpenMP 'map' clause.
1677 ///
1678 /// By default, performs semantic analysis to build the new OpenMP clause.
1679 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001680 OMPClause *
1681 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1682 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1683 SourceLocation MapLoc, SourceLocation ColonLoc,
1684 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1685 SourceLocation LParenLoc, SourceLocation EndLoc) {
1686 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1687 IsMapTypeImplicit, MapLoc, ColonLoc,
1688 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001689 }
1690
Kelvin Li099bb8c2015-11-24 20:50:12 +00001691 /// \brief Build a new OpenMP 'num_teams' clause.
1692 ///
1693 /// By default, performs semantic analysis to build the new statement.
1694 /// Subclasses may override this routine to provide different behavior.
1695 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1696 SourceLocation LParenLoc,
1697 SourceLocation EndLoc) {
1698 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1699 EndLoc);
1700 }
1701
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001702 /// \brief Build a new OpenMP 'thread_limit' clause.
1703 ///
1704 /// By default, performs semantic analysis to build the new statement.
1705 /// Subclasses may override this routine to provide different behavior.
1706 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1707 SourceLocation StartLoc,
1708 SourceLocation LParenLoc,
1709 SourceLocation EndLoc) {
1710 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1711 LParenLoc, EndLoc);
1712 }
1713
Alexey Bataeva0569352015-12-01 10:17:31 +00001714 /// \brief Build a new OpenMP 'priority' clause.
1715 ///
1716 /// By default, performs semantic analysis to build the new statement.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1719 SourceLocation LParenLoc,
1720 SourceLocation EndLoc) {
1721 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1722 EndLoc);
1723 }
1724
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001725 /// \brief Build a new OpenMP 'grainsize' clause.
1726 ///
1727 /// By default, performs semantic analysis to build the new statement.
1728 /// Subclasses may override this routine to provide different behavior.
1729 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1730 SourceLocation LParenLoc,
1731 SourceLocation EndLoc) {
1732 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1733 EndLoc);
1734 }
1735
Alexey Bataev382967a2015-12-08 12:06:20 +00001736 /// \brief Build a new OpenMP 'num_tasks' clause.
1737 ///
1738 /// By default, performs semantic analysis to build the new statement.
1739 /// Subclasses may override this routine to provide different behavior.
1740 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1741 SourceLocation LParenLoc,
1742 SourceLocation EndLoc) {
1743 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1744 EndLoc);
1745 }
1746
Alexey Bataev28c75412015-12-15 08:19:24 +00001747 /// \brief Build a new OpenMP 'hint' clause.
1748 ///
1749 /// By default, performs semantic analysis to build the new statement.
1750 /// Subclasses may override this routine to provide different behavior.
1751 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1752 SourceLocation LParenLoc,
1753 SourceLocation EndLoc) {
1754 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1755 }
1756
Carlo Bertollib4adf552016-01-15 18:50:31 +00001757 /// \brief Build a new OpenMP 'dist_schedule' clause.
1758 ///
1759 /// By default, performs semantic analysis to build the new OpenMP clause.
1760 /// Subclasses may override this routine to provide different behavior.
1761 OMPClause *
1762 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1763 Expr *ChunkSize, SourceLocation StartLoc,
1764 SourceLocation LParenLoc, SourceLocation KindLoc,
1765 SourceLocation CommaLoc, SourceLocation EndLoc) {
1766 return getSema().ActOnOpenMPDistScheduleClause(
1767 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1768 }
1769
Samuel Antao661c0902016-05-26 17:39:58 +00001770 /// \brief Build a new OpenMP 'to' clause.
1771 ///
1772 /// By default, performs semantic analysis to build the new statement.
1773 /// Subclasses may override this routine to provide different behavior.
1774 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1775 SourceLocation StartLoc,
1776 SourceLocation LParenLoc,
1777 SourceLocation EndLoc) {
1778 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1779 }
1780
Samuel Antaoec172c62016-05-26 17:49:04 +00001781 /// \brief Build a new OpenMP 'from' clause.
1782 ///
1783 /// By default, performs semantic analysis to build the new statement.
1784 /// Subclasses may override this routine to provide different behavior.
1785 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1786 SourceLocation StartLoc,
1787 SourceLocation LParenLoc,
1788 SourceLocation EndLoc) {
1789 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1790 EndLoc);
1791 }
1792
Carlo Bertolli2404b172016-07-13 15:37:16 +00001793 /// Build a new OpenMP 'use_device_ptr' clause.
1794 ///
1795 /// By default, performs semantic analysis to build the new OpenMP clause.
1796 /// Subclasses may override this routine to provide different behavior.
1797 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1798 SourceLocation StartLoc,
1799 SourceLocation LParenLoc,
1800 SourceLocation EndLoc) {
1801 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1802 EndLoc);
1803 }
1804
Carlo Bertolli70594e92016-07-13 17:16:49 +00001805 /// Build a new OpenMP 'is_device_ptr' clause.
1806 ///
1807 /// By default, performs semantic analysis to build the new OpenMP clause.
1808 /// Subclasses may override this routine to provide different behavior.
1809 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1810 SourceLocation StartLoc,
1811 SourceLocation LParenLoc,
1812 SourceLocation EndLoc) {
1813 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1814 EndLoc);
1815 }
1816
James Dennett2a4d13c2012-06-15 07:13:21 +00001817 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001818 ///
1819 /// By default, performs semantic analysis to build the new statement.
1820 /// Subclasses may override this routine to provide different behavior.
1821 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1822 Expr *object) {
1823 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1824 }
1825
James Dennett2a4d13c2012-06-15 07:13:21 +00001826 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001827 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001828 /// By default, performs semantic analysis to build the new statement.
1829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001830 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001831 Expr *Object, Stmt *Body) {
1832 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001833 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001834
James Dennett2a4d13c2012-06-15 07:13:21 +00001835 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001836 ///
1837 /// By default, performs semantic analysis to build the new statement.
1838 /// Subclasses may override this routine to provide different behavior.
1839 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1840 Stmt *Body) {
1841 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1842 }
John McCall53848232011-07-27 01:07:15 +00001843
Douglas Gregorf68a5082010-04-22 23:10:45 +00001844 /// \brief Build a new Objective-C fast enumeration statement.
1845 ///
1846 /// By default, performs semantic analysis to build the new statement.
1847 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001848 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001849 Stmt *Element,
1850 Expr *Collection,
1851 SourceLocation RParenLoc,
1852 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001853 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001854 Element,
John McCallb268a282010-08-23 23:25:46 +00001855 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001856 RParenLoc);
1857 if (ForEachStmt.isInvalid())
1858 return StmtError();
1859
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001860 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001862
Douglas Gregorebe10102009-08-20 07:17:43 +00001863 /// \brief Build a new C++ exception declaration.
1864 ///
1865 /// By default, performs semantic analysis to build the new decaration.
1866 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001867 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001868 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001869 SourceLocation StartLoc,
1870 SourceLocation IdLoc,
1871 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001872 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001873 StartLoc, IdLoc, Id);
1874 if (Var)
1875 getSema().CurContext->addDecl(Var);
1876 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001877 }
1878
1879 /// \brief Build a new C++ catch statement.
1880 ///
1881 /// By default, performs semantic analysis to build the new statement.
1882 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001883 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001884 VarDecl *ExceptionDecl,
1885 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001886 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1887 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001888 }
Mike Stump11289f42009-09-09 15:08:12 +00001889
Douglas Gregorebe10102009-08-20 07:17:43 +00001890 /// \brief Build a new C++ try statement.
1891 ///
1892 /// By default, performs semantic analysis to build the new statement.
1893 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001894 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1895 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001896 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001897 }
Mike Stump11289f42009-09-09 15:08:12 +00001898
Richard Smith02e85f32011-04-14 22:09:26 +00001899 /// \brief Build a new C++0x range-based for statement.
1900 ///
1901 /// By default, performs semantic analysis to build the new statement.
1902 /// Subclasses may override this routine to provide different behavior.
1903 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001904 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001905 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001906 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001907 Expr *Cond, Expr *Inc,
1908 Stmt *LoopVar,
1909 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001910 // If we've just learned that the range is actually an Objective-C
1911 // collection, treat this as an Objective-C fast enumeration loop.
1912 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1913 if (RangeStmt->isSingleDecl()) {
1914 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001915 if (RangeVar->isInvalidDecl())
1916 return StmtError();
1917
Douglas Gregorf7106af2013-04-08 18:40:13 +00001918 Expr *RangeExpr = RangeVar->getInit();
1919 if (!RangeExpr->isTypeDependent() &&
1920 RangeExpr->getType()->isObjCObjectPointerType())
1921 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1922 RParenLoc);
1923 }
1924 }
1925 }
1926
Richard Smithcfd53b42015-10-22 06:13:50 +00001927 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001928 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001929 Cond, Inc, LoopVar, RParenLoc,
1930 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001931 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001932
1933 /// \brief Build a new C++0x range-based for statement.
1934 ///
1935 /// By default, performs semantic analysis to build the new statement.
1936 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001937 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001938 bool IsIfExists,
1939 NestedNameSpecifierLoc QualifierLoc,
1940 DeclarationNameInfo NameInfo,
1941 Stmt *Nested) {
1942 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1943 QualifierLoc, NameInfo, Nested);
1944 }
1945
Richard Smith02e85f32011-04-14 22:09:26 +00001946 /// \brief Attach body to a C++0x range-based for statement.
1947 ///
1948 /// By default, performs semantic analysis to finish the new statement.
1949 /// Subclasses may override this routine to provide different behavior.
1950 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1951 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1952 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001953
David Majnemerfad8f482013-10-15 09:33:02 +00001954 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001955 Stmt *TryBlock, Stmt *Handler) {
1956 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001957 }
1958
David Majnemerfad8f482013-10-15 09:33:02 +00001959 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001960 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001961 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001962 }
1963
David Majnemerfad8f482013-10-15 09:33:02 +00001964 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001965 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001966 }
1967
Alexey Bataevec474782014-10-09 08:45:04 +00001968 /// \brief Build a new predefined expression.
1969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
1972 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1973 PredefinedExpr::IdentType IT) {
1974 return getSema().BuildPredefinedExpr(Loc, IT);
1975 }
1976
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// \brief Build a new expression that references a declaration.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001981 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001982 LookupResult &R,
1983 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001984 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1985 }
1986
1987
1988 /// \brief Build a new expression that references a declaration.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001992 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001993 ValueDecl *VD,
1994 const DeclarationNameInfo &NameInfo,
1995 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001996 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001997 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001998
1999 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002000
2001 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 }
Mike Stump11289f42009-09-09 15:08:12 +00002003
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002005 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002008 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002010 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 }
2012
Douglas Gregorad8a3362009-09-04 17:36:40 +00002013 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002014 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002018 SourceLocation OperatorLoc,
2019 bool isArrow,
2020 CXXScopeSpec &SS,
2021 TypeSourceInfo *ScopeType,
2022 SourceLocation CCLoc,
2023 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002024 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002027 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002030 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002031 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002032 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002033 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 }
Mike Stump11289f42009-09-09 15:08:12 +00002035
Douglas Gregor882211c2010-04-28 22:16:22 +00002036 /// \brief Build a new builtin offsetof expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002040 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002041 TypeSourceInfo *Type,
2042 ArrayRef<Sema::OffsetOfComponent> Components,
2043 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002044 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002045 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002046 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002047
2048 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002049 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002050 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002053 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2054 SourceLocation OpLoc,
2055 UnaryExprOrTypeTrait ExprKind,
2056 SourceRange R) {
2057 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 }
2059
Peter Collingbournee190dee2011-03-11 19:24:49 +00002060 /// \brief Build a new sizeof, alignof or vec step expression with an
2061 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002062 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002065 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2066 UnaryExprOrTypeTrait ExprKind,
2067 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002068 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002069 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002072
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002073 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 }
Mike Stump11289f42009-09-09 15:08:12 +00002075
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002077 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002080 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002082 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002084 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002085 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 RBracketLoc);
2087 }
2088
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002089 /// \brief Build a new array section expression.
2090 ///
2091 /// By default, performs semantic analysis to build the new expression.
2092 /// Subclasses may override this routine to provide different behavior.
2093 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2094 Expr *LowerBound,
2095 SourceLocation ColonLoc, Expr *Length,
2096 SourceLocation RBracketLoc) {
2097 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2098 ColonLoc, Length, RBracketLoc);
2099 }
2100
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002102 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002105 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002107 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002108 Expr *ExecConfig = nullptr) {
2109 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002110 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 }
2112
2113 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002114 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 /// By default, performs semantic analysis to build the new expression.
2116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002117 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002118 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002119 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002120 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002121 const DeclarationNameInfo &MemberNameInfo,
2122 ValueDecl *Member,
2123 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002124 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002125 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002126 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2127 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002128 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002129 // We have a reference to an unnamed field. This is always the
2130 // base of an anonymous struct/union member access, i.e. the
2131 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002132 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002133 assert(Member->getType()->isRecordType() &&
2134 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002135
Richard Smithcab9a7d2011-10-26 19:06:56 +00002136 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002137 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002138 QualifierLoc.getNestedNameSpecifier(),
2139 FoundDecl, Member);
2140 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002141 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002142 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002143 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002144 MemberExpr *ME = new (getSema().Context)
2145 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2146 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002147 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002148 }
Mike Stump11289f42009-09-09 15:08:12 +00002149
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002150 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002151 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002152
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002153 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002154 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002155
John McCall16df1e52010-03-30 21:47:33 +00002156 // FIXME: this involves duplicating earlier analysis in a lot of
2157 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002158 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002159 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002160 R.resolveKind();
2161
John McCallb268a282010-08-23 23:25:46 +00002162 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002163 SS, TemplateKWLoc,
2164 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002165 R, ExplicitTemplateArgs,
2166 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 }
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002170 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002174 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002175 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002176 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
2178
2179 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002180 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002184 SourceLocation QuestionLoc,
2185 Expr *LHS,
2186 SourceLocation ColonLoc,
2187 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002188 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2189 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 }
2191
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002193 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 /// By default, performs semantic analysis to build the new expression.
2195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002197 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002199 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002200 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002201 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 }
Mike Stump11289f42009-09-09 15:08:12 +00002203
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002205 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002208 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002209 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002211 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002212 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002213 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 }
Mike Stump11289f42009-09-09 15:08:12 +00002215
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002217 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002220 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 SourceLocation OpLoc,
2222 SourceLocation AccessorLoc,
2223 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002224
John McCall10eae182009-11-30 22:42:35 +00002225 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002226 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002227 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002228 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002229 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002230 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002231 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002232 /* TemplateArgs */ nullptr,
2233 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 }
Mike Stump11289f42009-09-09 15:08:12 +00002235
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002237 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002241 MultiExprArg Inits,
2242 SourceLocation RBraceLoc,
2243 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002244 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002245 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002246 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002247 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002248
Douglas Gregord3d93062009-11-09 17:16:50 +00002249 // Patch in the result type we were given, which may have been computed
2250 // when the initial InitListExpr was built.
2251 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2252 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002253 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 }
Mike Stump11289f42009-09-09 15:08:12 +00002255
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002257 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002260 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 MultiExprArg ArrayExprs,
2262 SourceLocation EqualOrColonLoc,
2263 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002264 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002265 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002267 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002269 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002270
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002271 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 }
Mike Stump11289f42009-09-09 15:08:12 +00002273
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002275 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 /// By default, builds the implicit value initialization without performing
2277 /// any semantic analysis. Subclasses may override this routine to provide
2278 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002279 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002280 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 }
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002284 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002287 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002288 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002289 SourceLocation RParenLoc) {
2290 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002291 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002292 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 }
2294
2295 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002296 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002299 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002300 MultiExprArg SubExprs,
2301 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002302 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 }
Mike Stump11289f42009-09-09 15:08:12 +00002304
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002306 ///
2307 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 /// rather than attempting to map the label statement itself.
2309 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002310 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002311 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002312 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 }
Mike Stump11289f42009-09-09 15:08:12 +00002314
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002316 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// By default, performs semantic analysis to build the new expression.
2318 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002319 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002320 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002322 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 }
Mike Stump11289f42009-09-09 15:08:12 +00002324
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 /// \brief Build a new __builtin_choose_expr expression.
2326 ///
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002329 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002330 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 SourceLocation RParenLoc) {
2332 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002333 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 RParenLoc);
2335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Peter Collingbourne91147592011-04-15 00:35:48 +00002337 /// \brief Build a new generic selection expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
2341 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2342 SourceLocation DefaultLoc,
2343 SourceLocation RParenLoc,
2344 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002345 ArrayRef<TypeSourceInfo *> Types,
2346 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002347 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002348 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002349 }
2350
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 /// \brief Build a new overloaded operator call expression.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// The semantic analysis provides the behavior of template instantiation,
2355 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002356 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 /// argument-dependent lookup, etc. Subclasses may override this routine to
2358 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002359 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002361 Expr *Callee,
2362 Expr *First,
2363 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002364
2365 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 /// reinterpret_cast.
2367 ///
2368 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002369 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002371 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 Stmt::StmtClass Class,
2373 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002374 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 SourceLocation RAngleLoc,
2376 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002377 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 SourceLocation RParenLoc) {
2379 switch (Class) {
2380 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002381 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002382 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002383 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002384
2385 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002386 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002387 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002388 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002389
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002391 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002392 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002393 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002395
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002397 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002398 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002399 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002400
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002402 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
Mike Stump11289f42009-09-09 15:08:12 +00002405
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 /// \brief Build a new C++ static_cast expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002412 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002413 SourceLocation RAngleLoc,
2414 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002415 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002417 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002418 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002419 SourceRange(LAngleLoc, RAngleLoc),
2420 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 }
2422
2423 /// \brief Build a new C++ dynamic_cast expression.
2424 ///
2425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002427 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 SourceLocation RAngleLoc,
2431 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002432 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002435 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002436 SourceRange(LAngleLoc, RAngleLoc),
2437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 }
2439
2440 /// \brief Build a new C++ reinterpret_cast expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002444 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002445 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002446 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002447 SourceLocation RAngleLoc,
2448 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002449 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002450 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002452 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002453 SourceRange(LAngleLoc, RAngleLoc),
2454 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002455 }
2456
2457 /// \brief Build a new C++ const_cast expression.
2458 ///
2459 /// By default, performs semantic analysis to build the new expression.
2460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002461 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002462 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002463 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 SourceLocation RAngleLoc,
2465 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002466 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002469 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002470 SourceRange(LAngleLoc, RAngleLoc),
2471 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002472 }
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregora16548e2009-08-11 05:31:07 +00002474 /// \brief Build a new C++ functional-style cast expression.
2475 ///
2476 /// By default, performs semantic analysis to build the new expression.
2477 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002478 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2479 SourceLocation LParenLoc,
2480 Expr *Sub,
2481 SourceLocation RParenLoc) {
2482 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002483 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002484 RParenLoc);
2485 }
Mike Stump11289f42009-09-09 15:08:12 +00002486
Douglas Gregora16548e2009-08-11 05:31:07 +00002487 /// \brief Build a new C++ typeid(type) expression.
2488 ///
2489 /// By default, performs semantic analysis to build the new expression.
2490 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002491 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002492 SourceLocation TypeidLoc,
2493 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002495 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002496 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002497 }
Mike Stump11289f42009-09-09 15:08:12 +00002498
Francois Pichet9f4f2072010-09-08 12:20:18 +00002499
Douglas Gregora16548e2009-08-11 05:31:07 +00002500 /// \brief Build a new C++ typeid(expr) expression.
2501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002504 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002505 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002506 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002507 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002508 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002509 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002510 }
2511
Francois Pichet9f4f2072010-09-08 12:20:18 +00002512 /// \brief Build a new C++ __uuidof(type) expression.
2513 ///
2514 /// By default, performs semantic analysis to build the new expression.
2515 /// Subclasses may override this routine to provide different behavior.
2516 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2517 SourceLocation TypeidLoc,
2518 TypeSourceInfo *Operand,
2519 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002520 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002521 RParenLoc);
2522 }
2523
2524 /// \brief Build a new C++ __uuidof(expr) expression.
2525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
2528 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2529 SourceLocation TypeidLoc,
2530 Expr *Operand,
2531 SourceLocation RParenLoc) {
2532 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2533 RParenLoc);
2534 }
2535
Douglas Gregora16548e2009-08-11 05:31:07 +00002536 /// \brief Build a new C++ "this" expression.
2537 ///
2538 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002539 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002540 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002541 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002542 QualType ThisType,
2543 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002544 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002545 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 }
2547
2548 /// \brief Build a new C++ throw expression.
2549 ///
2550 /// By default, performs semantic analysis to build the new expression.
2551 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002552 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2553 bool IsThrownVariableInScope) {
2554 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002555 }
2556
2557 /// \brief Build a new C++ default-argument expression.
2558 ///
2559 /// By default, builds a new default-argument expression, which does not
2560 /// require any semantic analysis. Subclasses may override this routine to
2561 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002562 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002563 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002564 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002565 }
2566
Richard Smith852c9db2013-04-20 22:23:05 +00002567 /// \brief Build a new C++11 default-initialization expression.
2568 ///
2569 /// By default, builds a new default field initialization expression, which
2570 /// does not require any semantic analysis. Subclasses may override this
2571 /// routine to provide different behavior.
2572 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2573 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002574 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002575 }
2576
Douglas Gregora16548e2009-08-11 05:31:07 +00002577 /// \brief Build a new C++ zero-initialization expression.
2578 ///
2579 /// By default, performs semantic analysis to build the new expression.
2580 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002581 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2582 SourceLocation LParenLoc,
2583 SourceLocation RParenLoc) {
2584 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002585 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002586 }
Mike Stump11289f42009-09-09 15:08:12 +00002587
Douglas Gregora16548e2009-08-11 05:31:07 +00002588 /// \brief Build a new C++ "new" expression.
2589 ///
2590 /// By default, performs semantic analysis to build the new expression.
2591 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002592 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002593 bool UseGlobal,
2594 SourceLocation PlacementLParen,
2595 MultiExprArg PlacementArgs,
2596 SourceLocation PlacementRParen,
2597 SourceRange TypeIdParens,
2598 QualType AllocatedType,
2599 TypeSourceInfo *AllocatedTypeInfo,
2600 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002601 SourceRange DirectInitRange,
2602 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002603 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002604 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002605 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002606 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002607 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002608 AllocatedType,
2609 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002610 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002611 DirectInitRange,
2612 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002613 }
Mike Stump11289f42009-09-09 15:08:12 +00002614
Douglas Gregora16548e2009-08-11 05:31:07 +00002615 /// \brief Build a new C++ "delete" expression.
2616 ///
2617 /// By default, performs semantic analysis to build the new expression.
2618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002619 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002620 bool IsGlobalDelete,
2621 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002622 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002623 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002624 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002625 }
Mike Stump11289f42009-09-09 15:08:12 +00002626
Douglas Gregor29c42f22012-02-24 07:38:34 +00002627 /// \brief Build a new type trait expression.
2628 ///
2629 /// By default, performs semantic analysis to build the new expression.
2630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildTypeTrait(TypeTrait Trait,
2632 SourceLocation StartLoc,
2633 ArrayRef<TypeSourceInfo *> Args,
2634 SourceLocation RParenLoc) {
2635 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002637
John Wiegley6242b6a2011-04-28 00:16:57 +00002638 /// \brief Build a new array type trait expression.
2639 ///
2640 /// By default, performs semantic analysis to build the new expression.
2641 /// Subclasses may override this routine to provide different behavior.
2642 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2643 SourceLocation StartLoc,
2644 TypeSourceInfo *TSInfo,
2645 Expr *DimExpr,
2646 SourceLocation RParenLoc) {
2647 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2648 }
2649
John Wiegleyf9f65842011-04-25 06:54:41 +00002650 /// \brief Build a new expression trait expression.
2651 ///
2652 /// By default, performs semantic analysis to build the new expression.
2653 /// Subclasses may override this routine to provide different behavior.
2654 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2655 SourceLocation StartLoc,
2656 Expr *Queried,
2657 SourceLocation RParenLoc) {
2658 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2659 }
2660
Mike Stump11289f42009-09-09 15:08:12 +00002661 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 /// expression.
2663 ///
2664 /// By default, performs semantic analysis to build the new expression.
2665 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002666 ExprResult RebuildDependentScopeDeclRefExpr(
2667 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002668 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002669 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002670 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002671 bool IsAddressOfOperand,
2672 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002674 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002675
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002676 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002677 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2678 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002679
Reid Kleckner32506ed2014-06-12 23:03:48 +00002680 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002681 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002682 }
2683
2684 /// \brief Build a new template-id expression.
2685 ///
2686 /// By default, performs semantic analysis to build the new expression.
2687 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002688 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002689 SourceLocation TemplateKWLoc,
2690 LookupResult &R,
2691 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002692 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002693 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2694 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002695 }
2696
2697 /// \brief Build a new object-construction expression.
2698 ///
2699 /// By default, performs semantic analysis to build the new expression.
2700 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002701 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002702 SourceLocation Loc,
2703 CXXConstructorDecl *Constructor,
2704 bool IsElidable,
2705 MultiExprArg Args,
2706 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002707 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002708 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002709 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002710 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002711 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002712 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002713 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002714 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002715 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002716
Richard Smithc83bf822016-06-10 00:58:19 +00002717 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002718 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002719 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002720 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002721 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002722 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002723 RequiresZeroInit, ConstructKind,
2724 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002725 }
2726
Richard Smith5179eb72016-06-28 19:03:57 +00002727 /// \brief Build a new implicit construction via inherited constructor
2728 /// expression.
2729 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2730 CXXConstructorDecl *Constructor,
2731 bool ConstructsVBase,
2732 bool InheritedFromVBase) {
2733 return new (getSema().Context) CXXInheritedCtorInitExpr(
2734 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2735 }
2736
Douglas Gregora16548e2009-08-11 05:31:07 +00002737 /// \brief Build a new object-construction expression.
2738 ///
2739 /// By default, performs semantic analysis to build the new expression.
2740 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002741 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2742 SourceLocation LParenLoc,
2743 MultiExprArg Args,
2744 SourceLocation RParenLoc) {
2745 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002746 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002747 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002748 RParenLoc);
2749 }
2750
2751 /// \brief Build a new object-construction expression.
2752 ///
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002755 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2756 SourceLocation LParenLoc,
2757 MultiExprArg Args,
2758 SourceLocation RParenLoc) {
2759 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002760 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002761 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002762 RParenLoc);
2763 }
Mike Stump11289f42009-09-09 15:08:12 +00002764
Douglas Gregora16548e2009-08-11 05:31:07 +00002765 /// \brief Build a new member reference expression.
2766 ///
2767 /// By default, performs semantic analysis to build the new expression.
2768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002769 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002770 QualType BaseType,
2771 bool IsArrow,
2772 SourceLocation OperatorLoc,
2773 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002774 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002775 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002776 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002777 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002778 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002779 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002780
John McCallb268a282010-08-23 23:25:46 +00002781 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002782 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002783 SS, TemplateKWLoc,
2784 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002785 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002786 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002787 }
2788
John McCall10eae182009-11-30 22:42:35 +00002789 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002790 ///
2791 /// By default, performs semantic analysis to build the new expression.
2792 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002793 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2794 SourceLocation OperatorLoc,
2795 bool IsArrow,
2796 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002797 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002798 NamedDecl *FirstQualifierInScope,
2799 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002800 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002801 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002802 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002803
John McCallb268a282010-08-23 23:25:46 +00002804 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002805 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002806 SS, TemplateKWLoc,
2807 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002808 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002809 }
Mike Stump11289f42009-09-09 15:08:12 +00002810
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002811 /// \brief Build a new noexcept expression.
2812 ///
2813 /// By default, performs semantic analysis to build the new expression.
2814 /// Subclasses may override this routine to provide different behavior.
2815 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2816 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2817 }
2818
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002819 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002820 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2821 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002822 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002823 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002824 Optional<unsigned> Length,
2825 ArrayRef<TemplateArgument> PartialArgs) {
2826 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2827 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002828 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002829
Patrick Beard0caa3942012-04-19 00:25:12 +00002830 /// \brief Build a new Objective-C boxed expression.
2831 ///
2832 /// By default, performs semantic analysis to build the new expression.
2833 /// Subclasses may override this routine to provide different behavior.
2834 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2835 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002837
Ted Kremeneke65b0862012-03-06 20:05:56 +00002838 /// \brief Build a new Objective-C array literal.
2839 ///
2840 /// By default, performs semantic analysis to build the new expression.
2841 /// Subclasses may override this routine to provide different behavior.
2842 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2843 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002844 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002845 MultiExprArg(Elements, NumElements));
2846 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002847
2848 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002849 Expr *Base, Expr *Key,
2850 ObjCMethodDecl *getterMethod,
2851 ObjCMethodDecl *setterMethod) {
2852 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2853 getterMethod, setterMethod);
2854 }
2855
2856 /// \brief Build a new Objective-C dictionary literal.
2857 ///
2858 /// By default, performs semantic analysis to build the new expression.
2859 /// Subclasses may override this routine to provide different behavior.
2860 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002861 MutableArrayRef<ObjCDictionaryElement> Elements) {
2862 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002864
James Dennett2a4d13c2012-06-15 07:13:21 +00002865 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002866 ///
2867 /// By default, performs semantic analysis to build the new expression.
2868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002869 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002870 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002871 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002872 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002873 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002874
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002875 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002876 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002877 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002878 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002879 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002880 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002881 MultiExprArg Args,
2882 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002883 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2884 ReceiverTypeInfo->getType(),
2885 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002886 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002887 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002888 }
2889
2890 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002891 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002892 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002893 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002894 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002895 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002896 MultiExprArg Args,
2897 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002898 return SemaRef.BuildInstanceMessage(Receiver,
2899 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002900 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002901 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002902 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002903 }
2904
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002905 /// \brief Build a new Objective-C instance/class message to 'super'.
2906 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2907 Selector Sel,
2908 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002909 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002910 ObjCMethodDecl *Method,
2911 SourceLocation LBracLoc,
2912 MultiExprArg Args,
2913 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002914 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(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 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002920 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002921 SuperLoc,
2922 Sel, Method, LBracLoc, SelectorLocs,
2923 RBracLoc, Args);
2924
2925
2926 }
2927
Douglas Gregord51d90d2010-04-26 20:11:03 +00002928 /// \brief Build a new Objective-C ivar reference expression.
2929 ///
2930 /// By default, performs semantic analysis to build the new expression.
2931 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002932 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002933 SourceLocation IvarLoc,
2934 bool IsArrow, bool IsFreeIvar) {
2935 // FIXME: We lose track of the IsFreeIvar bit.
2936 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002937 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2938 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002939 /*FIXME:*/IvarLoc, IsArrow,
2940 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002941 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002942 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002943 /*TemplateArgs=*/nullptr,
2944 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002945 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002946
2947 /// \brief Build a new Objective-C property reference expression.
2948 ///
2949 /// By default, performs semantic analysis to build the new expression.
2950 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002951 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002952 ObjCPropertyDecl *Property,
2953 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002954 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002955 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2956 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2957 /*FIXME:*/PropertyLoc,
2958 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002959 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002960 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002961 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002962 /*TemplateArgs=*/nullptr,
2963 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002965
John McCallb7bd14f2010-12-02 01:19:52 +00002966 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002967 ///
2968 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002969 /// Subclasses may override this routine to provide different behavior.
2970 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2971 ObjCMethodDecl *Getter,
2972 ObjCMethodDecl *Setter,
2973 SourceLocation PropertyLoc) {
2974 // Since these expressions can only be value-dependent, we do not
2975 // need to perform semantic analysis again.
2976 return Owned(
2977 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2978 VK_LValue, OK_ObjCProperty,
2979 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002980 }
2981
Douglas Gregord51d90d2010-04-26 20:11:03 +00002982 /// \brief Build a new Objective-C "isa" expression.
2983 ///
2984 /// By default, performs semantic analysis to build the new expression.
2985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002986 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002987 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002988 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002989 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2990 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002991 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002992 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002993 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002994 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002995 /*TemplateArgs=*/nullptr,
2996 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002998
Douglas Gregora16548e2009-08-11 05:31:07 +00002999 /// \brief Build a new shuffle vector expression.
3000 ///
3001 /// By default, performs semantic analysis to build the new expression.
3002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003003 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003004 MultiExprArg SubExprs,
3005 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003006 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003007 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003008 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3009 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3010 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003011 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003012
Douglas Gregora16548e2009-08-11 05:31:07 +00003013 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003014 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003015 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3016 SemaRef.Context.BuiltinFnTy,
3017 VK_RValue, BuiltinLoc);
3018 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3019 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003020 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003021
3022 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003023 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003024 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003025 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003026
Douglas Gregora16548e2009-08-11 05:31:07 +00003027 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003028 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003029 }
John McCall31f82722010-11-12 08:19:04 +00003030
Hal Finkelc4d7c822013-09-18 03:29:45 +00003031 /// \brief Build a new convert vector expression.
3032 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3033 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3034 SourceLocation RParenLoc) {
3035 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3036 BuiltinLoc, RParenLoc);
3037 }
3038
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039 /// \brief Build a new template argument pack expansion.
3040 ///
3041 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003042 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003043 /// different behavior.
3044 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003045 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003046 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003047 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003048 case TemplateArgument::Expression: {
3049 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003050 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3051 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003052 if (Result.isInvalid())
3053 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003054
Douglas Gregor98318c22011-01-03 21:37:45 +00003055 return TemplateArgumentLoc(Result.get(), Result.get());
3056 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003057
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003058 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003059 return TemplateArgumentLoc(TemplateArgument(
3060 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003061 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003062 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003063 Pattern.getTemplateNameLoc(),
3064 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003066 case TemplateArgument::Null:
3067 case TemplateArgument::Integral:
3068 case TemplateArgument::Declaration:
3069 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003070 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003071 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003072 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003073
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003074 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003075 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003076 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003077 EllipsisLoc,
3078 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003079 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3080 Expansion);
3081 break;
3082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003083
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003084 return TemplateArgumentLoc();
3085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003086
Douglas Gregor968f23a2011-01-03 19:31:53 +00003087 /// \brief Build a new expression pack expansion.
3088 ///
3089 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003090 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003091 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003092 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003093 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003094 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003095 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003096
Richard Smith0f0af192014-11-08 05:07:16 +00003097 /// \brief Build a new C++1z fold-expression.
3098 ///
3099 /// By default, performs semantic analysis in order to build a new fold
3100 /// expression.
3101 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3102 BinaryOperatorKind Operator,
3103 SourceLocation EllipsisLoc, Expr *RHS,
3104 SourceLocation RParenLoc) {
3105 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3106 RHS, RParenLoc);
3107 }
3108
3109 /// \brief Build an empty C++1z fold-expression with the given operator.
3110 ///
3111 /// By default, produces the fallback value for the fold-expression, or
3112 /// produce an error if there is no fallback value.
3113 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3114 BinaryOperatorKind Operator) {
3115 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3116 }
3117
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003118 /// \brief Build a new atomic operation expression.
3119 ///
3120 /// By default, performs semantic analysis to build the new expression.
3121 /// Subclasses may override this routine to provide different behavior.
3122 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3123 MultiExprArg SubExprs,
3124 QualType RetTy,
3125 AtomicExpr::AtomicOp Op,
3126 SourceLocation RParenLoc) {
3127 // Just create the expression; there is not any interesting semantic
3128 // analysis here because we can't actually build an AtomicExpr until
3129 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003130 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003131 RParenLoc);
3132 }
3133
John McCall31f82722010-11-12 08:19:04 +00003134private:
Douglas Gregor14454802011-02-25 02:25:35 +00003135 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3136 QualType ObjectType,
3137 NamedDecl *FirstQualifierInScope,
3138 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003139
3140 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3141 QualType ObjectType,
3142 NamedDecl *FirstQualifierInScope,
3143 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003144
3145 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3146 NamedDecl *FirstQualifierInScope,
3147 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003148};
Douglas Gregora16548e2009-08-11 05:31:07 +00003149
Douglas Gregorebe10102009-08-20 07:17:43 +00003150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003151StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003152 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003153 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003154
Douglas Gregorebe10102009-08-20 07:17:43 +00003155 switch (S->getStmtClass()) {
3156 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003157
Douglas Gregorebe10102009-08-20 07:17:43 +00003158 // Transform individual statement nodes
3159#define STMT(Node, Parent) \
3160 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003161#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003162#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003163#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003164
Douglas Gregorebe10102009-08-20 07:17:43 +00003165 // Transform expressions by calling TransformExpr.
3166#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003167#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003168#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003169#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003170 {
John McCalldadc5752010-08-24 06:29:42 +00003171 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003172 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003173 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003174
Richard Smith945f8d32013-01-14 22:39:08 +00003175 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003176 }
Mike Stump11289f42009-09-09 15:08:12 +00003177 }
3178
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003179 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003180}
Mike Stump11289f42009-09-09 15:08:12 +00003181
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003182template<typename Derived>
3183OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3184 if (!S)
3185 return S;
3186
3187 switch (S->getClauseKind()) {
3188 default: break;
3189 // Transform individual clause nodes
3190#define OPENMP_CLAUSE(Name, Class) \
3191 case OMPC_ ## Name : \
3192 return getDerived().Transform ## Class(cast<Class>(S));
3193#include "clang/Basic/OpenMPKinds.def"
3194 }
3195
3196 return S;
3197}
3198
Mike Stump11289f42009-09-09 15:08:12 +00003199
Douglas Gregore922c772009-08-04 22:27:00 +00003200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003201ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003202 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003203 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003204
3205 switch (E->getStmtClass()) {
3206 case Stmt::NoStmtClass: break;
3207#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003208#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003209#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003210 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003211#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003212 }
3213
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003214 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003215}
3216
3217template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003218ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003219 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003220 // Initializers are instantiated like expressions, except that various outer
3221 // layers are stripped.
3222 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003223 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003224
3225 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3226 Init = ExprTemp->getSubExpr();
3227
Richard Smith410306b2016-12-12 02:53:20 +00003228 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3229 Init = AIL->getCommonExpr();
3230
Richard Smithe6ca4752013-05-30 22:40:16 +00003231 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3232 Init = MTE->GetTemporaryExpr();
3233
Richard Smithd59b8322012-12-19 01:39:02 +00003234 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3235 Init = Binder->getSubExpr();
3236
3237 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3238 Init = ICE->getSubExprAsWritten();
3239
Richard Smithcc1b96d2013-06-12 22:31:48 +00003240 if (CXXStdInitializerListExpr *ILE =
3241 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003242 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003243
Richard Smithc6abd962014-07-25 01:12:44 +00003244 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003245 // InitListExprs. Other forms of copy-initialization will be a no-op if
3246 // the initializer is already the right type.
3247 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003248 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003249 return getDerived().TransformExpr(Init);
3250
3251 // Revert value-initialization back to empty parens.
3252 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3253 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003254 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003255 Parens.getEnd());
3256 }
3257
3258 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3259 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003260 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003261 SourceLocation());
3262
3263 // Revert initialization by constructor back to a parenthesized or braced list
3264 // of expressions. Any other form of initializer can just be reused directly.
3265 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003266 return getDerived().TransformExpr(Init);
3267
Richard Smithf8adcdc2014-07-17 05:12:35 +00003268 // If the initialization implicitly converted an initializer list to a
3269 // std::initializer_list object, unwrap the std::initializer_list too.
3270 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003271 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003272
Richard Smithd59b8322012-12-19 01:39:02 +00003273 SmallVector<Expr*, 8> NewArgs;
3274 bool ArgChanged = false;
3275 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003276 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003277 return ExprError();
3278
3279 // If this was list initialization, revert to list form.
3280 if (Construct->isListInitialization())
3281 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3282 Construct->getLocEnd(),
3283 Construct->getType());
3284
Richard Smithd59b8322012-12-19 01:39:02 +00003285 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003286 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003287 if (Parens.isInvalid()) {
3288 // This was a variable declaration's initialization for which no initializer
3289 // was specified.
3290 assert(NewArgs.empty() &&
3291 "no parens or braces but have direct init with arguments?");
3292 return ExprEmpty();
3293 }
Richard Smithd59b8322012-12-19 01:39:02 +00003294 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3295 Parens.getEnd());
3296}
3297
3298template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003299bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003300 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003301 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003302 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003303 bool *ArgChanged) {
3304 for (unsigned I = 0; I != NumInputs; ++I) {
3305 // If requested, drop call arguments that need to be dropped.
3306 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3307 if (ArgChanged)
3308 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003309
Douglas Gregora3efea12011-01-03 19:04:46 +00003310 break;
3311 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003312
Douglas Gregor968f23a2011-01-03 19:31:53 +00003313 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3314 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003315
Chris Lattner01cf8db2011-07-20 06:58:45 +00003316 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003317 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3318 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003319
Douglas Gregor968f23a2011-01-03 19:31:53 +00003320 // Determine whether the set of unexpanded parameter packs can and should
3321 // be expanded.
3322 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003323 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003324 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3325 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003326 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3327 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003328 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003329 Expand, RetainExpansion,
3330 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003331 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003332
Douglas Gregor968f23a2011-01-03 19:31:53 +00003333 if (!Expand) {
3334 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003335 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003336 // expansion.
3337 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3338 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3339 if (OutPattern.isInvalid())
3340 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003341
3342 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003343 Expansion->getEllipsisLoc(),
3344 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003345 if (Out.isInvalid())
3346 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003347
Douglas Gregor968f23a2011-01-03 19:31:53 +00003348 if (ArgChanged)
3349 *ArgChanged = true;
3350 Outputs.push_back(Out.get());
3351 continue;
3352 }
John McCall542e7c62011-07-06 07:30:07 +00003353
3354 // Record right away that the argument was changed. This needs
3355 // to happen even if the array expands to nothing.
3356 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor968f23a2011-01-03 19:31:53 +00003358 // The transform has determined that we should perform an elementwise
3359 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003360 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003361 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3362 ExprResult Out = getDerived().TransformExpr(Pattern);
3363 if (Out.isInvalid())
3364 return true;
3365
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003366 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003367 Out = getDerived().RebuildPackExpansion(
3368 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003369 if (Out.isInvalid())
3370 return true;
3371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003372
Douglas Gregor968f23a2011-01-03 19:31:53 +00003373 Outputs.push_back(Out.get());
3374 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003375
Richard Smith9467be42014-06-06 17:33:35 +00003376 // If we're supposed to retain a pack expansion, do so by temporarily
3377 // forgetting the partially-substituted parameter pack.
3378 if (RetainExpansion) {
3379 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3380
3381 ExprResult Out = getDerived().TransformExpr(Pattern);
3382 if (Out.isInvalid())
3383 return true;
3384
3385 Out = getDerived().RebuildPackExpansion(
3386 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3387 if (Out.isInvalid())
3388 return true;
3389
3390 Outputs.push_back(Out.get());
3391 }
3392
Douglas Gregor968f23a2011-01-03 19:31:53 +00003393 continue;
3394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003395
Richard Smithd59b8322012-12-19 01:39:02 +00003396 ExprResult Result =
3397 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3398 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003399 if (Result.isInvalid())
3400 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003401
Douglas Gregora3efea12011-01-03 19:04:46 +00003402 if (Result.get() != Inputs[I] && ArgChanged)
3403 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003404
3405 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003407
Douglas Gregora3efea12011-01-03 19:04:46 +00003408 return false;
3409}
3410
Richard Smith03a4aa32016-06-23 19:02:52 +00003411template <typename Derived>
3412Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3413 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3414 if (Var) {
3415 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3416 getDerived().TransformDefinition(Var->getLocation(), Var));
3417
3418 if (!ConditionVar)
3419 return Sema::ConditionError();
3420
3421 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3422 }
3423
3424 if (Expr) {
3425 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3426
3427 if (CondExpr.isInvalid())
3428 return Sema::ConditionError();
3429
3430 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3431 }
3432
3433 return Sema::ConditionResult();
3434}
3435
Douglas Gregora3efea12011-01-03 19:04:46 +00003436template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003437NestedNameSpecifierLoc
3438TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3439 NestedNameSpecifierLoc NNS,
3440 QualType ObjectType,
3441 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003442 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003443 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003444 Qualifier = Qualifier.getPrefix())
3445 Qualifiers.push_back(Qualifier);
3446
3447 CXXScopeSpec SS;
3448 while (!Qualifiers.empty()) {
3449 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3450 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
Douglas Gregor14454802011-02-25 02:25:35 +00003452 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003453 case NestedNameSpecifier::Identifier: {
3454 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3455 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3456 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3457 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003458 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003459 }
Douglas Gregor14454802011-02-25 02:25:35 +00003460 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003461
Douglas Gregor14454802011-02-25 02:25:35 +00003462 case NestedNameSpecifier::Namespace: {
3463 NamespaceDecl *NS
3464 = cast_or_null<NamespaceDecl>(
3465 getDerived().TransformDecl(
3466 Q.getLocalBeginLoc(),
3467 QNNS->getAsNamespace()));
3468 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3469 break;
3470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003471
Douglas Gregor14454802011-02-25 02:25:35 +00003472 case NestedNameSpecifier::NamespaceAlias: {
3473 NamespaceAliasDecl *Alias
3474 = cast_or_null<NamespaceAliasDecl>(
3475 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3476 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003477 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003478 Q.getLocalEndLoc());
3479 break;
3480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003481
Douglas Gregor14454802011-02-25 02:25:35 +00003482 case NestedNameSpecifier::Global:
3483 // There is no meaningful transformation that one could perform on the
3484 // global scope.
3485 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3486 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003487
Nikola Smiljanic67860242014-09-26 00:28:20 +00003488 case NestedNameSpecifier::Super: {
3489 CXXRecordDecl *RD =
3490 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3491 SourceLocation(), QNNS->getAsRecordDecl()));
3492 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3493 break;
3494 }
3495
Douglas Gregor14454802011-02-25 02:25:35 +00003496 case NestedNameSpecifier::TypeSpecWithTemplate:
3497 case NestedNameSpecifier::TypeSpec: {
3498 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3499 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003500
Douglas Gregor14454802011-02-25 02:25:35 +00003501 if (!TL)
3502 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003503
Douglas Gregor14454802011-02-25 02:25:35 +00003504 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003505 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003506 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003507 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003508 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003509 if (TL.getType()->isEnumeralType())
3510 SemaRef.Diag(TL.getBeginLoc(),
3511 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003512 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3513 Q.getLocalEndLoc());
3514 break;
3515 }
Richard Trieude756fb2011-05-07 01:36:37 +00003516 // If the nested-name-specifier is an invalid type def, don't emit an
3517 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003518 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3519 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003520 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003521 << TL.getType() << SS.getRange();
3522 }
Douglas Gregor14454802011-02-25 02:25:35 +00003523 return NestedNameSpecifierLoc();
3524 }
Douglas Gregore16af532011-02-28 18:50:33 +00003525 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003526
Douglas Gregore16af532011-02-28 18:50:33 +00003527 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003528 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003529 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003530 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003531
Douglas Gregor14454802011-02-25 02:25:35 +00003532 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003533 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003534 !getDerived().AlwaysRebuild())
3535 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003536
3537 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003538 // nested-name-specifier, do so.
3539 if (SS.location_size() == NNS.getDataLength() &&
3540 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3541 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3542
3543 // Allocate new nested-name-specifier location information.
3544 return SS.getWithLocInContext(SemaRef.Context);
3545}
3546
3547template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003548DeclarationNameInfo
3549TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003550::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003551 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003552 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003553 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003554
3555 switch (Name.getNameKind()) {
3556 case DeclarationName::Identifier:
3557 case DeclarationName::ObjCZeroArgSelector:
3558 case DeclarationName::ObjCOneArgSelector:
3559 case DeclarationName::ObjCMultiArgSelector:
3560 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003561 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003562 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003563 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003564
Douglas Gregorf816bd72009-09-03 22:13:48 +00003565 case DeclarationName::CXXConstructorName:
3566 case DeclarationName::CXXDestructorName:
3567 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003568 TypeSourceInfo *NewTInfo;
3569 CanQualType NewCanTy;
3570 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003571 NewTInfo = getDerived().TransformType(OldTInfo);
3572 if (!NewTInfo)
3573 return DeclarationNameInfo();
3574 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003575 }
3576 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003577 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003578 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003579 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003580 if (NewT.isNull())
3581 return DeclarationNameInfo();
3582 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3583 }
Mike Stump11289f42009-09-09 15:08:12 +00003584
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003585 DeclarationName NewName
3586 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3587 NewCanTy);
3588 DeclarationNameInfo NewNameInfo(NameInfo);
3589 NewNameInfo.setName(NewName);
3590 NewNameInfo.setNamedTypeInfo(NewTInfo);
3591 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003592 }
Mike Stump11289f42009-09-09 15:08:12 +00003593 }
3594
David Blaikie83d382b2011-09-23 05:06:16 +00003595 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003596}
3597
3598template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003599TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003600TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3601 TemplateName Name,
3602 SourceLocation NameLoc,
3603 QualType ObjectType,
3604 NamedDecl *FirstQualifierInScope) {
3605 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3606 TemplateDecl *Template = QTN->getTemplateDecl();
3607 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
Douglas Gregor9db53502011-03-02 18:07:45 +00003609 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003610 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003611 Template));
3612 if (!TransTemplate)
3613 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003614
Douglas Gregor9db53502011-03-02 18:07:45 +00003615 if (!getDerived().AlwaysRebuild() &&
3616 SS.getScopeRep() == QTN->getQualifier() &&
3617 TransTemplate == Template)
3618 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
Douglas Gregor9db53502011-03-02 18:07:45 +00003620 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3621 TransTemplate);
3622 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003623
Douglas Gregor9db53502011-03-02 18:07:45 +00003624 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3625 if (SS.getScopeRep()) {
3626 // These apply to the scope specifier, not the template.
3627 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003628 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003629 }
3630
Douglas Gregor9db53502011-03-02 18:07:45 +00003631 if (!getDerived().AlwaysRebuild() &&
3632 SS.getScopeRep() == DTN->getQualifier() &&
3633 ObjectType.isNull())
3634 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor9db53502011-03-02 18:07:45 +00003636 if (DTN->isIdentifier()) {
3637 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003638 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003639 NameLoc,
3640 ObjectType,
3641 FirstQualifierInScope);
3642 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
Douglas Gregor9db53502011-03-02 18:07:45 +00003644 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3645 ObjectType);
3646 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003647
Douglas Gregor9db53502011-03-02 18:07:45 +00003648 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3649 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003650 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003651 Template));
3652 if (!TransTemplate)
3653 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
Douglas Gregor9db53502011-03-02 18:07:45 +00003655 if (!getDerived().AlwaysRebuild() &&
3656 TransTemplate == Template)
3657 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor9db53502011-03-02 18:07:45 +00003659 return TemplateName(TransTemplate);
3660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003661
Douglas Gregor9db53502011-03-02 18:07:45 +00003662 if (SubstTemplateTemplateParmPackStorage *SubstPack
3663 = Name.getAsSubstTemplateTemplateParmPack()) {
3664 TemplateTemplateParmDecl *TransParam
3665 = cast_or_null<TemplateTemplateParmDecl>(
3666 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3667 if (!TransParam)
3668 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregor9db53502011-03-02 18:07:45 +00003670 if (!getDerived().AlwaysRebuild() &&
3671 TransParam == SubstPack->getParameterPack())
3672 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003673
3674 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003675 SubstPack->getArgumentPack());
3676 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
Douglas Gregor9db53502011-03-02 18:07:45 +00003678 // These should be getting filtered out before they reach the AST.
3679 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003680}
3681
3682template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003683void TreeTransform<Derived>::InventTemplateArgumentLoc(
3684 const TemplateArgument &Arg,
3685 TemplateArgumentLoc &Output) {
3686 SourceLocation Loc = getDerived().getBaseLocation();
3687 switch (Arg.getKind()) {
3688 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003689 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003690 break;
3691
3692 case TemplateArgument::Type:
3693 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003694 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003695
John McCall0ad16662009-10-29 08:12:44 +00003696 break;
3697
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003698 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003699 case TemplateArgument::TemplateExpansion: {
3700 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003701 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003702 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3703 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3704 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3705 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003706
Douglas Gregor9d802122011-03-02 17:09:35 +00003707 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003708 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003709 Builder.getWithLocInContext(SemaRef.Context),
3710 Loc);
3711 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003712 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003713 Builder.getWithLocInContext(SemaRef.Context),
3714 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003715
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003716 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003717 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003718
John McCall0ad16662009-10-29 08:12:44 +00003719 case TemplateArgument::Expression:
3720 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3721 break;
3722
3723 case TemplateArgument::Declaration:
3724 case TemplateArgument::Integral:
3725 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003726 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003727 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003728 break;
3729 }
3730}
3731
3732template<typename Derived>
3733bool TreeTransform<Derived>::TransformTemplateArgument(
3734 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003735 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003736 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003737 switch (Arg.getKind()) {
3738 case TemplateArgument::Null:
3739 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003740 case TemplateArgument::Pack:
3741 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003742 case TemplateArgument::NullPtr:
3743 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003744
Douglas Gregore922c772009-08-04 22:27:00 +00003745 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003746 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003747 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003748 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003749
3750 DI = getDerived().TransformType(DI);
3751 if (!DI) return true;
3752
3753 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3754 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003755 }
Mike Stump11289f42009-09-09 15:08:12 +00003756
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003757 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003758 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3759 if (QualifierLoc) {
3760 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3761 if (!QualifierLoc)
3762 return true;
3763 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregordf846d12011-03-02 18:46:51 +00003765 CXXScopeSpec SS;
3766 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003767 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003768 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3769 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003770 if (Template.isNull())
3771 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003772
Douglas Gregor9d802122011-03-02 17:09:35 +00003773 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003774 Input.getTemplateNameLoc());
3775 return false;
3776 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003777
3778 case TemplateArgument::TemplateExpansion:
3779 llvm_unreachable("Caller should expand pack expansions");
3780
Douglas Gregore922c772009-08-04 22:27:00 +00003781 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003782 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003783 EnterExpressionEvaluationContext Unevaluated(
3784 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003785
John McCall0ad16662009-10-29 08:12:44 +00003786 Expr *InputExpr = Input.getSourceExpression();
3787 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3788
Chris Lattnercdb591a2011-04-25 20:37:58 +00003789 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003790 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003791 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003792 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003793 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003794 }
Douglas Gregore922c772009-08-04 22:27:00 +00003795 }
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregore922c772009-08-04 22:27:00 +00003797 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003798 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003799}
3800
Douglas Gregorfe921a72010-12-20 23:36:19 +00003801/// \brief Iterator adaptor that invents template argument location information
3802/// for each of the template arguments in its underlying iterator.
3803template<typename Derived, typename InputIterator>
3804class TemplateArgumentLocInventIterator {
3805 TreeTransform<Derived> &Self;
3806 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003807
Douglas Gregorfe921a72010-12-20 23:36:19 +00003808public:
3809 typedef TemplateArgumentLoc value_type;
3810 typedef TemplateArgumentLoc reference;
3811 typedef typename std::iterator_traits<InputIterator>::difference_type
3812 difference_type;
3813 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003814
Douglas Gregorfe921a72010-12-20 23:36:19 +00003815 class pointer {
3816 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003817
Douglas Gregorfe921a72010-12-20 23:36:19 +00003818 public:
3819 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
Douglas Gregorfe921a72010-12-20 23:36:19 +00003821 const TemplateArgumentLoc *operator->() const { return &Arg; }
3822 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003823
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003824 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregorfe921a72010-12-20 23:36:19 +00003826 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3827 InputIterator Iter)
3828 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003829
Douglas Gregorfe921a72010-12-20 23:36:19 +00003830 TemplateArgumentLocInventIterator &operator++() {
3831 ++Iter;
3832 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003833 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003834
Douglas Gregorfe921a72010-12-20 23:36:19 +00003835 TemplateArgumentLocInventIterator operator++(int) {
3836 TemplateArgumentLocInventIterator Old(*this);
3837 ++(*this);
3838 return Old;
3839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003840
Douglas Gregorfe921a72010-12-20 23:36:19 +00003841 reference operator*() const {
3842 TemplateArgumentLoc Result;
3843 Self.InventTemplateArgumentLoc(*Iter, Result);
3844 return Result;
3845 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003846
Douglas Gregorfe921a72010-12-20 23:36:19 +00003847 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003848
Douglas Gregorfe921a72010-12-20 23:36:19 +00003849 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3850 const TemplateArgumentLocInventIterator &Y) {
3851 return X.Iter == Y.Iter;
3852 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003853
Douglas Gregorfe921a72010-12-20 23:36:19 +00003854 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3855 const TemplateArgumentLocInventIterator &Y) {
3856 return X.Iter != Y.Iter;
3857 }
3858};
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor42cafa82010-12-20 17:42:22 +00003860template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003861template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003862bool TreeTransform<Derived>::TransformTemplateArguments(
3863 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3864 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003865 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003866 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003867 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003868
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003869 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3870 // Unpack argument packs, which we translate them into separate
3871 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003872 // FIXME: We could do much better if we could guarantee that the
3873 // TemplateArgumentLocInfo for the pack expansion would be usable for
3874 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003875 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003876 TemplateArgument::pack_iterator>
3877 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003878 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003879 In.getArgument().pack_begin()),
3880 PackLocIterator(*this,
3881 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003882 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003883 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003884
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003885 continue;
3886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003887
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003888 if (In.getArgument().isPackExpansion()) {
3889 // We have a pack expansion, for which we will be substituting into
3890 // the pattern.
3891 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003892 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003893 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003894 = getSema().getTemplateArgumentPackExpansionPattern(
3895 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003896
Chris Lattner01cf8db2011-07-20 06:58:45 +00003897 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003898 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3899 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003900
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003901 // Determine whether the set of unexpanded parameter packs can and should
3902 // be expanded.
3903 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003904 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003905 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003906 if (getDerived().TryExpandParameterPacks(Ellipsis,
3907 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003908 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003909 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003910 RetainExpansion,
3911 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003912 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003913
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003914 if (!Expand) {
3915 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003916 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003917 // expansion.
3918 TemplateArgumentLoc OutPattern;
3919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003920 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003921 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003922
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003923 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3924 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003925 if (Out.getArgument().isNull())
3926 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003927
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003928 Outputs.addArgument(Out);
3929 continue;
3930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003931
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003932 // The transform has determined that we should perform an elementwise
3933 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003934 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003935 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3936
Richard Smithd784e682015-09-23 21:41:42 +00003937 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003938 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003939
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003940 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003941 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3942 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003943 if (Out.getArgument().isNull())
3944 return true;
3945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003946
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003947 Outputs.addArgument(Out);
3948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003949
Douglas Gregor48d24112011-01-10 20:53:55 +00003950 // If we're supposed to retain a pack expansion, do so by temporarily
3951 // forgetting the partially-substituted parameter pack.
3952 if (RetainExpansion) {
3953 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003954
Richard Smithd784e682015-09-23 21:41:42 +00003955 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003956 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003958 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3959 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003960 if (Out.getArgument().isNull())
3961 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003962
Douglas Gregor48d24112011-01-10 20:53:55 +00003963 Outputs.addArgument(Out);
3964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003965
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003966 continue;
3967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003968
3969 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003970 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003971 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003972
Douglas Gregor42cafa82010-12-20 17:42:22 +00003973 Outputs.addArgument(Out);
3974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003975
Douglas Gregor42cafa82010-12-20 17:42:22 +00003976 return false;
3977
3978}
3979
Douglas Gregord6ff3322009-08-04 16:50:30 +00003980//===----------------------------------------------------------------------===//
3981// Type transformation
3982//===----------------------------------------------------------------------===//
3983
3984template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003985QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003986 if (getDerived().AlreadyTransformed(T))
3987 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003988
John McCall550e0c22009-10-21 00:40:46 +00003989 // Temporary workaround. All of these transformations should
3990 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003991 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3992 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003993
John McCall31f82722010-11-12 08:19:04 +00003994 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003995
John McCall550e0c22009-10-21 00:40:46 +00003996 if (!NewDI)
3997 return QualType();
3998
3999 return NewDI->getType();
4000}
4001
4002template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004003TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004004 // Refine the base location to the type's location.
4005 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4006 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004007 if (getDerived().AlreadyTransformed(DI->getType()))
4008 return DI;
4009
4010 TypeLocBuilder TLB;
4011
4012 TypeLoc TL = DI->getTypeLoc();
4013 TLB.reserve(TL.getFullDataSize());
4014
John McCall31f82722010-11-12 08:19:04 +00004015 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004016 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004017 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004018
John McCallbcd03502009-12-07 02:54:59 +00004019 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004020}
4021
4022template<typename Derived>
4023QualType
John McCall31f82722010-11-12 08:19:04 +00004024TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004025 switch (T.getTypeLocClass()) {
4026#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004027#define TYPELOC(CLASS, PARENT) \
4028 case TypeLoc::CLASS: \
4029 return getDerived().Transform##CLASS##Type(TLB, \
4030 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004031#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004032 }
Mike Stump11289f42009-09-09 15:08:12 +00004033
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004034 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004035}
4036
4037/// FIXME: By default, this routine adds type qualifiers only to types
4038/// that can have qualifiers, and silently suppresses those qualifiers
4039/// that are not permitted (e.g., qualifiers on reference or function
4040/// types). This is the right thing for template instantiation, but
4041/// probably not for other clients.
4042template<typename Derived>
4043QualType
4044TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004045 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004046 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004047
John McCall31f82722010-11-12 08:19:04 +00004048 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004049 if (Result.isNull())
4050 return QualType();
4051
4052 // Silently suppress qualifiers if the result type can't be qualified.
4053 // FIXME: this is the right thing for template instantiation, but
4054 // probably not for other clients.
4055 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004057
John McCall31168b02011-06-15 23:02:42 +00004058 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004059 // resulting type.
4060 if (Quals.hasObjCLifetime()) {
4061 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4062 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004063 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004064 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004065 // A lifetime qualifier applied to a substituted template parameter
4066 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004067 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004068 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004069 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4070 QualType Replacement = SubstTypeParam->getReplacementType();
4071 Qualifiers Qs = Replacement.getQualifiers();
4072 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004073 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004074 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4075 Qs);
4076 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004077 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004078 Replacement);
4079 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004080 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4081 // 'auto' types behave the same way as template parameters.
4082 QualType Deduced = AutoTy->getDeducedType();
4083 Qualifiers Qs = Deduced.getQualifiers();
4084 Qs.removeObjCLifetime();
4085 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4086 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004087 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004088 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004089 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004090 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004091 // Otherwise, complain about the addition of a qualifier to an
4092 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004093 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004094 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004095 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004096
Douglas Gregore46db902011-06-17 22:11:49 +00004097 Quals.removeObjCLifetime();
4098 }
4099 }
4100 }
John McCallcb0f89a2010-06-05 06:41:15 +00004101 if (!Quals.empty()) {
4102 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004103 // BuildQualifiedType might not add qualifiers if they are invalid.
4104 if (Result.hasLocalQualifiers())
4105 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004106 // No location information to preserve.
4107 }
John McCall550e0c22009-10-21 00:40:46 +00004108
4109 return Result;
4110}
4111
Douglas Gregor14454802011-02-25 02:25:35 +00004112template<typename Derived>
4113TypeLoc
4114TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4115 QualType ObjectType,
4116 NamedDecl *UnqualLookup,
4117 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004118 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004119 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004120
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004121 TypeSourceInfo *TSI =
4122 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4123 if (TSI)
4124 return TSI->getTypeLoc();
4125 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004126}
4127
Douglas Gregor579c15f2011-03-02 18:32:08 +00004128template<typename Derived>
4129TypeSourceInfo *
4130TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4131 QualType ObjectType,
4132 NamedDecl *UnqualLookup,
4133 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004134 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004135 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004136
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004137 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4138 UnqualLookup, SS);
4139}
4140
4141template <typename Derived>
4142TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4143 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4144 CXXScopeSpec &SS) {
4145 QualType T = TL.getType();
4146 assert(!getDerived().AlreadyTransformed(T));
4147
Douglas Gregor579c15f2011-03-02 18:32:08 +00004148 TypeLocBuilder TLB;
4149 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004150
Douglas Gregor579c15f2011-03-02 18:32:08 +00004151 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004152 TemplateSpecializationTypeLoc SpecTL =
4153 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004154
Douglas Gregor579c15f2011-03-02 18:32:08 +00004155 TemplateName Template
4156 = getDerived().TransformTemplateName(SS,
4157 SpecTL.getTypePtr()->getTemplateName(),
4158 SpecTL.getTemplateNameLoc(),
4159 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004160 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004161 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004162
4163 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004164 Template);
4165 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004166 DependentTemplateSpecializationTypeLoc SpecTL =
4167 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004168
Douglas Gregor579c15f2011-03-02 18:32:08 +00004169 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004170 = getDerived().RebuildTemplateName(SS,
4171 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004172 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004173 ObjectType, UnqualLookup);
4174 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004175 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004176
4177 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004178 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004179 Template,
4180 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004181 } else {
4182 // Nothing special needs to be done for these.
4183 Result = getDerived().TransformType(TLB, TL);
4184 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004185
4186 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004187 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004188
Douglas Gregor579c15f2011-03-02 18:32:08 +00004189 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4190}
4191
John McCall550e0c22009-10-21 00:40:46 +00004192template <class TyLoc> static inline
4193QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4194 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4195 NewT.setNameLoc(T.getNameLoc());
4196 return T.getType();
4197}
4198
John McCall550e0c22009-10-21 00:40:46 +00004199template<typename Derived>
4200QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004201 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004202 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4203 NewT.setBuiltinLoc(T.getBuiltinLoc());
4204 if (T.needsExtraLocalData())
4205 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4206 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004207}
Mike Stump11289f42009-09-09 15:08:12 +00004208
Douglas Gregord6ff3322009-08-04 16:50:30 +00004209template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004210QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004211 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004212 // FIXME: recurse?
4213 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004214}
Mike Stump11289f42009-09-09 15:08:12 +00004215
Reid Kleckner0503a872013-12-05 01:23:43 +00004216template <typename Derived>
4217QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4218 AdjustedTypeLoc TL) {
4219 // Adjustments applied during transformation are handled elsewhere.
4220 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4221}
4222
Douglas Gregord6ff3322009-08-04 16:50:30 +00004223template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004224QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4225 DecayedTypeLoc TL) {
4226 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4227 if (OriginalType.isNull())
4228 return QualType();
4229
4230 QualType Result = TL.getType();
4231 if (getDerived().AlwaysRebuild() ||
4232 OriginalType != TL.getOriginalLoc().getType())
4233 Result = SemaRef.Context.getDecayedType(OriginalType);
4234 TLB.push<DecayedTypeLoc>(Result);
4235 // Nothing to set for DecayedTypeLoc.
4236 return Result;
4237}
4238
4239template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004240QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004241 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004242 QualType PointeeType
4243 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004244 if (PointeeType.isNull())
4245 return QualType();
4246
4247 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004248 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004249 // A dependent pointer type 'T *' has is being transformed such
4250 // that an Objective-C class type is being replaced for 'T'. The
4251 // resulting pointer type is an ObjCObjectPointerType, not a
4252 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004253 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004254
John McCall8b07ec22010-05-15 11:32:37 +00004255 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4256 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004257 return Result;
4258 }
John McCall31f82722010-11-12 08:19:04 +00004259
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004260 if (getDerived().AlwaysRebuild() ||
4261 PointeeType != TL.getPointeeLoc().getType()) {
4262 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4263 if (Result.isNull())
4264 return QualType();
4265 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004266
John McCall31168b02011-06-15 23:02:42 +00004267 // Objective-C ARC can add lifetime qualifiers to the type that we're
4268 // pointing to.
4269 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004270
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004271 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4272 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004273 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004274}
Mike Stump11289f42009-09-09 15:08:12 +00004275
4276template<typename Derived>
4277QualType
John McCall550e0c22009-10-21 00:40:46 +00004278TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004279 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004280 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004281 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4282 if (PointeeType.isNull())
4283 return QualType();
4284
4285 QualType Result = TL.getType();
4286 if (getDerived().AlwaysRebuild() ||
4287 PointeeType != TL.getPointeeLoc().getType()) {
4288 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004289 TL.getSigilLoc());
4290 if (Result.isNull())
4291 return QualType();
4292 }
4293
Douglas Gregor049211a2010-04-22 16:50:51 +00004294 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004295 NewT.setSigilLoc(TL.getSigilLoc());
4296 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004297}
4298
John McCall70dd5f62009-10-30 00:06:24 +00004299/// Transforms a reference type. Note that somewhat paradoxically we
4300/// don't care whether the type itself is an l-value type or an r-value
4301/// type; we only care if the type was *written* as an l-value type
4302/// or an r-value type.
4303template<typename Derived>
4304QualType
4305TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004306 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004307 const ReferenceType *T = TL.getTypePtr();
4308
4309 // Note that this works with the pointee-as-written.
4310 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4311 if (PointeeType.isNull())
4312 return QualType();
4313
4314 QualType Result = TL.getType();
4315 if (getDerived().AlwaysRebuild() ||
4316 PointeeType != T->getPointeeTypeAsWritten()) {
4317 Result = getDerived().RebuildReferenceType(PointeeType,
4318 T->isSpelledAsLValue(),
4319 TL.getSigilLoc());
4320 if (Result.isNull())
4321 return QualType();
4322 }
4323
John McCall31168b02011-06-15 23:02:42 +00004324 // Objective-C ARC can add lifetime qualifiers to the type that we're
4325 // referring to.
4326 TLB.TypeWasModifiedSafely(
4327 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4328
John McCall70dd5f62009-10-30 00:06:24 +00004329 // r-value references can be rebuilt as l-value references.
4330 ReferenceTypeLoc NewTL;
4331 if (isa<LValueReferenceType>(Result))
4332 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4333 else
4334 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4335 NewTL.setSigilLoc(TL.getSigilLoc());
4336
4337 return Result;
4338}
4339
Mike Stump11289f42009-09-09 15:08:12 +00004340template<typename Derived>
4341QualType
John McCall550e0c22009-10-21 00:40:46 +00004342TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004343 LValueReferenceTypeLoc TL) {
4344 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004345}
4346
Mike Stump11289f42009-09-09 15:08:12 +00004347template<typename Derived>
4348QualType
John McCall550e0c22009-10-21 00:40:46 +00004349TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004350 RValueReferenceTypeLoc TL) {
4351 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004352}
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregord6ff3322009-08-04 16:50:30 +00004354template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004355QualType
John McCall550e0c22009-10-21 00:40:46 +00004356TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004357 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004358 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004359 if (PointeeType.isNull())
4360 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004361
Abramo Bagnara509357842011-03-05 14:42:21 +00004362 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004363 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004364 if (OldClsTInfo) {
4365 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4366 if (!NewClsTInfo)
4367 return QualType();
4368 }
4369
4370 const MemberPointerType *T = TL.getTypePtr();
4371 QualType OldClsType = QualType(T->getClass(), 0);
4372 QualType NewClsType;
4373 if (NewClsTInfo)
4374 NewClsType = NewClsTInfo->getType();
4375 else {
4376 NewClsType = getDerived().TransformType(OldClsType);
4377 if (NewClsType.isNull())
4378 return QualType();
4379 }
Mike Stump11289f42009-09-09 15:08:12 +00004380
John McCall550e0c22009-10-21 00:40:46 +00004381 QualType Result = TL.getType();
4382 if (getDerived().AlwaysRebuild() ||
4383 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004384 NewClsType != OldClsType) {
4385 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004386 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004387 if (Result.isNull())
4388 return QualType();
4389 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004390
Reid Kleckner0503a872013-12-05 01:23:43 +00004391 // If we had to adjust the pointee type when building a member pointer, make
4392 // sure to push TypeLoc info for it.
4393 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4394 if (MPT && PointeeType != MPT->getPointeeType()) {
4395 assert(isa<AdjustedType>(MPT->getPointeeType()));
4396 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4397 }
4398
John McCall550e0c22009-10-21 00:40:46 +00004399 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4400 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004401 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004402
4403 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004404}
4405
Mike Stump11289f42009-09-09 15:08:12 +00004406template<typename Derived>
4407QualType
John McCall550e0c22009-10-21 00:40:46 +00004408TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004409 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004410 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004411 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004412 if (ElementType.isNull())
4413 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004414
John McCall550e0c22009-10-21 00:40:46 +00004415 QualType Result = TL.getType();
4416 if (getDerived().AlwaysRebuild() ||
4417 ElementType != T->getElementType()) {
4418 Result = getDerived().RebuildConstantArrayType(ElementType,
4419 T->getSizeModifier(),
4420 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004421 T->getIndexTypeCVRQualifiers(),
4422 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004423 if (Result.isNull())
4424 return QualType();
4425 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004426
4427 // We might have either a ConstantArrayType or a VariableArrayType now:
4428 // a ConstantArrayType is allowed to have an element type which is a
4429 // VariableArrayType if the type is dependent. Fortunately, all array
4430 // types have the same location layout.
4431 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004432 NewTL.setLBracketLoc(TL.getLBracketLoc());
4433 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004434
John McCall550e0c22009-10-21 00:40:46 +00004435 Expr *Size = TL.getSizeExpr();
4436 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004437 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4438 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004439 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4440 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004441 }
4442 NewTL.setSizeExpr(Size);
4443
4444 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004445}
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregord6ff3322009-08-04 16:50:30 +00004447template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004448QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004449 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004450 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004451 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004452 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004453 if (ElementType.isNull())
4454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004455
John McCall550e0c22009-10-21 00:40:46 +00004456 QualType Result = TL.getType();
4457 if (getDerived().AlwaysRebuild() ||
4458 ElementType != T->getElementType()) {
4459 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004460 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004461 T->getIndexTypeCVRQualifiers(),
4462 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004463 if (Result.isNull())
4464 return QualType();
4465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004466
John McCall550e0c22009-10-21 00:40:46 +00004467 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4468 NewTL.setLBracketLoc(TL.getLBracketLoc());
4469 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004470 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004471
4472 return Result;
4473}
4474
4475template<typename Derived>
4476QualType
4477TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004478 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004479 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004480 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4481 if (ElementType.isNull())
4482 return QualType();
4483
John McCalldadc5752010-08-24 06:29:42 +00004484 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004485 = getDerived().TransformExpr(T->getSizeExpr());
4486 if (SizeResult.isInvalid())
4487 return QualType();
4488
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004489 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004490
4491 QualType Result = TL.getType();
4492 if (getDerived().AlwaysRebuild() ||
4493 ElementType != T->getElementType() ||
4494 Size != T->getSizeExpr()) {
4495 Result = getDerived().RebuildVariableArrayType(ElementType,
4496 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004497 Size,
John McCall550e0c22009-10-21 00:40:46 +00004498 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004499 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004500 if (Result.isNull())
4501 return QualType();
4502 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004503
Serge Pavlov774c6d02014-02-06 03:49:11 +00004504 // We might have constant size array now, but fortunately it has the same
4505 // location layout.
4506 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004507 NewTL.setLBracketLoc(TL.getLBracketLoc());
4508 NewTL.setRBracketLoc(TL.getRBracketLoc());
4509 NewTL.setSizeExpr(Size);
4510
4511 return Result;
4512}
4513
4514template<typename Derived>
4515QualType
4516TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004517 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004518 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004519 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4520 if (ElementType.isNull())
4521 return QualType();
4522
Richard Smith764d2fe2011-12-20 02:08:33 +00004523 // Array bounds are constant expressions.
4524 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4525 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004526
John McCall33ddac02011-01-19 10:06:00 +00004527 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4528 Expr *origSize = TL.getSizeExpr();
4529 if (!origSize) origSize = T->getSizeExpr();
4530
4531 ExprResult sizeResult
4532 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004533 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004534 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004535 return QualType();
4536
John McCall33ddac02011-01-19 10:06:00 +00004537 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004538
4539 QualType Result = TL.getType();
4540 if (getDerived().AlwaysRebuild() ||
4541 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004542 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004543 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4544 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004545 size,
John McCall550e0c22009-10-21 00:40:46 +00004546 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004547 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004548 if (Result.isNull())
4549 return QualType();
4550 }
John McCall550e0c22009-10-21 00:40:46 +00004551
4552 // We might have any sort of array type now, but fortunately they
4553 // all have the same location layout.
4554 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4555 NewTL.setLBracketLoc(TL.getLBracketLoc());
4556 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004557 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004558
4559 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004560}
Mike Stump11289f42009-09-09 15:08:12 +00004561
4562template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004564 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004565 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004566 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004567
4568 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004569 QualType ElementType = getDerived().TransformType(T->getElementType());
4570 if (ElementType.isNull())
4571 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004572
Richard Smith764d2fe2011-12-20 02:08:33 +00004573 // Vector sizes are constant expressions.
4574 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4575 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004576
John McCalldadc5752010-08-24 06:29:42 +00004577 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004578 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004579 if (Size.isInvalid())
4580 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004581
John McCall550e0c22009-10-21 00:40:46 +00004582 QualType Result = TL.getType();
4583 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004584 ElementType != T->getElementType() ||
4585 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004586 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004587 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004588 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004589 if (Result.isNull())
4590 return QualType();
4591 }
John McCall550e0c22009-10-21 00:40:46 +00004592
4593 // Result might be dependent or not.
4594 if (isa<DependentSizedExtVectorType>(Result)) {
4595 DependentSizedExtVectorTypeLoc NewTL
4596 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4597 NewTL.setNameLoc(TL.getNameLoc());
4598 } else {
4599 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4600 NewTL.setNameLoc(TL.getNameLoc());
4601 }
4602
4603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004604}
Mike Stump11289f42009-09-09 15:08:12 +00004605
4606template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004607QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004608 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004609 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004610 QualType ElementType = getDerived().TransformType(T->getElementType());
4611 if (ElementType.isNull())
4612 return QualType();
4613
John McCall550e0c22009-10-21 00:40:46 +00004614 QualType Result = TL.getType();
4615 if (getDerived().AlwaysRebuild() ||
4616 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004617 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004618 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004619 if (Result.isNull())
4620 return QualType();
4621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004622
John McCall550e0c22009-10-21 00:40:46 +00004623 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4624 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004625
John McCall550e0c22009-10-21 00:40:46 +00004626 return Result;
4627}
4628
4629template<typename Derived>
4630QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004631 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004632 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004633 QualType ElementType = getDerived().TransformType(T->getElementType());
4634 if (ElementType.isNull())
4635 return QualType();
4636
4637 QualType Result = TL.getType();
4638 if (getDerived().AlwaysRebuild() ||
4639 ElementType != T->getElementType()) {
4640 Result = getDerived().RebuildExtVectorType(ElementType,
4641 T->getNumElements(),
4642 /*FIXME*/ SourceLocation());
4643 if (Result.isNull())
4644 return QualType();
4645 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004646
John McCall550e0c22009-10-21 00:40:46 +00004647 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4648 NewTL.setNameLoc(TL.getNameLoc());
4649
4650 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651}
Mike Stump11289f42009-09-09 15:08:12 +00004652
David Blaikie05785d12013-02-20 22:23:23 +00004653template <typename Derived>
4654ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4655 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4656 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004657 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004658 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004659
Douglas Gregor715e4612011-01-14 22:40:04 +00004660 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004661 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004662 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004663 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004664 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004665
Douglas Gregor715e4612011-01-14 22:40:04 +00004666 TypeLocBuilder TLB;
4667 TypeLoc NewTL = OldDI->getTypeLoc();
4668 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004669
4670 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004671 OldExpansionTL.getPatternLoc());
4672 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004673 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004674
4675 Result = RebuildPackExpansionType(Result,
4676 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004677 OldExpansionTL.getEllipsisLoc(),
4678 NumExpansions);
4679 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004680 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004681
Douglas Gregor715e4612011-01-14 22:40:04 +00004682 PackExpansionTypeLoc NewExpansionTL
4683 = TLB.push<PackExpansionTypeLoc>(Result);
4684 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4685 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4686 } else
4687 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004688 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004689 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004690
John McCall8fb0d9d2011-05-01 22:35:37 +00004691 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004692 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004693
4694 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4695 OldParm->getDeclContext(),
4696 OldParm->getInnerLocStart(),
4697 OldParm->getLocation(),
4698 OldParm->getIdentifier(),
4699 NewDI->getType(),
4700 NewDI,
4701 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004702 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004703 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4704 OldParm->getFunctionScopeIndex() + indexAdjustment);
4705 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004706}
4707
David Majnemer59f77922016-06-24 04:05:48 +00004708template <typename Derived>
4709bool TreeTransform<Derived>::TransformFunctionTypeParams(
4710 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4711 const QualType *ParamTypes,
4712 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4713 SmallVectorImpl<QualType> &OutParamTypes,
4714 SmallVectorImpl<ParmVarDecl *> *PVars,
4715 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004716 int indexAdjustment = 0;
4717
David Majnemer59f77922016-06-24 04:05:48 +00004718 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004719 for (unsigned i = 0; i != NumParams; ++i) {
4720 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004721 assert(OldParm->getFunctionScopeIndex() == i);
4722
David Blaikie05785d12013-02-20 22:23:23 +00004723 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004724 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004725 if (OldParm->isParameterPack()) {
4726 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004727 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004728
Douglas Gregor5499af42011-01-05 23:12:31 +00004729 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004730 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004731 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004732 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4733 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004734 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4735
Douglas Gregor5499af42011-01-05 23:12:31 +00004736 // Determine whether we should expand the parameter packs.
4737 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004738 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004739 Optional<unsigned> OrigNumExpansions =
4740 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004741 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004742 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4743 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004744 Unexpanded,
4745 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004746 RetainExpansion,
4747 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004748 return true;
4749 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004750
Douglas Gregor5499af42011-01-05 23:12:31 +00004751 if (ShouldExpand) {
4752 // Expand the function parameter pack into multiple, separate
4753 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004754 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004755 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004756 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004757 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004758 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004759 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004760 OrigNumExpansions,
4761 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004762 if (!NewParm)
4763 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004764
John McCallc8e321d2016-03-01 02:09:25 +00004765 if (ParamInfos)
4766 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004767 OutParamTypes.push_back(NewParm->getType());
4768 if (PVars)
4769 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004770 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004771
4772 // If we're supposed to retain a pack expansion, do so by temporarily
4773 // forgetting the partially-substituted parameter pack.
4774 if (RetainExpansion) {
4775 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004776 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004777 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004778 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004779 OrigNumExpansions,
4780 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004781 if (!NewParm)
4782 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004783
John McCallc8e321d2016-03-01 02:09:25 +00004784 if (ParamInfos)
4785 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004786 OutParamTypes.push_back(NewParm->getType());
4787 if (PVars)
4788 PVars->push_back(NewParm);
4789 }
4790
John McCall8fb0d9d2011-05-01 22:35:37 +00004791 // The next parameter should have the same adjustment as the
4792 // last thing we pushed, but we post-incremented indexAdjustment
4793 // on every push. Also, if we push nothing, the adjustment should
4794 // go down by one.
4795 indexAdjustment--;
4796
Douglas Gregor5499af42011-01-05 23:12:31 +00004797 // We're done with the pack expansion.
4798 continue;
4799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004800
4801 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004802 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004803 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4804 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004805 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004806 NumExpansions,
4807 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004808 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004809 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004810 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004811 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004812
John McCall58f10c32010-03-11 09:03:00 +00004813 if (!NewParm)
4814 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004815
John McCallc8e321d2016-03-01 02:09:25 +00004816 if (ParamInfos)
4817 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004818 OutParamTypes.push_back(NewParm->getType());
4819 if (PVars)
4820 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004821 continue;
4822 }
John McCall58f10c32010-03-11 09:03:00 +00004823
4824 // Deal with the possibility that we don't have a parameter
4825 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004826 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004827 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004828 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004829 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004830 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004831 = dyn_cast<PackExpansionType>(OldType)) {
4832 // We have a function parameter pack that may need to be expanded.
4833 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004834 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004835 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004836
Douglas Gregor5499af42011-01-05 23:12:31 +00004837 // Determine whether we should expand the parameter packs.
4838 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004839 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004840 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004841 Unexpanded,
4842 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004843 RetainExpansion,
4844 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004845 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004846 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004847
Douglas Gregor5499af42011-01-05 23:12:31 +00004848 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004849 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004850 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004851 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004852 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4853 QualType NewType = getDerived().TransformType(Pattern);
4854 if (NewType.isNull())
4855 return true;
John McCall58f10c32010-03-11 09:03:00 +00004856
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00004857 if (NewType->containsUnexpandedParameterPack()) {
4858 NewType =
4859 getSema().getASTContext().getPackExpansionType(NewType, None);
4860
4861 if (NewType.isNull())
4862 return true;
4863 }
4864
John McCallc8e321d2016-03-01 02:09:25 +00004865 if (ParamInfos)
4866 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004867 OutParamTypes.push_back(NewType);
4868 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004869 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004871
Douglas Gregor5499af42011-01-05 23:12:31 +00004872 // We're done with the pack expansion.
4873 continue;
4874 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004875
Douglas Gregor48d24112011-01-10 20:53:55 +00004876 // If we're supposed to retain a pack expansion, do so by temporarily
4877 // forgetting the partially-substituted parameter pack.
4878 if (RetainExpansion) {
4879 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4880 QualType NewType = getDerived().TransformType(Pattern);
4881 if (NewType.isNull())
4882 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004883
John McCallc8e321d2016-03-01 02:09:25 +00004884 if (ParamInfos)
4885 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004886 OutParamTypes.push_back(NewType);
4887 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004888 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004889 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004890
Chad Rosier1dcde962012-08-08 18:46:20 +00004891 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004892 // expansion.
4893 OldType = Expansion->getPattern();
4894 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004895 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4896 NewType = getDerived().TransformType(OldType);
4897 } else {
4898 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004899 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004900
Douglas Gregor5499af42011-01-05 23:12:31 +00004901 if (NewType.isNull())
4902 return true;
4903
4904 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004905 NewType = getSema().Context.getPackExpansionType(NewType,
4906 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004907
John McCallc8e321d2016-03-01 02:09:25 +00004908 if (ParamInfos)
4909 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004910 OutParamTypes.push_back(NewType);
4911 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004912 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004913 }
4914
John McCall8fb0d9d2011-05-01 22:35:37 +00004915#ifndef NDEBUG
4916 if (PVars) {
4917 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4918 if (ParmVarDecl *parm = (*PVars)[i])
4919 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004920 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004921#endif
4922
4923 return false;
4924}
John McCall58f10c32010-03-11 09:03:00 +00004925
4926template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004927QualType
John McCall550e0c22009-10-21 00:40:46 +00004928TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004929 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004930 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004931 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004932 return getDerived().TransformFunctionProtoType(
4933 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004934 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4935 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4936 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004937 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004938}
4939
Richard Smith2e321552014-11-12 02:00:47 +00004940template<typename Derived> template<typename Fn>
4941QualType TreeTransform<Derived>::TransformFunctionProtoType(
4942 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4943 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004944
Douglas Gregor4afc2362010-08-31 00:26:14 +00004945 // Transform the parameters and return type.
4946 //
Richard Smithf623c962012-04-17 00:58:00 +00004947 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004948 // When the function has a trailing return type, we instantiate the
4949 // parameters before the return type, since the return type can then refer
4950 // to the parameters themselves (via decltype, sizeof, etc.).
4951 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004952 SmallVector<QualType, 4> ParamTypes;
4953 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004954 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004955 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004956
Douglas Gregor7fb25412010-10-01 18:44:50 +00004957 QualType ResultType;
4958
Richard Smith1226c602012-08-14 22:51:13 +00004959 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004960 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004961 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004962 TL.getTypePtr()->param_type_begin(),
4963 T->getExtParameterInfosOrNull(),
4964 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004965 return QualType();
4966
Douglas Gregor3024f072012-04-16 07:05:22 +00004967 {
4968 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004969 // If a declaration declares a member function or member function
4970 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004971 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004972 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004973 // declarator.
4974 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004975
Alp Toker42a16a62014-01-25 23:51:36 +00004976 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004977 if (ResultType.isNull())
4978 return QualType();
4979 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004980 }
4981 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004982 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004983 if (ResultType.isNull())
4984 return QualType();
4985
Alp Toker9cacbab2014-01-20 20:26:09 +00004986 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004987 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004988 TL.getTypePtr()->param_type_begin(),
4989 T->getExtParameterInfosOrNull(),
4990 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004991 return QualType();
4992 }
4993
Richard Smith2e321552014-11-12 02:00:47 +00004994 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4995
4996 bool EPIChanged = false;
4997 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4998 return QualType();
4999
John McCallc8e321d2016-03-01 02:09:25 +00005000 // Handle extended parameter information.
5001 if (auto NewExtParamInfos =
5002 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5003 if (!EPI.ExtParameterInfos ||
5004 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5005 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5006 EPIChanged = true;
5007 }
5008 EPI.ExtParameterInfos = NewExtParamInfos;
5009 } else if (EPI.ExtParameterInfos) {
5010 EPIChanged = true;
5011 EPI.ExtParameterInfos = nullptr;
5012 }
Richard Smithf623c962012-04-17 00:58:00 +00005013
John McCall550e0c22009-10-21 00:40:46 +00005014 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005015 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005016 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005017 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005018 if (Result.isNull())
5019 return QualType();
5020 }
Mike Stump11289f42009-09-09 15:08:12 +00005021
John McCall550e0c22009-10-21 00:40:46 +00005022 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005023 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005024 NewTL.setLParenLoc(TL.getLParenLoc());
5025 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005026 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005027 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5028 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005029
5030 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregord6ff3322009-08-04 16:50:30 +00005033template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005034bool TreeTransform<Derived>::TransformExceptionSpec(
5035 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5036 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5037 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5038
5039 // Instantiate a dynamic noexcept expression, if any.
5040 if (ESI.Type == EST_ComputedNoexcept) {
5041 EnterExpressionEvaluationContext Unevaluated(getSema(),
5042 Sema::ConstantEvaluated);
5043 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5044 if (NoexceptExpr.isInvalid())
5045 return true;
5046
Richard Smith03a4aa32016-06-23 19:02:52 +00005047 // FIXME: This is bogus, a noexcept expression is not a condition.
5048 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005049 if (NoexceptExpr.isInvalid())
5050 return true;
5051
5052 if (!NoexceptExpr.get()->isValueDependent()) {
5053 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5054 NoexceptExpr.get(), nullptr,
5055 diag::err_noexcept_needs_constant_expression,
5056 /*AllowFold*/false);
5057 if (NoexceptExpr.isInvalid())
5058 return true;
5059 }
5060
5061 if (ESI.NoexceptExpr != NoexceptExpr.get())
5062 Changed = true;
5063 ESI.NoexceptExpr = NoexceptExpr.get();
5064 }
5065
5066 if (ESI.Type != EST_Dynamic)
5067 return false;
5068
5069 // Instantiate a dynamic exception specification's type.
5070 for (QualType T : ESI.Exceptions) {
5071 if (const PackExpansionType *PackExpansion =
5072 T->getAs<PackExpansionType>()) {
5073 Changed = true;
5074
5075 // We have a pack expansion. Instantiate it.
5076 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5077 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5078 Unexpanded);
5079 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5080
5081 // Determine whether the set of unexpanded parameter packs can and
5082 // should
5083 // be expanded.
5084 bool Expand = false;
5085 bool RetainExpansion = false;
5086 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5087 // FIXME: Track the location of the ellipsis (and track source location
5088 // information for the types in the exception specification in general).
5089 if (getDerived().TryExpandParameterPacks(
5090 Loc, SourceRange(), Unexpanded, Expand,
5091 RetainExpansion, NumExpansions))
5092 return true;
5093
5094 if (!Expand) {
5095 // We can't expand this pack expansion into separate arguments yet;
5096 // just substitute into the pattern and create a new pack expansion
5097 // type.
5098 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5099 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5100 if (U.isNull())
5101 return true;
5102
5103 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5104 Exceptions.push_back(U);
5105 continue;
5106 }
5107
5108 // Substitute into the pack expansion pattern for each slice of the
5109 // pack.
5110 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5111 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5112
5113 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5114 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5115 return true;
5116
5117 Exceptions.push_back(U);
5118 }
5119 } else {
5120 QualType U = getDerived().TransformType(T);
5121 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5122 return true;
5123 if (T != U)
5124 Changed = true;
5125
5126 Exceptions.push_back(U);
5127 }
5128 }
5129
5130 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005131 if (ESI.Exceptions.empty())
5132 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005133 return false;
5134}
5135
5136template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005137QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005138 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005139 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005140 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005141 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005142 if (ResultType.isNull())
5143 return QualType();
5144
5145 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005146 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005147 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5148
5149 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005150 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005151 NewTL.setLParenLoc(TL.getLParenLoc());
5152 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005153 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005154
5155 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005156}
Mike Stump11289f42009-09-09 15:08:12 +00005157
John McCallb96ec562009-12-04 22:46:56 +00005158template<typename Derived> QualType
5159TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005160 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005161 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005162 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005163 if (!D)
5164 return QualType();
5165
5166 QualType Result = TL.getType();
5167 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005168 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005169 if (Result.isNull())
5170 return QualType();
5171 }
5172
5173 // We might get an arbitrary type spec type back. We should at
5174 // least always get a type spec type, though.
5175 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5176 NewTL.setNameLoc(TL.getNameLoc());
5177
5178 return Result;
5179}
5180
Douglas Gregord6ff3322009-08-04 16:50:30 +00005181template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005182QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005183 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005184 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005185 TypedefNameDecl *Typedef
5186 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5187 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005188 if (!Typedef)
5189 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005190
John McCall550e0c22009-10-21 00:40:46 +00005191 QualType Result = TL.getType();
5192 if (getDerived().AlwaysRebuild() ||
5193 Typedef != T->getDecl()) {
5194 Result = getDerived().RebuildTypedefType(Typedef);
5195 if (Result.isNull())
5196 return QualType();
5197 }
Mike Stump11289f42009-09-09 15:08:12 +00005198
John McCall550e0c22009-10-21 00:40:46 +00005199 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5200 NewTL.setNameLoc(TL.getNameLoc());
5201
5202 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005203}
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregord6ff3322009-08-04 16:50:30 +00005205template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005206QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005207 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005208 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005209 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5210 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005211
John McCalldadc5752010-08-24 06:29:42 +00005212 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005213 if (E.isInvalid())
5214 return QualType();
5215
Eli Friedmane4f22df2012-02-29 04:03:55 +00005216 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5217 if (E.isInvalid())
5218 return QualType();
5219
John McCall550e0c22009-10-21 00:40:46 +00005220 QualType Result = TL.getType();
5221 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005222 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005223 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005224 if (Result.isNull())
5225 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005226 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005227 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005228
John McCall550e0c22009-10-21 00:40:46 +00005229 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005230 NewTL.setTypeofLoc(TL.getTypeofLoc());
5231 NewTL.setLParenLoc(TL.getLParenLoc());
5232 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005233
5234 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005235}
Mike Stump11289f42009-09-09 15:08:12 +00005236
5237template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005238QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005239 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005240 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5241 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5242 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005243 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005244
John McCall550e0c22009-10-21 00:40:46 +00005245 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005246 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5247 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005248 if (Result.isNull())
5249 return QualType();
5250 }
Mike Stump11289f42009-09-09 15:08:12 +00005251
John McCall550e0c22009-10-21 00:40:46 +00005252 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005253 NewTL.setTypeofLoc(TL.getTypeofLoc());
5254 NewTL.setLParenLoc(TL.getLParenLoc());
5255 NewTL.setRParenLoc(TL.getRParenLoc());
5256 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005257
5258 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
5261template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005262QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005263 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005264 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005265
Douglas Gregore922c772009-08-04 22:27:00 +00005266 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005267 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5268 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005269
John McCalldadc5752010-08-24 06:29:42 +00005270 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005271 if (E.isInvalid())
5272 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005273
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005274 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005275 if (E.isInvalid())
5276 return QualType();
5277
John McCall550e0c22009-10-21 00:40:46 +00005278 QualType Result = TL.getType();
5279 if (getDerived().AlwaysRebuild() ||
5280 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005281 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005282 if (Result.isNull())
5283 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005284 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005285 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005286
John McCall550e0c22009-10-21 00:40:46 +00005287 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5288 NewTL.setNameLoc(TL.getNameLoc());
5289
5290 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005291}
5292
5293template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005294QualType TreeTransform<Derived>::TransformUnaryTransformType(
5295 TypeLocBuilder &TLB,
5296 UnaryTransformTypeLoc TL) {
5297 QualType Result = TL.getType();
5298 if (Result->isDependentType()) {
5299 const UnaryTransformType *T = TL.getTypePtr();
5300 QualType NewBase =
5301 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5302 Result = getDerived().RebuildUnaryTransformType(NewBase,
5303 T->getUTTKind(),
5304 TL.getKWLoc());
5305 if (Result.isNull())
5306 return QualType();
5307 }
5308
5309 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5310 NewTL.setKWLoc(TL.getKWLoc());
5311 NewTL.setParensRange(TL.getParensRange());
5312 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5313 return Result;
5314}
5315
5316template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005317QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5318 AutoTypeLoc TL) {
5319 const AutoType *T = TL.getTypePtr();
5320 QualType OldDeduced = T->getDeducedType();
5321 QualType NewDeduced;
5322 if (!OldDeduced.isNull()) {
5323 NewDeduced = getDerived().TransformType(OldDeduced);
5324 if (NewDeduced.isNull())
5325 return QualType();
5326 }
5327
5328 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005329 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5330 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005331 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005332 if (Result.isNull())
5333 return QualType();
5334 }
5335
5336 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5337 NewTL.setNameLoc(TL.getNameLoc());
5338
5339 return Result;
5340}
5341
5342template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005343QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005344 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005345 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005346 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005347 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5348 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005349 if (!Record)
5350 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005351
John McCall550e0c22009-10-21 00:40:46 +00005352 QualType Result = TL.getType();
5353 if (getDerived().AlwaysRebuild() ||
5354 Record != T->getDecl()) {
5355 Result = getDerived().RebuildRecordType(Record);
5356 if (Result.isNull())
5357 return QualType();
5358 }
Mike Stump11289f42009-09-09 15:08:12 +00005359
John McCall550e0c22009-10-21 00:40:46 +00005360 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5361 NewTL.setNameLoc(TL.getNameLoc());
5362
5363 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005364}
Mike Stump11289f42009-09-09 15:08:12 +00005365
5366template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005367QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005368 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005369 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005370 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005371 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5372 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005373 if (!Enum)
5374 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005375
John McCall550e0c22009-10-21 00:40:46 +00005376 QualType Result = TL.getType();
5377 if (getDerived().AlwaysRebuild() ||
5378 Enum != T->getDecl()) {
5379 Result = getDerived().RebuildEnumType(Enum);
5380 if (Result.isNull())
5381 return QualType();
5382 }
Mike Stump11289f42009-09-09 15:08:12 +00005383
John McCall550e0c22009-10-21 00:40:46 +00005384 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5385 NewTL.setNameLoc(TL.getNameLoc());
5386
5387 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005388}
John McCallfcc33b02009-09-05 00:15:47 +00005389
John McCalle78aac42010-03-10 03:28:59 +00005390template<typename Derived>
5391QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5392 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005393 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005394 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5395 TL.getTypePtr()->getDecl());
5396 if (!D) return QualType();
5397
5398 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5399 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5400 return T;
5401}
5402
Douglas Gregord6ff3322009-08-04 16:50:30 +00005403template<typename Derived>
5404QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005405 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005406 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005407 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005408}
5409
Mike Stump11289f42009-09-09 15:08:12 +00005410template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005411QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005412 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005413 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005414 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005415
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005416 // Substitute into the replacement type, which itself might involve something
5417 // that needs to be transformed. This only tends to occur with default
5418 // template arguments of template template parameters.
5419 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5420 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5421 if (Replacement.isNull())
5422 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005423
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005424 // Always canonicalize the replacement type.
5425 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5426 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005427 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005428 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005429
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005430 // Propagate type-source information.
5431 SubstTemplateTypeParmTypeLoc NewTL
5432 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5433 NewTL.setNameLoc(TL.getNameLoc());
5434 return Result;
5435
John McCallcebee162009-10-18 09:09:24 +00005436}
5437
5438template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005439QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5440 TypeLocBuilder &TLB,
5441 SubstTemplateTypeParmPackTypeLoc TL) {
5442 return TransformTypeSpecType(TLB, TL);
5443}
5444
5445template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005446QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005447 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005448 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005449 const TemplateSpecializationType *T = TL.getTypePtr();
5450
Douglas Gregordf846d12011-03-02 18:46:51 +00005451 // The nested-name-specifier never matters in a TemplateSpecializationType,
5452 // because we can't have a dependent nested-name-specifier anyway.
5453 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005454 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005455 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5456 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005457 if (Template.isNull())
5458 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005459
John McCall31f82722010-11-12 08:19:04 +00005460 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5461}
5462
Eli Friedman0dfb8892011-10-06 23:00:33 +00005463template<typename Derived>
5464QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5465 AtomicTypeLoc TL) {
5466 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5467 if (ValueType.isNull())
5468 return QualType();
5469
5470 QualType Result = TL.getType();
5471 if (getDerived().AlwaysRebuild() ||
5472 ValueType != TL.getValueLoc().getType()) {
5473 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5474 if (Result.isNull())
5475 return QualType();
5476 }
5477
5478 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5479 NewTL.setKWLoc(TL.getKWLoc());
5480 NewTL.setLParenLoc(TL.getLParenLoc());
5481 NewTL.setRParenLoc(TL.getRParenLoc());
5482
5483 return Result;
5484}
5485
Xiuli Pan9c14e282016-01-09 12:53:17 +00005486template <typename Derived>
5487QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5488 PipeTypeLoc TL) {
5489 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5490 if (ValueType.isNull())
5491 return QualType();
5492
5493 QualType Result = TL.getType();
5494 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005495 const PipeType *PT = Result->getAs<PipeType>();
5496 bool isReadPipe = PT->isReadOnly();
5497 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005498 if (Result.isNull())
5499 return QualType();
5500 }
5501
5502 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5503 NewTL.setKWLoc(TL.getKWLoc());
5504
5505 return Result;
5506}
5507
Chad Rosier1dcde962012-08-08 18:46:20 +00005508 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005509 /// container that provides a \c getArgLoc() member function.
5510 ///
5511 /// This iterator is intended to be used with the iterator form of
5512 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5513 template<typename ArgLocContainer>
5514 class TemplateArgumentLocContainerIterator {
5515 ArgLocContainer *Container;
5516 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005517
Douglas Gregorfe921a72010-12-20 23:36:19 +00005518 public:
5519 typedef TemplateArgumentLoc value_type;
5520 typedef TemplateArgumentLoc reference;
5521 typedef int difference_type;
5522 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005523
Douglas Gregorfe921a72010-12-20 23:36:19 +00005524 class pointer {
5525 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005526
Douglas Gregorfe921a72010-12-20 23:36:19 +00005527 public:
5528 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005529
Douglas Gregorfe921a72010-12-20 23:36:19 +00005530 const TemplateArgumentLoc *operator->() const {
5531 return &Arg;
5532 }
5533 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005534
5535
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005536 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005537
Douglas Gregorfe921a72010-12-20 23:36:19 +00005538 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5539 unsigned Index)
5540 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005541
Douglas Gregorfe921a72010-12-20 23:36:19 +00005542 TemplateArgumentLocContainerIterator &operator++() {
5543 ++Index;
5544 return *this;
5545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005546
Douglas Gregorfe921a72010-12-20 23:36:19 +00005547 TemplateArgumentLocContainerIterator operator++(int) {
5548 TemplateArgumentLocContainerIterator Old(*this);
5549 ++(*this);
5550 return Old;
5551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregorfe921a72010-12-20 23:36:19 +00005553 TemplateArgumentLoc operator*() const {
5554 return Container->getArgLoc(Index);
5555 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005556
Douglas Gregorfe921a72010-12-20 23:36:19 +00005557 pointer operator->() const {
5558 return pointer(Container->getArgLoc(Index));
5559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005560
Douglas Gregorfe921a72010-12-20 23:36:19 +00005561 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005562 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005563 return X.Container == Y.Container && X.Index == Y.Index;
5564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005565
Douglas Gregorfe921a72010-12-20 23:36:19 +00005566 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005567 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005568 return !(X == Y);
5569 }
5570 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005571
5572
John McCall31f82722010-11-12 08:19:04 +00005573template <typename Derived>
5574QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5575 TypeLocBuilder &TLB,
5576 TemplateSpecializationTypeLoc TL,
5577 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005578 TemplateArgumentListInfo NewTemplateArgs;
5579 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5580 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005581 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5582 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005583 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005584 ArgIterator(TL, TL.getNumArgs()),
5585 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005586 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005587
John McCall0ad16662009-10-29 08:12:44 +00005588 // FIXME: maybe don't rebuild if all the template arguments are the same.
5589
5590 QualType Result =
5591 getDerived().RebuildTemplateSpecializationType(Template,
5592 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005593 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005594
5595 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005596 // Specializations of template template parameters are represented as
5597 // TemplateSpecializationTypes, and substitution of type alias templates
5598 // within a dependent context can transform them into
5599 // DependentTemplateSpecializationTypes.
5600 if (isa<DependentTemplateSpecializationType>(Result)) {
5601 DependentTemplateSpecializationTypeLoc NewTL
5602 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005603 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005604 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005605 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005606 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005607 NewTL.setLAngleLoc(TL.getLAngleLoc());
5608 NewTL.setRAngleLoc(TL.getRAngleLoc());
5609 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5610 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5611 return Result;
5612 }
5613
John McCall0ad16662009-10-29 08:12:44 +00005614 TemplateSpecializationTypeLoc NewTL
5615 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005616 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005617 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5618 NewTL.setLAngleLoc(TL.getLAngleLoc());
5619 NewTL.setRAngleLoc(TL.getRAngleLoc());
5620 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5621 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005622 }
Mike Stump11289f42009-09-09 15:08:12 +00005623
John McCall0ad16662009-10-29 08:12:44 +00005624 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005625}
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregor5a064722011-02-28 17:23:35 +00005627template <typename Derived>
5628QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5629 TypeLocBuilder &TLB,
5630 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005631 TemplateName Template,
5632 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005633 TemplateArgumentListInfo NewTemplateArgs;
5634 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5635 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5636 typedef TemplateArgumentLocContainerIterator<
5637 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005638 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005639 ArgIterator(TL, TL.getNumArgs()),
5640 NewTemplateArgs))
5641 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005642
Douglas Gregor5a064722011-02-28 17:23:35 +00005643 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005644
Douglas Gregor5a064722011-02-28 17:23:35 +00005645 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5646 QualType Result
5647 = getSema().Context.getDependentTemplateSpecializationType(
5648 TL.getTypePtr()->getKeyword(),
5649 DTN->getQualifier(),
5650 DTN->getIdentifier(),
5651 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005652
Douglas Gregor5a064722011-02-28 17:23:35 +00005653 DependentTemplateSpecializationTypeLoc NewTL
5654 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005655 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005656 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005657 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005658 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005659 NewTL.setLAngleLoc(TL.getLAngleLoc());
5660 NewTL.setRAngleLoc(TL.getRAngleLoc());
5661 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5662 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5663 return Result;
5664 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005665
5666 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005667 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005668 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005669 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005670
Douglas Gregor5a064722011-02-28 17:23:35 +00005671 if (!Result.isNull()) {
5672 /// FIXME: Wrap this in an elaborated-type-specifier?
5673 TemplateSpecializationTypeLoc NewTL
5674 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005675 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005676 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005677 NewTL.setLAngleLoc(TL.getLAngleLoc());
5678 NewTL.setRAngleLoc(TL.getRAngleLoc());
5679 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5680 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5681 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005682
Douglas Gregor5a064722011-02-28 17:23:35 +00005683 return Result;
5684}
5685
Mike Stump11289f42009-09-09 15:08:12 +00005686template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005687QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005688TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005689 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005690 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005691
Douglas Gregor844cb502011-03-01 18:12:44 +00005692 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005693 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005694 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005695 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005696 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5697 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005698 return QualType();
5699 }
Mike Stump11289f42009-09-09 15:08:12 +00005700
John McCall31f82722010-11-12 08:19:04 +00005701 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5702 if (NamedT.isNull())
5703 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005704
Richard Smith3f1b5d02011-05-05 21:57:07 +00005705 // C++0x [dcl.type.elab]p2:
5706 // If the identifier resolves to a typedef-name or the simple-template-id
5707 // resolves to an alias template specialization, the
5708 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005709 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5710 if (const TemplateSpecializationType *TST =
5711 NamedT->getAs<TemplateSpecializationType>()) {
5712 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005713 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5714 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005715 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005716 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005717 << TAT << Sema::NTK_TypeAliasTemplate
5718 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005719 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5720 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005721 }
5722 }
5723
John McCall550e0c22009-10-21 00:40:46 +00005724 QualType Result = TL.getType();
5725 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005726 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005727 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005728 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005729 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005730 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005731 if (Result.isNull())
5732 return QualType();
5733 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005734
Abramo Bagnara6150c882010-05-11 21:36:43 +00005735 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005736 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005737 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005738 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005739}
Mike Stump11289f42009-09-09 15:08:12 +00005740
5741template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005742QualType TreeTransform<Derived>::TransformAttributedType(
5743 TypeLocBuilder &TLB,
5744 AttributedTypeLoc TL) {
5745 const AttributedType *oldType = TL.getTypePtr();
5746 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5747 if (modifiedType.isNull())
5748 return QualType();
5749
5750 QualType result = TL.getType();
5751
5752 // FIXME: dependent operand expressions?
5753 if (getDerived().AlwaysRebuild() ||
5754 modifiedType != oldType->getModifiedType()) {
5755 // TODO: this is really lame; we should really be rebuilding the
5756 // equivalent type from first principles.
5757 QualType equivalentType
5758 = getDerived().TransformType(oldType->getEquivalentType());
5759 if (equivalentType.isNull())
5760 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005761
5762 // Check whether we can add nullability; it is only represented as
5763 // type sugar, and therefore cannot be diagnosed in any other way.
5764 if (auto nullability = oldType->getImmediateNullability()) {
5765 if (!modifiedType->canHaveNullability()) {
5766 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005767 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005768 return QualType();
5769 }
5770 }
5771
John McCall81904512011-01-06 01:58:22 +00005772 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5773 modifiedType,
5774 equivalentType);
5775 }
5776
5777 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5778 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5779 if (TL.hasAttrOperand())
5780 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5781 if (TL.hasAttrExprOperand())
5782 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5783 else if (TL.hasAttrEnumOperand())
5784 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5785
5786 return result;
5787}
5788
5789template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005790QualType
5791TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5792 ParenTypeLoc TL) {
5793 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5794 if (Inner.isNull())
5795 return QualType();
5796
5797 QualType Result = TL.getType();
5798 if (getDerived().AlwaysRebuild() ||
5799 Inner != TL.getInnerLoc().getType()) {
5800 Result = getDerived().RebuildParenType(Inner);
5801 if (Result.isNull())
5802 return QualType();
5803 }
5804
5805 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5806 NewTL.setLParenLoc(TL.getLParenLoc());
5807 NewTL.setRParenLoc(TL.getRParenLoc());
5808 return Result;
5809}
5810
5811template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005812QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005813 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005814 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005815
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005816 NestedNameSpecifierLoc QualifierLoc
5817 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5818 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005819 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005820
John McCallc392f372010-06-11 00:33:02 +00005821 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005822 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005823 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005824 QualifierLoc,
5825 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005826 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005827 if (Result.isNull())
5828 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005829
Abramo Bagnarad7548482010-05-19 21:37:53 +00005830 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5831 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005832 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5833
Abramo Bagnarad7548482010-05-19 21:37:53 +00005834 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005835 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005836 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005837 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005838 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005839 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005840 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005841 NewTL.setNameLoc(TL.getNameLoc());
5842 }
John McCall550e0c22009-10-21 00:40:46 +00005843 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005844}
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregord6ff3322009-08-04 16:50:30 +00005846template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005847QualType TreeTransform<Derived>::
5848 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005849 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005850 NestedNameSpecifierLoc QualifierLoc;
5851 if (TL.getQualifierLoc()) {
5852 QualifierLoc
5853 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5854 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005855 return QualType();
5856 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005857
John McCall31f82722010-11-12 08:19:04 +00005858 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005859 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005860}
5861
5862template<typename Derived>
5863QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005864TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5865 DependentTemplateSpecializationTypeLoc TL,
5866 NestedNameSpecifierLoc QualifierLoc) {
5867 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Douglas Gregora7a795b2011-03-01 20:11:18 +00005869 TemplateArgumentListInfo NewTemplateArgs;
5870 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5871 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005872
Douglas Gregora7a795b2011-03-01 20:11:18 +00005873 typedef TemplateArgumentLocContainerIterator<
5874 DependentTemplateSpecializationTypeLoc> ArgIterator;
5875 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5876 ArgIterator(TL, TL.getNumArgs()),
5877 NewTemplateArgs))
5878 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005879
Douglas Gregora7a795b2011-03-01 20:11:18 +00005880 QualType Result
5881 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5882 QualifierLoc,
5883 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005884 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005885 NewTemplateArgs);
5886 if (Result.isNull())
5887 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005888
Douglas Gregora7a795b2011-03-01 20:11:18 +00005889 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5890 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005891
Douglas Gregora7a795b2011-03-01 20:11:18 +00005892 // Copy information relevant to the template specialization.
5893 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005894 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005895 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005896 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005897 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5898 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005899 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005900 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
Douglas Gregora7a795b2011-03-01 20:11:18 +00005902 // Copy information relevant to the elaborated type.
5903 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005904 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005905 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005906 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5907 DependentTemplateSpecializationTypeLoc SpecTL
5908 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005909 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005910 SpecTL.setQualifierLoc(QualifierLoc);
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 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005918 TemplateSpecializationTypeLoc SpecTL
5919 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005920 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005921 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005922 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5923 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005924 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005925 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005926 }
5927 return Result;
5928}
5929
5930template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005931QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5932 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005933 QualType Pattern
5934 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005935 if (Pattern.isNull())
5936 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005937
5938 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005939 if (getDerived().AlwaysRebuild() ||
5940 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005941 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005942 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005943 TL.getEllipsisLoc(),
5944 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005945 if (Result.isNull())
5946 return QualType();
5947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005948
Douglas Gregor822d0302011-01-12 17:07:58 +00005949 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5950 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5951 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005952}
5953
5954template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005955QualType
5956TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005957 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005958 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005959 TLB.pushFullCopy(TL);
5960 return TL.getType();
5961}
5962
5963template<typename Derived>
5964QualType
Manman Rene6be26c2016-09-13 17:25:08 +00005965TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
5966 ObjCTypeParamTypeLoc TL) {
5967 const ObjCTypeParamType *T = TL.getTypePtr();
5968 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
5969 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
5970 if (!OTP)
5971 return QualType();
5972
5973 QualType Result = TL.getType();
5974 if (getDerived().AlwaysRebuild() ||
5975 OTP != T->getDecl()) {
5976 Result = getDerived().RebuildObjCTypeParamType(OTP,
5977 TL.getProtocolLAngleLoc(),
5978 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5979 TL.getNumProtocols()),
5980 TL.getProtocolLocs(),
5981 TL.getProtocolRAngleLoc());
5982 if (Result.isNull())
5983 return QualType();
5984 }
5985
5986 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
5987 if (TL.getNumProtocols()) {
5988 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5989 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5990 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
5991 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5992 }
5993 return Result;
5994}
5995
5996template<typename Derived>
5997QualType
John McCall8b07ec22010-05-15 11:32:37 +00005998TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005999 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006000 // Transform base type.
6001 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6002 if (BaseType.isNull())
6003 return QualType();
6004
6005 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6006
6007 // Transform type arguments.
6008 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6009 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6010 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6011 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6012 QualType TypeArg = TypeArgInfo->getType();
6013 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6014 AnyChanged = true;
6015
6016 // We have a pack expansion. Instantiate it.
6017 const auto *PackExpansion = PackExpansionLoc.getType()
6018 ->castAs<PackExpansionType>();
6019 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6020 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6021 Unexpanded);
6022 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6023
6024 // Determine whether the set of unexpanded parameter packs can
6025 // and should be expanded.
6026 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6027 bool Expand = false;
6028 bool RetainExpansion = false;
6029 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6030 if (getDerived().TryExpandParameterPacks(
6031 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6032 Unexpanded, Expand, RetainExpansion, NumExpansions))
6033 return QualType();
6034
6035 if (!Expand) {
6036 // We can't expand this pack expansion into separate arguments yet;
6037 // just substitute into the pattern and create a new pack expansion
6038 // type.
6039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6040
6041 TypeLocBuilder TypeArgBuilder;
6042 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6043 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6044 PatternLoc);
6045 if (NewPatternType.isNull())
6046 return QualType();
6047
6048 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6049 NewPatternType, NumExpansions);
6050 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6051 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6052 NewTypeArgInfos.push_back(
6053 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6054 continue;
6055 }
6056
6057 // Substitute into the pack expansion pattern for each slice of the
6058 // pack.
6059 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6061
6062 TypeLocBuilder TypeArgBuilder;
6063 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6064
6065 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6066 PatternLoc);
6067 if (NewTypeArg.isNull())
6068 return QualType();
6069
6070 NewTypeArgInfos.push_back(
6071 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6072 }
6073
6074 continue;
6075 }
6076
6077 TypeLocBuilder TypeArgBuilder;
6078 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6079 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6080 if (NewTypeArg.isNull())
6081 return QualType();
6082
6083 // If nothing changed, just keep the old TypeSourceInfo.
6084 if (NewTypeArg == TypeArg) {
6085 NewTypeArgInfos.push_back(TypeArgInfo);
6086 continue;
6087 }
6088
6089 NewTypeArgInfos.push_back(
6090 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6091 AnyChanged = true;
6092 }
6093
6094 QualType Result = TL.getType();
6095 if (getDerived().AlwaysRebuild() || AnyChanged) {
6096 // Rebuild the type.
6097 Result = getDerived().RebuildObjCObjectType(
6098 BaseType,
6099 TL.getLocStart(),
6100 TL.getTypeArgsLAngleLoc(),
6101 NewTypeArgInfos,
6102 TL.getTypeArgsRAngleLoc(),
6103 TL.getProtocolLAngleLoc(),
6104 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6105 TL.getNumProtocols()),
6106 TL.getProtocolLocs(),
6107 TL.getProtocolRAngleLoc());
6108
6109 if (Result.isNull())
6110 return QualType();
6111 }
6112
6113 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006114 NewT.setHasBaseTypeAsWritten(true);
6115 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6116 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6117 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6118 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6119 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6120 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6121 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6122 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6123 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006124}
Mike Stump11289f42009-09-09 15:08:12 +00006125
6126template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006127QualType
6128TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006129 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006130 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6131 if (PointeeType.isNull())
6132 return QualType();
6133
6134 QualType Result = TL.getType();
6135 if (getDerived().AlwaysRebuild() ||
6136 PointeeType != TL.getPointeeLoc().getType()) {
6137 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6138 TL.getStarLoc());
6139 if (Result.isNull())
6140 return QualType();
6141 }
6142
6143 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6144 NewT.setStarLoc(TL.getStarLoc());
6145 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006146}
6147
Douglas Gregord6ff3322009-08-04 16:50:30 +00006148//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006149// Statement transformation
6150//===----------------------------------------------------------------------===//
6151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006152StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006153TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006154 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006155}
6156
6157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006158StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006159TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6160 return getDerived().TransformCompoundStmt(S, false);
6161}
6162
6163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006164StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006165TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006167 Sema::CompoundScopeRAII CompoundScope(getSema());
6168
John McCall1ababa62010-08-27 19:56:05 +00006169 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006171 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006172 for (auto *B : S->body()) {
6173 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006174 if (Result.isInvalid()) {
6175 // Immediately fail if this was a DeclStmt, since it's very
6176 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006177 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006178 return StmtError();
6179
6180 // Otherwise, just keep processing substatements and fail later.
6181 SubStmtInvalid = true;
6182 continue;
6183 }
Mike Stump11289f42009-09-09 15:08:12 +00006184
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006185 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006186 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 }
Mike Stump11289f42009-09-09 15:08:12 +00006188
John McCall1ababa62010-08-27 19:56:05 +00006189 if (SubStmtInvalid)
6190 return StmtError();
6191
Douglas Gregorebe10102009-08-20 07:17:43 +00006192 if (!getDerived().AlwaysRebuild() &&
6193 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006194 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006195
6196 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006197 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006198 S->getRBracLoc(),
6199 IsStmtExpr);
6200}
Mike Stump11289f42009-09-09 15:08:12 +00006201
Douglas Gregorebe10102009-08-20 07:17:43 +00006202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006203StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006204TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006205 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006206 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006207 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6208 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006209
Eli Friedman06577382009-11-19 03:14:00 +00006210 // Transform the left-hand case value.
6211 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006212 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006213 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006214 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006215
Eli Friedman06577382009-11-19 03:14:00 +00006216 // Transform the right-hand case value (for the GNU case-range extension).
6217 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006218 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006219 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006220 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006221 }
Mike Stump11289f42009-09-09 15:08:12 +00006222
Douglas Gregorebe10102009-08-20 07:17:43 +00006223 // Build the case statement.
6224 // Case statements are always rebuilt so that they will attached to their
6225 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006226 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006227 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006228 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006229 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006230 S->getColonLoc());
6231 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006232 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregorebe10102009-08-20 07:17:43 +00006234 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006235 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006236 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006238
Douglas Gregorebe10102009-08-20 07:17:43 +00006239 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006240 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006241}
6242
6243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006244StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006245TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006246 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006247 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006249 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregorebe10102009-08-20 07:17:43 +00006251 // Default statements are always rebuilt
6252 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006253 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006254}
Mike Stump11289f42009-09-09 15:08:12 +00006255
Douglas Gregorebe10102009-08-20 07:17:43 +00006256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006257StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006258TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006259 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006260 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006261 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006262
Chris Lattnercab02a62011-02-17 20:34:02 +00006263 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6264 S->getDecl());
6265 if (!LD)
6266 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006267
6268
Douglas Gregorebe10102009-08-20 07:17:43 +00006269 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006270 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006271 cast<LabelDecl>(LD), SourceLocation(),
6272 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006273}
Mike Stump11289f42009-09-09 15:08:12 +00006274
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006275template <typename Derived>
6276const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6277 if (!R)
6278 return R;
6279
6280 switch (R->getKind()) {
6281// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6282#define ATTR(X)
6283#define PRAGMA_SPELLING_ATTR(X) \
6284 case attr::X: \
6285 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6286#include "clang/Basic/AttrList.inc"
6287 default:
6288 return R;
6289 }
6290}
6291
6292template <typename Derived>
6293StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6294 bool AttrsChanged = false;
6295 SmallVector<const Attr *, 1> Attrs;
6296
6297 // Visit attributes and keep track if any are transformed.
6298 for (const auto *I : S->getAttrs()) {
6299 const Attr *R = getDerived().TransformAttr(I);
6300 AttrsChanged |= (I != R);
6301 Attrs.push_back(R);
6302 }
6303
Richard Smithc202b282012-04-14 00:33:13 +00006304 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6305 if (SubStmt.isInvalid())
6306 return StmtError();
6307
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006308 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006309 return S;
6310
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006311 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006312 SubStmt.get());
6313}
6314
6315template<typename Derived>
6316StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006317TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006318 // Transform the initialization statement
6319 StmtResult Init = getDerived().TransformStmt(S->getInit());
6320 if (Init.isInvalid())
6321 return StmtError();
6322
Douglas Gregorebe10102009-08-20 07:17:43 +00006323 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006324 Sema::ConditionResult Cond = getDerived().TransformCondition(
6325 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006326 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6327 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006328 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006329 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006330
Richard Smithb130fe72016-06-23 19:16:49 +00006331 // If this is a constexpr if, determine which arm we should instantiate.
6332 llvm::Optional<bool> ConstexprConditionValue;
6333 if (S->isConstexpr())
6334 ConstexprConditionValue = Cond.getKnownValue();
6335
Douglas Gregorebe10102009-08-20 07:17:43 +00006336 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006337 StmtResult Then;
6338 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6339 Then = getDerived().TransformStmt(S->getThen());
6340 if (Then.isInvalid())
6341 return StmtError();
6342 } else {
6343 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6344 }
Mike Stump11289f42009-09-09 15:08:12 +00006345
Douglas Gregorebe10102009-08-20 07:17:43 +00006346 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006347 StmtResult Else;
6348 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6349 Else = getDerived().TransformStmt(S->getElse());
6350 if (Else.isInvalid())
6351 return StmtError();
6352 }
Mike Stump11289f42009-09-09 15:08:12 +00006353
Douglas Gregorebe10102009-08-20 07:17:43 +00006354 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006355 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006356 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006357 Then.get() == S->getThen() &&
6358 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006359 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006360
Richard Smithb130fe72016-06-23 19:16:49 +00006361 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006362 Init.get(), Then.get(), S->getElseLoc(),
6363 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006364}
6365
6366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006367StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006368TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006369 // Transform the initialization statement
6370 StmtResult Init = getDerived().TransformStmt(S->getInit());
6371 if (Init.isInvalid())
6372 return StmtError();
6373
Douglas Gregorebe10102009-08-20 07:17:43 +00006374 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006375 Sema::ConditionResult Cond = getDerived().TransformCondition(
6376 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6377 Sema::ConditionKind::Switch);
6378 if (Cond.isInvalid())
6379 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregorebe10102009-08-20 07:17:43 +00006381 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006382 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006383 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6384 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006385 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006386 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006387
Douglas Gregorebe10102009-08-20 07:17:43 +00006388 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006389 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006390 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006391 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006392
Douglas Gregorebe10102009-08-20 07:17:43 +00006393 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006394 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6395 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006396}
Mike Stump11289f42009-09-09 15:08:12 +00006397
Douglas Gregorebe10102009-08-20 07:17:43 +00006398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006399StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006400TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006401 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006402 Sema::ConditionResult Cond = getDerived().TransformCondition(
6403 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6404 Sema::ConditionKind::Boolean);
6405 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006406 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006407
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006409 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006410 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006412
Douglas Gregorebe10102009-08-20 07:17:43 +00006413 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006414 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006415 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006416 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006417
Richard Smith03a4aa32016-06-23 19:02:52 +00006418 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006419}
Mike Stump11289f42009-09-09 15:08:12 +00006420
Douglas Gregorebe10102009-08-20 07:17:43 +00006421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006422StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006423TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006424 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006425 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006426 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006427 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006428
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006429 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006430 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006431 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006432 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006433
Douglas Gregorebe10102009-08-20 07:17:43 +00006434 if (!getDerived().AlwaysRebuild() &&
6435 Cond.get() == S->getCond() &&
6436 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006437 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006438
John McCallb268a282010-08-23 23:25:46 +00006439 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6440 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006441 S->getRParenLoc());
6442}
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregorebe10102009-08-20 07:17:43 +00006444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006445StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006446TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006447 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006448 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006449 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006450 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006451
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006452 // In OpenMP loop region loop control variable must be captured and be
6453 // private. Perform analysis of first part (if any).
6454 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6455 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6456
Douglas Gregorebe10102009-08-20 07:17:43 +00006457 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006458 Sema::ConditionResult Cond = getDerived().TransformCondition(
6459 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6460 Sema::ConditionKind::Boolean);
6461 if (Cond.isInvalid())
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 increment
John McCalldadc5752010-08-24 06:29:42 +00006465 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006466 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006467 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006468
Richard Smith945f8d32013-01-14 22:39:08 +00006469 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006470 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006471 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006472
Douglas Gregorebe10102009-08-20 07:17:43 +00006473 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006474 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006475 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006476 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006477
Douglas Gregorebe10102009-08-20 07:17:43 +00006478 if (!getDerived().AlwaysRebuild() &&
6479 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006480 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006481 Inc.get() == S->getInc() &&
6482 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006483 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006484
Douglas Gregorebe10102009-08-20 07:17:43 +00006485 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006486 Init.get(), Cond, FullInc,
6487 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006488}
6489
6490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006491StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006492TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006493 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6494 S->getLabel());
6495 if (!LD)
6496 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006497
Douglas Gregorebe10102009-08-20 07:17:43 +00006498 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006499 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006500 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006501}
6502
6503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006504StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006505TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006506 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006507 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006508 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006509 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregorebe10102009-08-20 07:17:43 +00006511 if (!getDerived().AlwaysRebuild() &&
6512 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006513 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006514
6515 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006516 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006517}
6518
6519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006520StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006521TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006522 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006523}
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregorebe10102009-08-20 07:17:43 +00006525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006526StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006527TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006528 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006529}
Mike Stump11289f42009-09-09 15:08:12 +00006530
Douglas Gregorebe10102009-08-20 07:17:43 +00006531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006532StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006533TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006534 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6535 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006536 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006537 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006538
Mike Stump11289f42009-09-09 15:08:12 +00006539 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006540 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006541 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006542}
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregorebe10102009-08-20 07:17:43 +00006544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006545StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006546TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006547 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006548 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006549 for (auto *D : S->decls()) {
6550 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006551 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006552 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006553
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006554 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006555 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregorebe10102009-08-20 07:17:43 +00006557 Decls.push_back(Transformed);
6558 }
Mike Stump11289f42009-09-09 15:08:12 +00006559
Douglas Gregorebe10102009-08-20 07:17:43 +00006560 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006561 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006562
Rafael Espindolaab417692013-07-09 12:05:01 +00006563 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006564}
Mike Stump11289f42009-09-09 15:08:12 +00006565
Douglas Gregorebe10102009-08-20 07:17:43 +00006566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006567StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006568TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006569
Benjamin Kramerf0623432012-08-23 22:51:59 +00006570 SmallVector<Expr*, 8> Constraints;
6571 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006572 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006573
John McCalldadc5752010-08-24 06:29:42 +00006574 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006575 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006576
6577 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006578
Anders Carlssonaaeef072010-01-24 05:50:09 +00006579 // Go through the outputs.
6580 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006581 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Anders Carlssonaaeef072010-01-24 05:50:09 +00006583 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006584 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006585
Anders Carlssonaaeef072010-01-24 05:50:09 +00006586 // Transform the output expr.
6587 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006588 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006589 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006590 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006591
Anders Carlssonaaeef072010-01-24 05:50:09 +00006592 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006593
John McCallb268a282010-08-23 23:25:46 +00006594 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006596
Anders Carlssonaaeef072010-01-24 05:50:09 +00006597 // Go through the inputs.
6598 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006599 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006600
Anders Carlssonaaeef072010-01-24 05:50:09 +00006601 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006602 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006603
Anders Carlssonaaeef072010-01-24 05:50:09 +00006604 // Transform the input expr.
6605 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006606 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006607 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006608 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006609
Anders Carlssonaaeef072010-01-24 05:50:09 +00006610 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006611
John McCallb268a282010-08-23 23:25:46 +00006612 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006613 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006614
Anders Carlssonaaeef072010-01-24 05:50:09 +00006615 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006616 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006617
6618 // Go through the clobbers.
6619 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006620 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006621
6622 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006623 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006624 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6625 S->isVolatile(), S->getNumOutputs(),
6626 S->getNumInputs(), Names.data(),
6627 Constraints, Exprs, AsmString.get(),
6628 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006629}
6630
Chad Rosier32503022012-06-11 20:47:18 +00006631template<typename Derived>
6632StmtResult
6633TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006634 ArrayRef<Token> AsmToks =
6635 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006636
John McCallf413f5e2013-05-03 00:10:13 +00006637 bool HadError = false, HadChange = false;
6638
6639 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6640 SmallVector<Expr*, 8> TransformedExprs;
6641 TransformedExprs.reserve(SrcExprs.size());
6642 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6643 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6644 if (!Result.isUsable()) {
6645 HadError = true;
6646 } else {
6647 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006648 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006649 }
6650 }
6651
6652 if (HadError) return StmtError();
6653 if (!HadChange && !getDerived().AlwaysRebuild())
6654 return Owned(S);
6655
Chad Rosierb6f46c12012-08-15 16:53:30 +00006656 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006657 AsmToks, S->getAsmString(),
6658 S->getNumOutputs(), S->getNumInputs(),
6659 S->getAllConstraints(), S->getClobbers(),
6660 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006661}
Douglas Gregorebe10102009-08-20 07:17:43 +00006662
Richard Smith9f690bd2015-10-27 06:02:45 +00006663// C++ Coroutines TS
6664
6665template<typename Derived>
6666StmtResult
6667TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6668 // The coroutine body should be re-formed by the caller if necessary.
Eric Fiselier709d1b32016-10-27 07:30:31 +00006669 // FIXME: The coroutine body is always rebuilt by ActOnFinishFunctionBody
Richard Smith9f690bd2015-10-27 06:02:45 +00006670 return getDerived().TransformStmt(S->getBody());
6671}
6672
6673template<typename Derived>
6674StmtResult
6675TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6676 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6677 /*NotCopyInit*/false);
6678 if (Result.isInvalid())
6679 return StmtError();
6680
6681 // Always rebuild; we don't know if this needs to be injected into a new
6682 // context or if the promise type has changed.
6683 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6684}
6685
6686template<typename Derived>
6687ExprResult
6688TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6689 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6690 /*NotCopyInit*/false);
6691 if (Result.isInvalid())
6692 return ExprError();
6693
6694 // Always rebuild; we don't know if this needs to be injected into a new
6695 // context or if the promise type has changed.
6696 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6697}
6698
6699template<typename Derived>
6700ExprResult
6701TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6702 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6703 /*NotCopyInit*/false);
6704 if (Result.isInvalid())
6705 return ExprError();
6706
6707 // Always rebuild; we don't know if this needs to be injected into a new
6708 // context or if the promise type has changed.
6709 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6710}
6711
6712// Objective-C Statements.
6713
Douglas Gregorebe10102009-08-20 07:17:43 +00006714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006715StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006716TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006717 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006718 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006719 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006720 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006721
Douglas Gregor96c79492010-04-23 22:50:49 +00006722 // Transform the @catch statements (if present).
6723 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006724 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006725 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006726 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006727 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006729 if (Catch.get() != S->getCatchStmt(I))
6730 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006731 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006732 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006733
Douglas Gregor306de2f2010-04-22 23:59:56 +00006734 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006735 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006736 if (S->getFinallyStmt()) {
6737 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6738 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006740 }
6741
6742 // If nothing changed, just retain this statement.
6743 if (!getDerived().AlwaysRebuild() &&
6744 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006745 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006746 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006747 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006748
Douglas Gregor306de2f2010-04-22 23:59:56 +00006749 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006750 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006751 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006752}
Mike Stump11289f42009-09-09 15:08:12 +00006753
Douglas Gregorebe10102009-08-20 07:17:43 +00006754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006755StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006756TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006757 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006758 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006759 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006760 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006761 if (FromVar->getTypeSourceInfo()) {
6762 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6763 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +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 QualType T;
6768 if (TSInfo)
6769 T = TSInfo->getType();
6770 else {
6771 T = getDerived().TransformType(FromVar->getType());
6772 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006773 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006774 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006776 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6777 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006779 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
John McCalldadc5752010-08-24 06:29:42 +00006781 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006782 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006783 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006784
6785 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006786 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006787 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006788}
Mike Stump11289f42009-09-09 15:08:12 +00006789
Douglas Gregorebe10102009-08-20 07:17:43 +00006790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006792TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006793 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006794 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006795 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006796 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006797
Douglas Gregor306de2f2010-04-22 23:59:56 +00006798 // If nothing changed, just retain this statement.
6799 if (!getDerived().AlwaysRebuild() &&
6800 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006801 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006802
6803 // Build a new statement.
6804 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006805 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006806}
Mike Stump11289f42009-09-09 15:08:12 +00006807
Douglas Gregorebe10102009-08-20 07:17:43 +00006808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006809StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006810TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006811 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006812 if (S->getThrowExpr()) {
6813 Operand = getDerived().TransformExpr(S->getThrowExpr());
6814 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006815 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006817
Douglas Gregor2900c162010-04-22 21:44:01 +00006818 if (!getDerived().AlwaysRebuild() &&
6819 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006820 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006821
John McCallb268a282010-08-23 23:25:46 +00006822 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006823}
Mike Stump11289f42009-09-09 15:08:12 +00006824
Douglas Gregorebe10102009-08-20 07:17:43 +00006825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006826StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006827TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006828 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006829 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006830 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006831 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006833 Object =
6834 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6835 Object.get());
6836 if (Object.isInvalid())
6837 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006838
Douglas Gregor6148de72010-04-22 22:01:21 +00006839 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006840 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006841 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006842 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006843
Douglas Gregor6148de72010-04-22 22:01:21 +00006844 // If nothing change, just retain the current statement.
6845 if (!getDerived().AlwaysRebuild() &&
6846 Object.get() == S->getSynchExpr() &&
6847 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006848 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006849
6850 // Build a new statement.
6851 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006852 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006853}
6854
6855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006856StmtResult
John McCall31168b02011-06-15 23:02:42 +00006857TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6858 ObjCAutoreleasePoolStmt *S) {
6859 // Transform the body.
6860 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6861 if (Body.isInvalid())
6862 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006863
John McCall31168b02011-06-15 23:02:42 +00006864 // If nothing changed, just retain this statement.
6865 if (!getDerived().AlwaysRebuild() &&
6866 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006867 return S;
John McCall31168b02011-06-15 23:02:42 +00006868
6869 // Build a new statement.
6870 return getDerived().RebuildObjCAutoreleasePoolStmt(
6871 S->getAtLoc(), Body.get());
6872}
6873
6874template<typename Derived>
6875StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006876TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006877 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006878 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006879 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006880 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006881 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006882
Douglas Gregorf68a5082010-04-22 23:10:45 +00006883 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006884 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006885 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006886 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006887
Douglas Gregorf68a5082010-04-22 23:10:45 +00006888 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006889 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006890 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006891 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006892
Douglas Gregorf68a5082010-04-22 23:10:45 +00006893 // If nothing changed, just retain this statement.
6894 if (!getDerived().AlwaysRebuild() &&
6895 Element.get() == S->getElement() &&
6896 Collection.get() == S->getCollection() &&
6897 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006898 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006899
Douglas Gregorf68a5082010-04-22 23:10:45 +00006900 // Build a new statement.
6901 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006902 Element.get(),
6903 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006904 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006905 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006906}
6907
David Majnemer5f7efef2013-10-15 09:50:08 +00006908template <typename Derived>
6909StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006910 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006911 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006912 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6913 TypeSourceInfo *T =
6914 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006915 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006916 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006917
David Majnemer5f7efef2013-10-15 09:50:08 +00006918 Var = getDerived().RebuildExceptionDecl(
6919 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6920 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006921 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006922 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006923 }
Mike Stump11289f42009-09-09 15:08:12 +00006924
Douglas Gregorebe10102009-08-20 07:17:43 +00006925 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006926 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006927 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006928 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006929
David Majnemer5f7efef2013-10-15 09:50:08 +00006930 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006931 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006932 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006933
David Majnemer5f7efef2013-10-15 09:50:08 +00006934 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006935}
Mike Stump11289f42009-09-09 15:08:12 +00006936
David Majnemer5f7efef2013-10-15 09:50:08 +00006937template <typename Derived>
6938StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006939 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006940 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006941 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006942 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006943
Douglas Gregorebe10102009-08-20 07:17:43 +00006944 // Transform the handlers.
6945 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006946 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006947 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006948 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006949 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006950 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006951
Douglas Gregorebe10102009-08-20 07:17:43 +00006952 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006953 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006954 }
Mike Stump11289f42009-09-09 15:08:12 +00006955
David Majnemer5f7efef2013-10-15 09:50:08 +00006956 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006957 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006958 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006959
John McCallb268a282010-08-23 23:25:46 +00006960 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006961 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006962}
Mike Stump11289f42009-09-09 15:08:12 +00006963
Richard Smith02e85f32011-04-14 22:09:26 +00006964template<typename Derived>
6965StmtResult
6966TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6967 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6968 if (Range.isInvalid())
6969 return StmtError();
6970
Richard Smith01694c32016-03-20 10:33:40 +00006971 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6972 if (Begin.isInvalid())
6973 return StmtError();
6974 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6975 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006976 return StmtError();
6977
6978 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6979 if (Cond.isInvalid())
6980 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006981 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006982 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006983 if (Cond.isInvalid())
6984 return StmtError();
6985 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006986 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006987
6988 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6989 if (Inc.isInvalid())
6990 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006991 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006992 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006993
6994 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6995 if (LoopVar.isInvalid())
6996 return StmtError();
6997
6998 StmtResult NewStmt = S;
6999 if (getDerived().AlwaysRebuild() ||
7000 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007001 Begin.get() != S->getBeginStmt() ||
7002 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007003 Cond.get() != S->getCond() ||
7004 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007005 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007006 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007007 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007008 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007009 Begin.get(), End.get(),
7010 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007011 Inc.get(), LoopVar.get(),
7012 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007013 if (NewStmt.isInvalid())
7014 return StmtError();
7015 }
Richard Smith02e85f32011-04-14 22:09:26 +00007016
7017 StmtResult Body = getDerived().TransformStmt(S->getBody());
7018 if (Body.isInvalid())
7019 return StmtError();
7020
7021 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7022 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007023 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007024 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007025 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007026 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007027 Begin.get(), End.get(),
7028 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007029 Inc.get(), LoopVar.get(),
7030 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007031 if (NewStmt.isInvalid())
7032 return StmtError();
7033 }
Richard Smith02e85f32011-04-14 22:09:26 +00007034
7035 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007036 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007037
7038 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7039}
7040
John Wiegley1c0675e2011-04-28 01:08:34 +00007041template<typename Derived>
7042StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007043TreeTransform<Derived>::TransformMSDependentExistsStmt(
7044 MSDependentExistsStmt *S) {
7045 // Transform the nested-name-specifier, if any.
7046 NestedNameSpecifierLoc QualifierLoc;
7047 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007048 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007049 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7050 if (!QualifierLoc)
7051 return StmtError();
7052 }
7053
7054 // Transform the declaration name.
7055 DeclarationNameInfo NameInfo = S->getNameInfo();
7056 if (NameInfo.getName()) {
7057 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7058 if (!NameInfo.getName())
7059 return StmtError();
7060 }
7061
7062 // Check whether anything changed.
7063 if (!getDerived().AlwaysRebuild() &&
7064 QualifierLoc == S->getQualifierLoc() &&
7065 NameInfo.getName() == S->getNameInfo().getName())
7066 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007067
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007068 // Determine whether this name exists, if we can.
7069 CXXScopeSpec SS;
7070 SS.Adopt(QualifierLoc);
7071 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007072 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007073 case Sema::IER_Exists:
7074 if (S->isIfExists())
7075 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007076
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007077 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7078
7079 case Sema::IER_DoesNotExist:
7080 if (S->isIfNotExists())
7081 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007082
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007083 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007084
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007085 case Sema::IER_Dependent:
7086 Dependent = true;
7087 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007088
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007089 case Sema::IER_Error:
7090 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007091 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007092
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007093 // We need to continue with the instantiation, so do so now.
7094 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7095 if (SubStmt.isInvalid())
7096 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007097
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007098 // If we have resolved the name, just transform to the substatement.
7099 if (!Dependent)
7100 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007101
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007102 // The name is still dependent, so build a dependent expression again.
7103 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7104 S->isIfExists(),
7105 QualifierLoc,
7106 NameInfo,
7107 SubStmt.get());
7108}
7109
7110template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007111ExprResult
7112TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7113 NestedNameSpecifierLoc QualifierLoc;
7114 if (E->getQualifierLoc()) {
7115 QualifierLoc
7116 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7117 if (!QualifierLoc)
7118 return ExprError();
7119 }
7120
7121 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7122 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7123 if (!PD)
7124 return ExprError();
7125
7126 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7127 if (Base.isInvalid())
7128 return ExprError();
7129
7130 return new (SemaRef.getASTContext())
7131 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7132 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7133 QualifierLoc, E->getMemberLoc());
7134}
7135
David Majnemerfad8f482013-10-15 09:33:02 +00007136template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007137ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7138 MSPropertySubscriptExpr *E) {
7139 auto BaseRes = getDerived().TransformExpr(E->getBase());
7140 if (BaseRes.isInvalid())
7141 return ExprError();
7142 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7143 if (IdxRes.isInvalid())
7144 return ExprError();
7145
7146 if (!getDerived().AlwaysRebuild() &&
7147 BaseRes.get() == E->getBase() &&
7148 IdxRes.get() == E->getIdx())
7149 return E;
7150
7151 return getDerived().RebuildArraySubscriptExpr(
7152 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7153}
7154
7155template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007156StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007157 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007158 if (TryBlock.isInvalid())
7159 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007160
7161 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007162 if (Handler.isInvalid())
7163 return StmtError();
7164
David Majnemerfad8f482013-10-15 09:33:02 +00007165 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7166 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007167 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007168
Warren Huntf6be4cb2014-07-25 20:52:51 +00007169 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7170 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007171}
7172
David Majnemerfad8f482013-10-15 09:33:02 +00007173template <typename Derived>
7174StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007175 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007176 if (Block.isInvalid())
7177 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007178
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007179 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007180}
7181
David Majnemerfad8f482013-10-15 09:33:02 +00007182template <typename Derived>
7183StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007184 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007185 if (FilterExpr.isInvalid())
7186 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007187
David Majnemer7e755502013-10-15 09:30:14 +00007188 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007189 if (Block.isInvalid())
7190 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007191
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007192 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7193 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007194}
7195
David Majnemerfad8f482013-10-15 09:33:02 +00007196template <typename Derived>
7197StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7198 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007199 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7200 else
7201 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7202}
7203
Nico Weber9b982072014-07-07 00:12:30 +00007204template<typename Derived>
7205StmtResult
7206TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7207 return S;
7208}
7209
Alexander Musman64d33f12014-06-04 07:53:32 +00007210//===----------------------------------------------------------------------===//
7211// OpenMP directive transformation
7212//===----------------------------------------------------------------------===//
7213template <typename Derived>
7214StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7215 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007216
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007217 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007218 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007219 ArrayRef<OMPClause *> Clauses = D->clauses();
7220 TClauses.reserve(Clauses.size());
7221 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7222 I != E; ++I) {
7223 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007224 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007225 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007226 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007227 if (Clause)
7228 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007229 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007230 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007231 }
7232 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007233 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007234 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007235 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7236 /*CurScope=*/nullptr);
7237 StmtResult Body;
7238 {
7239 Sema::CompoundScopeRAII CompoundScope(getSema());
7240 Body = getDerived().TransformStmt(
7241 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7242 }
7243 AssociatedStmt =
7244 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007245 if (AssociatedStmt.isInvalid()) {
7246 return StmtError();
7247 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007248 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007249 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007250 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007251 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007252
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007253 // Transform directive name for 'omp critical' directive.
7254 DeclarationNameInfo DirName;
7255 if (D->getDirectiveKind() == OMPD_critical) {
7256 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7257 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7258 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007259 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7260 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7261 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007262 } else if (D->getDirectiveKind() == OMPD_cancel) {
7263 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007264 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007265
Alexander Musman64d33f12014-06-04 07:53:32 +00007266 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007267 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7268 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007269}
7270
Alexander Musman64d33f12014-06-04 07:53:32 +00007271template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007272StmtResult
7273TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7274 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007275 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7276 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007277 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7278 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7279 return Res;
7280}
7281
Alexander Musman64d33f12014-06-04 07:53:32 +00007282template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007283StmtResult
7284TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7285 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007286 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7287 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007288 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7289 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007290 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007291}
7292
Alexey Bataevf29276e2014-06-18 04:14:57 +00007293template <typename Derived>
7294StmtResult
7295TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7296 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007297 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7298 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007299 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7300 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7301 return Res;
7302}
7303
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007304template <typename Derived>
7305StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007306TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7307 DeclarationNameInfo DirName;
7308 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7309 D->getLocStart());
7310 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7311 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7312 return Res;
7313}
7314
7315template <typename Derived>
7316StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007317TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7318 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007319 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7320 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007321 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7322 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7323 return Res;
7324}
7325
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007326template <typename Derived>
7327StmtResult
7328TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7329 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007330 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7331 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007332 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7333 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7334 return Res;
7335}
7336
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007337template <typename Derived>
7338StmtResult
7339TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7340 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007341 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7342 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007343 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7344 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7345 return Res;
7346}
7347
Alexey Bataev4acb8592014-07-07 13:01:15 +00007348template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007349StmtResult
7350TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7351 DeclarationNameInfo DirName;
7352 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7353 D->getLocStart());
7354 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7355 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7356 return Res;
7357}
7358
7359template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007360StmtResult
7361TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7362 getDerived().getSema().StartOpenMPDSABlock(
7363 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7364 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7365 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7366 return Res;
7367}
7368
7369template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007370StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7371 OMPParallelForDirective *D) {
7372 DeclarationNameInfo DirName;
7373 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7374 nullptr, D->getLocStart());
7375 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7376 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7377 return Res;
7378}
7379
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007380template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007381StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7382 OMPParallelForSimdDirective *D) {
7383 DeclarationNameInfo DirName;
7384 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7385 nullptr, D->getLocStart());
7386 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7387 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7388 return Res;
7389}
7390
7391template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007392StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7393 OMPParallelSectionsDirective *D) {
7394 DeclarationNameInfo DirName;
7395 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7396 nullptr, D->getLocStart());
7397 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7398 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7399 return Res;
7400}
7401
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007402template <typename Derived>
7403StmtResult
7404TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7405 DeclarationNameInfo DirName;
7406 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7407 D->getLocStart());
7408 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7409 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7410 return Res;
7411}
7412
Alexey Bataev68446b72014-07-18 07:47:19 +00007413template <typename Derived>
7414StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7415 OMPTaskyieldDirective *D) {
7416 DeclarationNameInfo DirName;
7417 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7418 D->getLocStart());
7419 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7420 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7421 return Res;
7422}
7423
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007424template <typename Derived>
7425StmtResult
7426TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7427 DeclarationNameInfo DirName;
7428 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7429 D->getLocStart());
7430 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7431 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7432 return Res;
7433}
7434
Alexey Bataev2df347a2014-07-18 10:17:07 +00007435template <typename Derived>
7436StmtResult
7437TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7438 DeclarationNameInfo DirName;
7439 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7440 D->getLocStart());
7441 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7442 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7443 return Res;
7444}
7445
Alexey Bataev6125da92014-07-21 11:26:11 +00007446template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007447StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7448 OMPTaskgroupDirective *D) {
7449 DeclarationNameInfo DirName;
7450 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7451 D->getLocStart());
7452 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7453 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7454 return Res;
7455}
7456
7457template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007458StmtResult
7459TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7460 DeclarationNameInfo DirName;
7461 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7462 D->getLocStart());
7463 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7464 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7465 return Res;
7466}
7467
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007468template <typename Derived>
7469StmtResult
7470TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7471 DeclarationNameInfo DirName;
7472 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7473 D->getLocStart());
7474 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7475 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7476 return Res;
7477}
7478
Alexey Bataev0162e452014-07-22 10:10:35 +00007479template <typename Derived>
7480StmtResult
7481TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7482 DeclarationNameInfo DirName;
7483 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7484 D->getLocStart());
7485 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7486 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7487 return Res;
7488}
7489
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007490template <typename Derived>
7491StmtResult
7492TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7493 DeclarationNameInfo DirName;
7494 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7495 D->getLocStart());
7496 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7497 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7498 return Res;
7499}
7500
Alexey Bataev13314bf2014-10-09 04:18:56 +00007501template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007502StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7503 OMPTargetDataDirective *D) {
7504 DeclarationNameInfo DirName;
7505 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7506 D->getLocStart());
7507 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7508 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7509 return Res;
7510}
7511
7512template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007513StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7514 OMPTargetEnterDataDirective *D) {
7515 DeclarationNameInfo DirName;
7516 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7517 nullptr, D->getLocStart());
7518 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7519 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7520 return Res;
7521}
7522
7523template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007524StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7525 OMPTargetExitDataDirective *D) {
7526 DeclarationNameInfo DirName;
7527 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7528 nullptr, D->getLocStart());
7529 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7530 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7531 return Res;
7532}
7533
7534template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007535StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7536 OMPTargetParallelDirective *D) {
7537 DeclarationNameInfo DirName;
7538 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7539 nullptr, D->getLocStart());
7540 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7541 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7542 return Res;
7543}
7544
7545template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007546StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7547 OMPTargetParallelForDirective *D) {
7548 DeclarationNameInfo DirName;
7549 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7550 nullptr, D->getLocStart());
7551 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7552 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7553 return Res;
7554}
7555
7556template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007557StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7558 OMPTargetUpdateDirective *D) {
7559 DeclarationNameInfo DirName;
7560 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7561 nullptr, D->getLocStart());
7562 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7563 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7564 return Res;
7565}
7566
7567template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007568StmtResult
7569TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7570 DeclarationNameInfo DirName;
7571 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7572 D->getLocStart());
7573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7574 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7575 return Res;
7576}
7577
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007578template <typename Derived>
7579StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7580 OMPCancellationPointDirective *D) {
7581 DeclarationNameInfo DirName;
7582 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7583 nullptr, D->getLocStart());
7584 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7585 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7586 return Res;
7587}
7588
Alexey Bataev80909872015-07-02 11:25:17 +00007589template <typename Derived>
7590StmtResult
7591TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7592 DeclarationNameInfo DirName;
7593 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7594 D->getLocStart());
7595 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7596 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7597 return Res;
7598}
7599
Alexey Bataev49f6e782015-12-01 04:18:41 +00007600template <typename Derived>
7601StmtResult
7602TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7603 DeclarationNameInfo DirName;
7604 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7605 D->getLocStart());
7606 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7607 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7608 return Res;
7609}
7610
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007611template <typename Derived>
7612StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7613 OMPTaskLoopSimdDirective *D) {
7614 DeclarationNameInfo DirName;
7615 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7616 nullptr, D->getLocStart());
7617 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7618 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7619 return Res;
7620}
7621
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007622template <typename Derived>
7623StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7624 OMPDistributeDirective *D) {
7625 DeclarationNameInfo DirName;
7626 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7627 D->getLocStart());
7628 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7629 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7630 return Res;
7631}
7632
Carlo Bertolli9925f152016-06-27 14:55:37 +00007633template <typename Derived>
7634StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7635 OMPDistributeParallelForDirective *D) {
7636 DeclarationNameInfo DirName;
7637 getDerived().getSema().StartOpenMPDSABlock(
7638 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7640 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7641 return Res;
7642}
7643
Kelvin Li4a39add2016-07-05 05:00:15 +00007644template <typename Derived>
7645StmtResult
7646TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7647 OMPDistributeParallelForSimdDirective *D) {
7648 DeclarationNameInfo DirName;
7649 getDerived().getSema().StartOpenMPDSABlock(
7650 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7651 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7652 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7653 return Res;
7654}
7655
Kelvin Li787f3fc2016-07-06 04:45:38 +00007656template <typename Derived>
7657StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7658 OMPDistributeSimdDirective *D) {
7659 DeclarationNameInfo DirName;
7660 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7661 nullptr, D->getLocStart());
7662 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7663 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7664 return Res;
7665}
7666
Kelvin Lia579b912016-07-14 02:54:56 +00007667template <typename Derived>
7668StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7669 OMPTargetParallelForSimdDirective *D) {
7670 DeclarationNameInfo DirName;
7671 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7672 DirName, nullptr,
7673 D->getLocStart());
7674 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7675 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7676 return Res;
7677}
7678
Kelvin Li986330c2016-07-20 22:57:10 +00007679template <typename Derived>
7680StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7681 OMPTargetSimdDirective *D) {
7682 DeclarationNameInfo DirName;
7683 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7684 D->getLocStart());
7685 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7686 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7687 return Res;
7688}
7689
Kelvin Li02532872016-08-05 14:37:37 +00007690template <typename Derived>
7691StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7692 OMPTeamsDistributeDirective *D) {
7693 DeclarationNameInfo DirName;
7694 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7695 nullptr, D->getLocStart());
7696 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7697 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7698 return Res;
7699}
7700
Kelvin Li4e325f72016-10-25 12:50:55 +00007701template <typename Derived>
7702StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
7703 OMPTeamsDistributeSimdDirective *D) {
7704 DeclarationNameInfo DirName;
7705 getDerived().getSema().StartOpenMPDSABlock(
7706 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7707 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7708 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7709 return Res;
7710}
7711
Kelvin Li579e41c2016-11-30 23:51:03 +00007712template <typename Derived>
7713StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
7714 OMPTeamsDistributeParallelForSimdDirective *D) {
7715 DeclarationNameInfo DirName;
7716 getDerived().getSema().StartOpenMPDSABlock(
7717 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7718 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7719 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7720 return Res;
7721}
7722
Kelvin Li7ade93f2016-12-09 03:24:30 +00007723template <typename Derived>
7724StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
7725 OMPTeamsDistributeParallelForDirective *D) {
7726 DeclarationNameInfo DirName;
7727 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
7728 DirName, nullptr, D->getLocStart());
7729 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7730 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7731 return Res;
7732}
7733
Kelvin Libf594a52016-12-17 05:48:59 +00007734template <typename Derived>
7735StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
7736 OMPTargetTeamsDirective *D) {
7737 DeclarationNameInfo DirName;
7738 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
7739 nullptr, D->getLocStart());
7740 auto Res = getDerived().TransformOMPExecutableDirective(D);
7741 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7742 return Res;
7743}
Kelvin Li579e41c2016-11-30 23:51:03 +00007744
Kelvin Li83c451e2016-12-25 04:52:54 +00007745template <typename Derived>
7746StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
7747 OMPTargetTeamsDistributeDirective *D) {
7748 DeclarationNameInfo DirName;
7749 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
7750 DirName, nullptr, D->getLocStart());
7751 auto Res = getDerived().TransformOMPExecutableDirective(D);
7752 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7753 return Res;
7754}
7755
Kelvin Li80e8f562016-12-29 22:16:30 +00007756template <typename Derived>
7757StmtResult
7758TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
7759 OMPTargetTeamsDistributeParallelForDirective *D) {
7760 DeclarationNameInfo DirName;
7761 getDerived().getSema().StartOpenMPDSABlock(
7762 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
7763 D->getLocStart());
7764 auto Res = getDerived().TransformOMPExecutableDirective(D);
7765 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7766 return Res;
7767}
7768
Alexander Musman64d33f12014-06-04 07:53:32 +00007769//===----------------------------------------------------------------------===//
7770// OpenMP clause transformation
7771//===----------------------------------------------------------------------===//
7772template <typename Derived>
7773OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007774 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7775 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007776 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007777 return getDerived().RebuildOMPIfClause(
7778 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7779 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007780}
7781
Alexander Musman64d33f12014-06-04 07:53:32 +00007782template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007783OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7784 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7785 if (Cond.isInvalid())
7786 return nullptr;
7787 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7788 C->getLParenLoc(), C->getLocEnd());
7789}
7790
7791template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007792OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007793TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7794 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7795 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007796 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007797 return getDerived().RebuildOMPNumThreadsClause(
7798 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007799}
7800
Alexey Bataev62c87d22014-03-21 04:51:18 +00007801template <typename Derived>
7802OMPClause *
7803TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7804 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7805 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007806 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007807 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007808 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007809}
7810
Alexander Musman8bd31e62014-05-27 15:12:19 +00007811template <typename Derived>
7812OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007813TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7814 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7815 if (E.isInvalid())
7816 return nullptr;
7817 return getDerived().RebuildOMPSimdlenClause(
7818 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7819}
7820
7821template <typename Derived>
7822OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007823TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7824 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7825 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007826 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007827 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007828 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007829}
7830
Alexander Musman64d33f12014-06-04 07:53:32 +00007831template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007832OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007833TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007834 return getDerived().RebuildOMPDefaultClause(
7835 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7836 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007837}
7838
Alexander Musman64d33f12014-06-04 07:53:32 +00007839template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007840OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007841TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007842 return getDerived().RebuildOMPProcBindClause(
7843 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7844 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007845}
7846
Alexander Musman64d33f12014-06-04 07:53:32 +00007847template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007848OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007849TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7850 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7851 if (E.isInvalid())
7852 return nullptr;
7853 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007854 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007855 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007856 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007857 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7858}
7859
7860template <typename Derived>
7861OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007862TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007863 ExprResult E;
7864 if (auto *Num = C->getNumForLoops()) {
7865 E = getDerived().TransformExpr(Num);
7866 if (E.isInvalid())
7867 return nullptr;
7868 }
7869 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7870 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007871}
7872
7873template <typename Derived>
7874OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007875TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7876 // No need to rebuild this clause, no template-dependent parameters.
7877 return C;
7878}
7879
7880template <typename Derived>
7881OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007882TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7883 // No need to rebuild this clause, no template-dependent parameters.
7884 return C;
7885}
7886
7887template <typename Derived>
7888OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007889TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7890 // No need to rebuild this clause, no template-dependent parameters.
7891 return C;
7892}
7893
7894template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007895OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7896 // No need to rebuild this clause, no template-dependent parameters.
7897 return C;
7898}
7899
7900template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007901OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7902 // No need to rebuild this clause, no template-dependent parameters.
7903 return C;
7904}
7905
7906template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007907OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007908TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7909 // No need to rebuild this clause, no template-dependent parameters.
7910 return C;
7911}
7912
7913template <typename Derived>
7914OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007915TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7916 // No need to rebuild this clause, no template-dependent parameters.
7917 return C;
7918}
7919
7920template <typename Derived>
7921OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007922TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7923 // No need to rebuild this clause, no template-dependent parameters.
7924 return C;
7925}
7926
7927template <typename Derived>
7928OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007929TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7930 // No need to rebuild this clause, no template-dependent parameters.
7931 return C;
7932}
7933
7934template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007935OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7936 // No need to rebuild this clause, no template-dependent parameters.
7937 return C;
7938}
7939
7940template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007941OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007942TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7943 // No need to rebuild this clause, no template-dependent parameters.
7944 return C;
7945}
7946
7947template <typename Derived>
7948OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007949TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007950 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007951 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007952 for (auto *VE : C->varlists()) {
7953 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007954 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007955 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007956 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007957 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007958 return getDerived().RebuildOMPPrivateClause(
7959 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007960}
7961
Alexander Musman64d33f12014-06-04 07:53:32 +00007962template <typename Derived>
7963OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7964 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007965 llvm::SmallVector<Expr *, 16> Vars;
7966 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007967 for (auto *VE : C->varlists()) {
7968 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007969 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007970 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007971 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007972 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007973 return getDerived().RebuildOMPFirstprivateClause(
7974 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007975}
7976
Alexander Musman64d33f12014-06-04 07:53:32 +00007977template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007978OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007979TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7980 llvm::SmallVector<Expr *, 16> Vars;
7981 Vars.reserve(C->varlist_size());
7982 for (auto *VE : C->varlists()) {
7983 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7984 if (EVar.isInvalid())
7985 return nullptr;
7986 Vars.push_back(EVar.get());
7987 }
7988 return getDerived().RebuildOMPLastprivateClause(
7989 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7990}
7991
7992template <typename Derived>
7993OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007994TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7995 llvm::SmallVector<Expr *, 16> Vars;
7996 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007997 for (auto *VE : C->varlists()) {
7998 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007999 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008000 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008001 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008002 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008003 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8004 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008005}
8006
Alexander Musman64d33f12014-06-04 07:53:32 +00008007template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008008OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008009TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *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 CXXScopeSpec ReductionIdScopeSpec;
8019 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8020
8021 DeclarationNameInfo NameInfo = C->getNameInfo();
8022 if (NameInfo.getName()) {
8023 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8024 if (!NameInfo.getName())
8025 return nullptr;
8026 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008027 // Build a list of all UDR decls with the same names ranged by the Scopes.
8028 // The Scope boundary is a duplication of the previous decl.
8029 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8030 for (auto *E : C->reduction_ops()) {
8031 // Transform all the decls.
8032 if (E) {
8033 auto *ULE = cast<UnresolvedLookupExpr>(E);
8034 UnresolvedSet<8> Decls;
8035 for (auto *D : ULE->decls()) {
8036 NamedDecl *InstD =
8037 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8038 Decls.addDecl(InstD, InstD->getAccess());
8039 }
8040 UnresolvedReductions.push_back(
8041 UnresolvedLookupExpr::Create(
8042 SemaRef.Context, /*NamingClass=*/nullptr,
8043 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8044 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8045 Decls.begin(), Decls.end()));
8046 } else
8047 UnresolvedReductions.push_back(nullptr);
8048 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008049 return getDerived().RebuildOMPReductionClause(
8050 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008051 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008052}
8053
8054template <typename Derived>
8055OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008056TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8057 llvm::SmallVector<Expr *, 16> Vars;
8058 Vars.reserve(C->varlist_size());
8059 for (auto *VE : C->varlists()) {
8060 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8061 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008062 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008063 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008064 }
8065 ExprResult Step = getDerived().TransformExpr(C->getStep());
8066 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008067 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008068 return getDerived().RebuildOMPLinearClause(
8069 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8070 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008071}
8072
Alexander Musman64d33f12014-06-04 07:53:32 +00008073template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008074OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008075TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8076 llvm::SmallVector<Expr *, 16> Vars;
8077 Vars.reserve(C->varlist_size());
8078 for (auto *VE : C->varlists()) {
8079 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8080 if (EVar.isInvalid())
8081 return nullptr;
8082 Vars.push_back(EVar.get());
8083 }
8084 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8085 if (Alignment.isInvalid())
8086 return nullptr;
8087 return getDerived().RebuildOMPAlignedClause(
8088 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8089 C->getColonLoc(), C->getLocEnd());
8090}
8091
Alexander Musman64d33f12014-06-04 07:53:32 +00008092template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008093OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008094TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8095 llvm::SmallVector<Expr *, 16> Vars;
8096 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008097 for (auto *VE : C->varlists()) {
8098 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008099 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008100 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008101 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008102 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008103 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8104 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008105}
8106
Alexey Bataevbae9a792014-06-27 10:37:06 +00008107template <typename Derived>
8108OMPClause *
8109TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8110 llvm::SmallVector<Expr *, 16> Vars;
8111 Vars.reserve(C->varlist_size());
8112 for (auto *VE : C->varlists()) {
8113 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8114 if (EVar.isInvalid())
8115 return nullptr;
8116 Vars.push_back(EVar.get());
8117 }
8118 return getDerived().RebuildOMPCopyprivateClause(
8119 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8120}
8121
Alexey Bataev6125da92014-07-21 11:26:11 +00008122template <typename Derived>
8123OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8124 llvm::SmallVector<Expr *, 16> Vars;
8125 Vars.reserve(C->varlist_size());
8126 for (auto *VE : C->varlists()) {
8127 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8128 if (EVar.isInvalid())
8129 return nullptr;
8130 Vars.push_back(EVar.get());
8131 }
8132 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8133 C->getLParenLoc(), C->getLocEnd());
8134}
8135
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008136template <typename Derived>
8137OMPClause *
8138TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8139 llvm::SmallVector<Expr *, 16> Vars;
8140 Vars.reserve(C->varlist_size());
8141 for (auto *VE : C->varlists()) {
8142 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8143 if (EVar.isInvalid())
8144 return nullptr;
8145 Vars.push_back(EVar.get());
8146 }
8147 return getDerived().RebuildOMPDependClause(
8148 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8149 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8150}
8151
Michael Wonge710d542015-08-07 16:16:36 +00008152template <typename Derived>
8153OMPClause *
8154TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8155 ExprResult E = getDerived().TransformExpr(C->getDevice());
8156 if (E.isInvalid())
8157 return nullptr;
8158 return getDerived().RebuildOMPDeviceClause(
8159 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8160}
8161
Kelvin Li0bff7af2015-11-23 05:32:03 +00008162template <typename Derived>
8163OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8164 llvm::SmallVector<Expr *, 16> Vars;
8165 Vars.reserve(C->varlist_size());
8166 for (auto *VE : C->varlists()) {
8167 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8168 if (EVar.isInvalid())
8169 return nullptr;
8170 Vars.push_back(EVar.get());
8171 }
8172 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008173 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8174 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8175 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008176}
8177
Kelvin Li099bb8c2015-11-24 20:50:12 +00008178template <typename Derived>
8179OMPClause *
8180TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8181 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8182 if (E.isInvalid())
8183 return nullptr;
8184 return getDerived().RebuildOMPNumTeamsClause(
8185 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8186}
8187
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008188template <typename Derived>
8189OMPClause *
8190TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8191 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8192 if (E.isInvalid())
8193 return nullptr;
8194 return getDerived().RebuildOMPThreadLimitClause(
8195 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8196}
8197
Alexey Bataeva0569352015-12-01 10:17:31 +00008198template <typename Derived>
8199OMPClause *
8200TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8201 ExprResult E = getDerived().TransformExpr(C->getPriority());
8202 if (E.isInvalid())
8203 return nullptr;
8204 return getDerived().RebuildOMPPriorityClause(
8205 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8206}
8207
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008208template <typename Derived>
8209OMPClause *
8210TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8211 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8212 if (E.isInvalid())
8213 return nullptr;
8214 return getDerived().RebuildOMPGrainsizeClause(
8215 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8216}
8217
Alexey Bataev382967a2015-12-08 12:06:20 +00008218template <typename Derived>
8219OMPClause *
8220TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8221 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8222 if (E.isInvalid())
8223 return nullptr;
8224 return getDerived().RebuildOMPNumTasksClause(
8225 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8226}
8227
Alexey Bataev28c75412015-12-15 08:19:24 +00008228template <typename Derived>
8229OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8230 ExprResult E = getDerived().TransformExpr(C->getHint());
8231 if (E.isInvalid())
8232 return nullptr;
8233 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8234 C->getLParenLoc(), C->getLocEnd());
8235}
8236
Carlo Bertollib4adf552016-01-15 18:50:31 +00008237template <typename Derived>
8238OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8239 OMPDistScheduleClause *C) {
8240 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8241 if (E.isInvalid())
8242 return nullptr;
8243 return getDerived().RebuildOMPDistScheduleClause(
8244 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8245 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8246}
8247
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008248template <typename Derived>
8249OMPClause *
8250TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8251 return C;
8252}
8253
Samuel Antao661c0902016-05-26 17:39:58 +00008254template <typename Derived>
8255OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8256 llvm::SmallVector<Expr *, 16> Vars;
8257 Vars.reserve(C->varlist_size());
8258 for (auto *VE : C->varlists()) {
8259 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8260 if (EVar.isInvalid())
8261 return 0;
8262 Vars.push_back(EVar.get());
8263 }
8264 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8265 C->getLParenLoc(), C->getLocEnd());
8266}
8267
Samuel Antaoec172c62016-05-26 17:49:04 +00008268template <typename Derived>
8269OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8270 llvm::SmallVector<Expr *, 16> Vars;
8271 Vars.reserve(C->varlist_size());
8272 for (auto *VE : C->varlists()) {
8273 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8274 if (EVar.isInvalid())
8275 return 0;
8276 Vars.push_back(EVar.get());
8277 }
8278 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8279 C->getLParenLoc(), C->getLocEnd());
8280}
8281
Carlo Bertolli2404b172016-07-13 15:37:16 +00008282template <typename Derived>
8283OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8284 OMPUseDevicePtrClause *C) {
8285 llvm::SmallVector<Expr *, 16> Vars;
8286 Vars.reserve(C->varlist_size());
8287 for (auto *VE : C->varlists()) {
8288 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8289 if (EVar.isInvalid())
8290 return nullptr;
8291 Vars.push_back(EVar.get());
8292 }
8293 return getDerived().RebuildOMPUseDevicePtrClause(
8294 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8295}
8296
Carlo Bertolli70594e92016-07-13 17:16:49 +00008297template <typename Derived>
8298OMPClause *
8299TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8300 llvm::SmallVector<Expr *, 16> Vars;
8301 Vars.reserve(C->varlist_size());
8302 for (auto *VE : C->varlists()) {
8303 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8304 if (EVar.isInvalid())
8305 return nullptr;
8306 Vars.push_back(EVar.get());
8307 }
8308 return getDerived().RebuildOMPIsDevicePtrClause(
8309 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8310}
8311
Douglas Gregorebe10102009-08-20 07:17:43 +00008312//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008313// Expression transformation
8314//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008317TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008318 if (!E->isTypeDependent())
8319 return E;
8320
8321 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8322 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008323}
Mike Stump11289f42009-09-09 15:08:12 +00008324
8325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008326ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008327TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008328 NestedNameSpecifierLoc QualifierLoc;
8329 if (E->getQualifierLoc()) {
8330 QualifierLoc
8331 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8332 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008333 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008334 }
John McCallce546572009-12-08 09:08:17 +00008335
8336 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008337 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8338 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008339 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008341
John McCall815039a2010-08-17 21:27:17 +00008342 DeclarationNameInfo NameInfo = E->getNameInfo();
8343 if (NameInfo.getName()) {
8344 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8345 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008346 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008347 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008348
8349 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008350 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008351 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008352 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008353 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008354
8355 // Mark it referenced in the new context regardless.
8356 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008357 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008358
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008359 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008360 }
John McCallce546572009-12-08 09:08:17 +00008361
Craig Topperc3ec1492014-05-26 06:22:03 +00008362 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008363 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008364 TemplateArgs = &TransArgs;
8365 TransArgs.setLAngleLoc(E->getLAngleLoc());
8366 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008367 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8368 E->getNumTemplateArgs(),
8369 TransArgs))
8370 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008371 }
8372
Chad Rosier1dcde962012-08-08 18:46:20 +00008373 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008374 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008375}
Mike Stump11289f42009-09-09 15:08:12 +00008376
Douglas Gregora16548e2009-08-11 05:31:07 +00008377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008378ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008379TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008380 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008381}
Mike Stump11289f42009-09-09 15:08:12 +00008382
Douglas Gregora16548e2009-08-11 05:31:07 +00008383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008385TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008386 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008387}
Mike Stump11289f42009-09-09 15:08:12 +00008388
Douglas Gregora16548e2009-08-11 05:31:07 +00008389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008390ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008391TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008392 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008393}
Mike Stump11289f42009-09-09 15:08:12 +00008394
Douglas Gregora16548e2009-08-11 05:31:07 +00008395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008397TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008398 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008399}
Mike Stump11289f42009-09-09 15:08:12 +00008400
Douglas Gregora16548e2009-08-11 05:31:07 +00008401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008402ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008403TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008404 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008405}
8406
8407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008408ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008409TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008410 if (FunctionDecl *FD = E->getDirectCallee())
8411 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008412 return SemaRef.MaybeBindToTemporary(E);
8413}
8414
8415template<typename Derived>
8416ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008417TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8418 ExprResult ControllingExpr =
8419 getDerived().TransformExpr(E->getControllingExpr());
8420 if (ControllingExpr.isInvalid())
8421 return ExprError();
8422
Chris Lattner01cf8db2011-07-20 06:58:45 +00008423 SmallVector<Expr *, 4> AssocExprs;
8424 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008425 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8426 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8427 if (TS) {
8428 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8429 if (!AssocType)
8430 return ExprError();
8431 AssocTypes.push_back(AssocType);
8432 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008433 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008434 }
8435
8436 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8437 if (AssocExpr.isInvalid())
8438 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008439 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008440 }
8441
8442 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8443 E->getDefaultLoc(),
8444 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008445 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008446 AssocTypes,
8447 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008448}
8449
8450template<typename Derived>
8451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008452TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008453 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008454 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008456
Douglas Gregora16548e2009-08-11 05:31:07 +00008457 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008458 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008459
John McCallb268a282010-08-23 23:25:46 +00008460 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008461 E->getRParen());
8462}
8463
Richard Smithdb2630f2012-10-21 03:28:35 +00008464/// \brief The operand of a unary address-of operator has special rules: it's
8465/// allowed to refer to a non-static member of a class even if there's no 'this'
8466/// object available.
8467template<typename Derived>
8468ExprResult
8469TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8470 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008471 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008472 else
8473 return getDerived().TransformExpr(E);
8474}
8475
Mike Stump11289f42009-09-09 15:08:12 +00008476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008478TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008479 ExprResult SubExpr;
8480 if (E->getOpcode() == UO_AddrOf)
8481 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8482 else
8483 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008484 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008485 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008486
Douglas Gregora16548e2009-08-11 05:31:07 +00008487 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008488 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008489
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8491 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008492 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008493}
Mike Stump11289f42009-09-09 15:08:12 +00008494
Douglas Gregora16548e2009-08-11 05:31:07 +00008495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008496ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008497TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8498 // Transform the type.
8499 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8500 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008501 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008502
Douglas Gregor882211c2010-04-28 22:16:22 +00008503 // Transform all of the components into components similar to what the
8504 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008505 // FIXME: It would be slightly more efficient in the non-dependent case to
8506 // just map FieldDecls, rather than requiring the rebuilder to look for
8507 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008508 // template code that we don't care.
8509 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008510 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008511 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008512 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008513 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008514 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008515 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008516 Comp.LocStart = ON.getSourceRange().getBegin();
8517 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008518 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008519 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008520 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008521 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008522 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008523 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008524
Douglas Gregor882211c2010-04-28 22:16:22 +00008525 ExprChanged = ExprChanged || Index.get() != FromIndex;
8526 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008527 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008528 break;
8529 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008530
James Y Knight7281c352015-12-29 22:31:18 +00008531 case OffsetOfNode::Field:
8532 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008533 Comp.isBrackets = false;
8534 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008535 if (!Comp.U.IdentInfo)
8536 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008537
Douglas Gregor882211c2010-04-28 22:16:22 +00008538 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008539
James Y Knight7281c352015-12-29 22:31:18 +00008540 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008541 // Will be recomputed during the rebuild.
8542 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008544
Douglas Gregor882211c2010-04-28 22:16:22 +00008545 Components.push_back(Comp);
8546 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008547
Douglas Gregor882211c2010-04-28 22:16:22 +00008548 // If nothing changed, retain the existing expression.
8549 if (!getDerived().AlwaysRebuild() &&
8550 Type == E->getTypeSourceInfo() &&
8551 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008552 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008553
Douglas Gregor882211c2010-04-28 22:16:22 +00008554 // Build a new offsetof expression.
8555 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008556 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008557}
8558
8559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008560ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008561TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008562 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008563 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008564 return E;
John McCall8d69a212010-11-15 23:31:06 +00008565}
8566
8567template<typename Derived>
8568ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008569TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8570 return E;
8571}
8572
8573template<typename Derived>
8574ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008575TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008576 // Rebuild the syntactic form. The original syntactic form has
8577 // opaque-value expressions in it, so strip those away and rebuild
8578 // the result. This is a really awful way of doing this, but the
8579 // better solution (rebuilding the semantic expressions and
8580 // rebinding OVEs as necessary) doesn't work; we'd need
8581 // TreeTransform to not strip away implicit conversions.
8582 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8583 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008584 if (result.isInvalid()) return ExprError();
8585
8586 // If that gives us a pseudo-object result back, the pseudo-object
8587 // expression must have been an lvalue-to-rvalue conversion which we
8588 // should reapply.
8589 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008590 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008591
8592 return result;
8593}
8594
8595template<typename Derived>
8596ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008597TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8598 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008599 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008600 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008601
John McCallbcd03502009-12-07 02:54:59 +00008602 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008603 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008605
John McCall4c98fd82009-11-04 07:28:41 +00008606 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008607 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008608
Peter Collingbournee190dee2011-03-11 19:24:49 +00008609 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8610 E->getKind(),
8611 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008612 }
Mike Stump11289f42009-09-09 15:08:12 +00008613
Eli Friedmane4f22df2012-02-29 04:03:55 +00008614 // C++0x [expr.sizeof]p1:
8615 // The operand is either an expression, which is an unevaluated operand
8616 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008617 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8618 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008619
Reid Kleckner32506ed2014-06-12 23:03:48 +00008620 // Try to recover if we have something like sizeof(T::X) where X is a type.
8621 // Notably, there must be *exactly* one set of parens if X is a type.
8622 TypeSourceInfo *RecoveryTSI = nullptr;
8623 ExprResult SubExpr;
8624 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8625 if (auto *DRE =
8626 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8627 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8628 PE, DRE, false, &RecoveryTSI);
8629 else
8630 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8631
8632 if (RecoveryTSI) {
8633 return getDerived().RebuildUnaryExprOrTypeTrait(
8634 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8635 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008637
Eli Friedmane4f22df2012-02-29 04:03:55 +00008638 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008639 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008640
Peter Collingbournee190dee2011-03-11 19:24:49 +00008641 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8642 E->getOperatorLoc(),
8643 E->getKind(),
8644 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008645}
Mike Stump11289f42009-09-09 15:08:12 +00008646
Douglas Gregora16548e2009-08-11 05:31:07 +00008647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008648ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008649TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008650 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008651 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008652 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008653
John McCalldadc5752010-08-24 06:29:42 +00008654 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008655 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008657
8658
Douglas Gregora16548e2009-08-11 05:31:07 +00008659 if (!getDerived().AlwaysRebuild() &&
8660 LHS.get() == E->getLHS() &&
8661 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008662 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008663
John McCallb268a282010-08-23 23:25:46 +00008664 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008665 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008666 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008667 E->getRBracketLoc());
8668}
Mike Stump11289f42009-09-09 15:08:12 +00008669
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008670template <typename Derived>
8671ExprResult
8672TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8673 ExprResult Base = getDerived().TransformExpr(E->getBase());
8674 if (Base.isInvalid())
8675 return ExprError();
8676
8677 ExprResult LowerBound;
8678 if (E->getLowerBound()) {
8679 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8680 if (LowerBound.isInvalid())
8681 return ExprError();
8682 }
8683
8684 ExprResult Length;
8685 if (E->getLength()) {
8686 Length = getDerived().TransformExpr(E->getLength());
8687 if (Length.isInvalid())
8688 return ExprError();
8689 }
8690
8691 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8692 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8693 return E;
8694
8695 return getDerived().RebuildOMPArraySectionExpr(
8696 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8697 Length.get(), E->getRBracketLoc());
8698}
8699
Mike Stump11289f42009-09-09 15:08:12 +00008700template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008701ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008702TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008703 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008704 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008705 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008706 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008707
8708 // Transform arguments.
8709 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008710 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008711 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008712 &ArgChanged))
8713 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008714
Douglas Gregora16548e2009-08-11 05:31:07 +00008715 if (!getDerived().AlwaysRebuild() &&
8716 Callee.get() == E->getCallee() &&
8717 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008718 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008719
Douglas Gregora16548e2009-08-11 05:31:07 +00008720 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008721 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008722 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008723 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008724 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008725 E->getRParenLoc());
8726}
Mike Stump11289f42009-09-09 15:08:12 +00008727
8728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008730TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008731 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008732 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008734
Douglas Gregorea972d32011-02-28 21:54:11 +00008735 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008736 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008737 QualifierLoc
8738 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008739
Douglas Gregorea972d32011-02-28 21:54:11 +00008740 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008741 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008742 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008743 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008744
Eli Friedman2cfcef62009-12-04 06:40:45 +00008745 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008746 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8747 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008748 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008750
John McCall16df1e52010-03-30 21:47:33 +00008751 NamedDecl *FoundDecl = E->getFoundDecl();
8752 if (FoundDecl == E->getMemberDecl()) {
8753 FoundDecl = Member;
8754 } else {
8755 FoundDecl = cast_or_null<NamedDecl>(
8756 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8757 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008758 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008759 }
8760
Douglas Gregora16548e2009-08-11 05:31:07 +00008761 if (!getDerived().AlwaysRebuild() &&
8762 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008763 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008764 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008765 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008766 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008767
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008768 // Mark it referenced in the new context regardless.
8769 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008770 SemaRef.MarkMemberReferenced(E);
8771
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008772 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008773 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008774
John McCall6b51f282009-11-23 01:53:49 +00008775 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008776 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008777 TransArgs.setLAngleLoc(E->getLAngleLoc());
8778 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008779 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8780 E->getNumTemplateArgs(),
8781 TransArgs))
8782 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008783 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008784
Douglas Gregora16548e2009-08-11 05:31:07 +00008785 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008786 SourceLocation FakeOperatorLoc =
8787 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008788
John McCall38836f02010-01-15 08:34:02 +00008789 // FIXME: to do this check properly, we will need to preserve the
8790 // first-qualifier-in-scope here, just in case we had a dependent
8791 // base (and therefore couldn't do the check) and a
8792 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008793 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008794
John McCallb268a282010-08-23 23:25:46 +00008795 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008796 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008797 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008798 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008799 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008800 Member,
John McCall16df1e52010-03-30 21:47:33 +00008801 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008802 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008803 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008804 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008805}
Mike Stump11289f42009-09-09 15:08:12 +00008806
Douglas Gregora16548e2009-08-11 05:31:07 +00008807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008808ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008809TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008810 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008811 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008813
John McCalldadc5752010-08-24 06:29:42 +00008814 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008817
Douglas Gregora16548e2009-08-11 05:31:07 +00008818 if (!getDerived().AlwaysRebuild() &&
8819 LHS.get() == E->getLHS() &&
8820 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008821 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008822
Lang Hames5de91cc2012-10-02 04:45:10 +00008823 Sema::FPContractStateRAII FPContractState(getSema());
8824 getSema().FPFeatures.fp_contract = E->isFPContractable();
8825
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008827 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008828}
8829
Mike Stump11289f42009-09-09 15:08:12 +00008830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008831ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008832TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008833 CompoundAssignOperator *E) {
8834 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008835}
Mike Stump11289f42009-09-09 15:08:12 +00008836
Douglas Gregora16548e2009-08-11 05:31:07 +00008837template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008838ExprResult TreeTransform<Derived>::
8839TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8840 // Just rebuild the common and RHS expressions and see whether we
8841 // get any changes.
8842
8843 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8844 if (commonExpr.isInvalid())
8845 return ExprError();
8846
8847 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8848 if (rhs.isInvalid())
8849 return ExprError();
8850
8851 if (!getDerived().AlwaysRebuild() &&
8852 commonExpr.get() == e->getCommon() &&
8853 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008854 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008855
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008856 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008857 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008858 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008859 e->getColonLoc(),
8860 rhs.get());
8861}
8862
8863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008865TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008866 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008867 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008869
John McCalldadc5752010-08-24 06:29:42 +00008870 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008871 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008873
John McCalldadc5752010-08-24 06:29:42 +00008874 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008875 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008877
Douglas Gregora16548e2009-08-11 05:31:07 +00008878 if (!getDerived().AlwaysRebuild() &&
8879 Cond.get() == E->getCond() &&
8880 LHS.get() == E->getLHS() &&
8881 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008882 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008883
John McCallb268a282010-08-23 23:25:46 +00008884 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008885 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008886 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008887 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008888 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008889}
Mike Stump11289f42009-09-09 15:08:12 +00008890
8891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008893TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008894 // Implicit casts are eliminated during transformation, since they
8895 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008896 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008897}
Mike Stump11289f42009-09-09 15:08:12 +00008898
Douglas Gregora16548e2009-08-11 05:31:07 +00008899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008900ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008901TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008902 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8903 if (!Type)
8904 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008905
John McCalldadc5752010-08-24 06:29:42 +00008906 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008907 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008908 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008910
Douglas Gregora16548e2009-08-11 05:31:07 +00008911 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008912 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008913 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008914 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008915
John McCall97513962010-01-15 18:39:57 +00008916 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008917 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008918 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008919 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008920}
Mike Stump11289f42009-09-09 15:08:12 +00008921
Douglas Gregora16548e2009-08-11 05:31:07 +00008922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008923ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008924TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008925 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8926 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8927 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008928 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008929
John McCalldadc5752010-08-24 06:29:42 +00008930 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008931 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008932 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008933
Douglas Gregora16548e2009-08-11 05:31:07 +00008934 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008935 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008936 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008937 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008938
John McCall5d7aa7f2010-01-19 22:33:45 +00008939 // Note: the expression type doesn't necessarily match the
8940 // type-as-written, but that's okay, because it should always be
8941 // derivable from the initializer.
8942
John McCalle15bbff2010-01-18 19:35:47 +00008943 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008944 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008945 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008946}
Mike Stump11289f42009-09-09 15:08:12 +00008947
Douglas Gregora16548e2009-08-11 05:31:07 +00008948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008950TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008951 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008952 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008953 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008954
Douglas Gregora16548e2009-08-11 05:31:07 +00008955 if (!getDerived().AlwaysRebuild() &&
8956 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008957 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008958
Douglas Gregora16548e2009-08-11 05:31:07 +00008959 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008960 SourceLocation FakeOperatorLoc =
8961 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008962 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008963 E->getAccessorLoc(),
8964 E->getAccessor());
8965}
Mike Stump11289f42009-09-09 15:08:12 +00008966
Douglas Gregora16548e2009-08-11 05:31:07 +00008967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008968ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008969TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008970 if (InitListExpr *Syntactic = E->getSyntacticForm())
8971 E = Syntactic;
8972
Douglas Gregora16548e2009-08-11 05:31:07 +00008973 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008974
Benjamin Kramerf0623432012-08-23 22:51:59 +00008975 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008976 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008977 Inits, &InitChanged))
8978 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008979
Richard Smith520449d2015-02-05 06:15:50 +00008980 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8981 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8982 // in some cases. We can't reuse it in general, because the syntactic and
8983 // semantic forms are linked, and we can't know that semantic form will
8984 // match even if the syntactic form does.
8985 }
Mike Stump11289f42009-09-09 15:08:12 +00008986
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008987 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008988 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008989}
Mike Stump11289f42009-09-09 15:08:12 +00008990
Douglas Gregora16548e2009-08-11 05:31:07 +00008991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008993TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008994 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008995
Douglas Gregorebe10102009-08-20 07:17:43 +00008996 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008997 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008998 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008999 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009000
Douglas Gregorebe10102009-08-20 07:17:43 +00009001 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009002 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009003 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009004 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9005 if (D.isFieldDesignator()) {
9006 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9007 D.getDotLoc(),
9008 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009009 if (D.getField()) {
9010 FieldDecl *Field = cast_or_null<FieldDecl>(
9011 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9012 if (Field != D.getField())
9013 // Rebuild the expression when the transformed FieldDecl is
9014 // different to the already assigned FieldDecl.
9015 ExprChanged = true;
9016 } else {
9017 // Ensure that the designator expression is rebuilt when there isn't
9018 // a resolved FieldDecl in the designator as we don't want to assign
9019 // a FieldDecl to a pattern designator that will be instantiated again.
9020 ExprChanged = true;
9021 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009022 continue;
9023 }
Mike Stump11289f42009-09-09 15:08:12 +00009024
David Majnemerf7e36092016-06-23 00:15:04 +00009025 if (D.isArrayDesignator()) {
9026 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009027 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009028 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009029
David Majnemerf7e36092016-06-23 00:15:04 +00009030 Desig.AddDesignator(
9031 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009032
David Majnemerf7e36092016-06-23 00:15:04 +00009033 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009034 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009035 continue;
9036 }
Mike Stump11289f42009-09-09 15:08:12 +00009037
David Majnemerf7e36092016-06-23 00:15:04 +00009038 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009039 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009040 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009041 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009043
David Majnemerf7e36092016-06-23 00:15:04 +00009044 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009045 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009047
9048 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009049 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009050 D.getLBracketLoc(),
9051 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009052
David Majnemerf7e36092016-06-23 00:15:04 +00009053 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9054 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009055
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009056 ArrayExprs.push_back(Start.get());
9057 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009058 }
Mike Stump11289f42009-09-09 15:08:12 +00009059
Douglas Gregora16548e2009-08-11 05:31:07 +00009060 if (!getDerived().AlwaysRebuild() &&
9061 Init.get() == E->getInit() &&
9062 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009063 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009064
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009065 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009066 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009067 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009068}
Mike Stump11289f42009-09-09 15:08:12 +00009069
Yunzhong Gaocb779302015-06-10 00:27:52 +00009070// Seems that if TransformInitListExpr() only works on the syntactic form of an
9071// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9072template<typename Derived>
9073ExprResult
9074TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9075 DesignatedInitUpdateExpr *E) {
9076 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9077 "initializer");
9078 return ExprError();
9079}
9080
9081template<typename Derived>
9082ExprResult
9083TreeTransform<Derived>::TransformNoInitExpr(
9084 NoInitExpr *E) {
9085 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9086 return ExprError();
9087}
9088
Douglas Gregora16548e2009-08-11 05:31:07 +00009089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009090ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009091TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9092 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9093 return ExprError();
9094}
9095
9096template<typename Derived>
9097ExprResult
9098TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9099 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9100 return ExprError();
9101}
9102
9103template<typename Derived>
9104ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009105TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009106 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009107 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009108
Douglas Gregor3da3c062009-10-28 00:29:27 +00009109 // FIXME: Will we ever have proper type location here? Will we actually
9110 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009111 QualType T = getDerived().TransformType(E->getType());
9112 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009114
Douglas Gregora16548e2009-08-11 05:31:07 +00009115 if (!getDerived().AlwaysRebuild() &&
9116 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009117 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009118
Douglas Gregora16548e2009-08-11 05:31:07 +00009119 return getDerived().RebuildImplicitValueInitExpr(T);
9120}
Mike Stump11289f42009-09-09 15:08:12 +00009121
Douglas Gregora16548e2009-08-11 05:31:07 +00009122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009124TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009125 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9126 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009128
John McCalldadc5752010-08-24 06:29:42 +00009129 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009130 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009132
Douglas Gregora16548e2009-08-11 05:31:07 +00009133 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009134 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009135 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009136 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009137
John McCallb268a282010-08-23 23:25:46 +00009138 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009139 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009140}
9141
9142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009144TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009145 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009146 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009147 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9148 &ArgumentChanged))
9149 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009150
Douglas Gregora16548e2009-08-11 05:31:07 +00009151 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009152 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009153 E->getRParenLoc());
9154}
Mike Stump11289f42009-09-09 15:08:12 +00009155
Douglas Gregora16548e2009-08-11 05:31:07 +00009156/// \brief Transform an address-of-label expression.
9157///
9158/// By default, the transformation of an address-of-label expression always
9159/// rebuilds the expression, so that the label identifier can be resolved to
9160/// the corresponding label statement by semantic analysis.
9161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009163TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009164 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9165 E->getLabel());
9166 if (!LD)
9167 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009168
Douglas Gregora16548e2009-08-11 05:31:07 +00009169 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009170 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009171}
Mike Stump11289f42009-09-09 15:08:12 +00009172
9173template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009174ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009175TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009176 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009177 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009178 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009179 if (SubStmt.isInvalid()) {
9180 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009181 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009182 }
Mike Stump11289f42009-09-09 15:08:12 +00009183
Douglas Gregora16548e2009-08-11 05:31:07 +00009184 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009185 SubStmt.get() == E->getSubStmt()) {
9186 // Calling this an 'error' is unintuitive, but it does the right thing.
9187 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009188 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009189 }
Mike Stump11289f42009-09-09 15:08:12 +00009190
9191 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009192 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009193 E->getRParenLoc());
9194}
Mike Stump11289f42009-09-09 15:08:12 +00009195
Douglas Gregora16548e2009-08-11 05:31:07 +00009196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009198TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009199 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009200 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009202
John McCalldadc5752010-08-24 06:29:42 +00009203 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009204 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009206
John McCalldadc5752010-08-24 06:29:42 +00009207 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009208 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009210
Douglas Gregora16548e2009-08-11 05:31:07 +00009211 if (!getDerived().AlwaysRebuild() &&
9212 Cond.get() == E->getCond() &&
9213 LHS.get() == E->getLHS() &&
9214 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009215 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009216
Douglas Gregora16548e2009-08-11 05:31:07 +00009217 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009218 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009219 E->getRParenLoc());
9220}
Mike Stump11289f42009-09-09 15:08:12 +00009221
Douglas Gregora16548e2009-08-11 05:31:07 +00009222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009224TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009225 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009226}
9227
9228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009230TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009231 switch (E->getOperator()) {
9232 case OO_New:
9233 case OO_Delete:
9234 case OO_Array_New:
9235 case OO_Array_Delete:
9236 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009237
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009238 case OO_Call: {
9239 // This is a call to an object's operator().
9240 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9241
9242 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009243 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009244 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009245 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009246
9247 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009248 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9249 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009250
9251 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009252 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009253 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009254 Args))
9255 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009256
John McCallb268a282010-08-23 23:25:46 +00009257 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009258 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009259 E->getLocEnd());
9260 }
9261
9262#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9263 case OO_##Name:
9264#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9265#include "clang/Basic/OperatorKinds.def"
9266 case OO_Subscript:
9267 // Handled below.
9268 break;
9269
9270 case OO_Conditional:
9271 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009272
9273 case OO_None:
9274 case NUM_OVERLOADED_OPERATORS:
9275 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009276 }
9277
John McCalldadc5752010-08-24 06:29:42 +00009278 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009279 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009281
Richard Smithdb2630f2012-10-21 03:28:35 +00009282 ExprResult First;
9283 if (E->getOperator() == OO_Amp)
9284 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9285 else
9286 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009287 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009288 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009289
John McCalldadc5752010-08-24 06:29:42 +00009290 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009291 if (E->getNumArgs() == 2) {
9292 Second = getDerived().TransformExpr(E->getArg(1));
9293 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009294 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009295 }
Mike Stump11289f42009-09-09 15:08:12 +00009296
Douglas Gregora16548e2009-08-11 05:31:07 +00009297 if (!getDerived().AlwaysRebuild() &&
9298 Callee.get() == E->getCallee() &&
9299 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009300 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009301 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009302
Lang Hames5de91cc2012-10-02 04:45:10 +00009303 Sema::FPContractStateRAII FPContractState(getSema());
9304 getSema().FPFeatures.fp_contract = E->isFPContractable();
9305
Douglas Gregora16548e2009-08-11 05:31:07 +00009306 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9307 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009308 Callee.get(),
9309 First.get(),
9310 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009311}
Mike Stump11289f42009-09-09 15:08:12 +00009312
Douglas Gregora16548e2009-08-11 05:31:07 +00009313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009314ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009315TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9316 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009317}
Mike Stump11289f42009-09-09 15:08:12 +00009318
Douglas Gregora16548e2009-08-11 05:31:07 +00009319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009320ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009321TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9322 // Transform the callee.
9323 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9324 if (Callee.isInvalid())
9325 return ExprError();
9326
9327 // Transform exec config.
9328 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9329 if (EC.isInvalid())
9330 return ExprError();
9331
9332 // Transform arguments.
9333 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009334 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009335 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009336 &ArgChanged))
9337 return ExprError();
9338
9339 if (!getDerived().AlwaysRebuild() &&
9340 Callee.get() == E->getCallee() &&
9341 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009342 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009343
9344 // FIXME: Wrong source location information for the '('.
9345 SourceLocation FakeLParenLoc
9346 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9347 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009348 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009349 E->getRParenLoc(), EC.get());
9350}
9351
9352template<typename Derived>
9353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009354TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009355 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9356 if (!Type)
9357 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009358
John McCalldadc5752010-08-24 06:29:42 +00009359 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009360 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009361 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009363
Douglas Gregora16548e2009-08-11 05:31:07 +00009364 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009365 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009366 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009367 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009368 return getDerived().RebuildCXXNamedCastExpr(
9369 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9370 Type, E->getAngleBrackets().getEnd(),
9371 // FIXME. this should be '(' location
9372 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009373}
Mike Stump11289f42009-09-09 15:08:12 +00009374
Douglas Gregora16548e2009-08-11 05:31:07 +00009375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009377TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9378 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009379}
Mike Stump11289f42009-09-09 15:08:12 +00009380
9381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009383TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9384 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009385}
9386
Douglas Gregora16548e2009-08-11 05:31:07 +00009387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009388ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009389TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009390 CXXReinterpretCastExpr *E) {
9391 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009392}
Mike Stump11289f42009-09-09 15:08:12 +00009393
Douglas Gregora16548e2009-08-11 05:31:07 +00009394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009396TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9397 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009398}
Mike Stump11289f42009-09-09 15:08:12 +00009399
Douglas Gregora16548e2009-08-11 05:31:07 +00009400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009401ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009402TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009403 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009404 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9405 if (!Type)
9406 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009407
John McCalldadc5752010-08-24 06:29:42 +00009408 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009409 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009410 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009412
Douglas Gregora16548e2009-08-11 05:31:07 +00009413 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009414 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009415 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009416 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009417
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009418 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009419 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009420 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009421 E->getRParenLoc());
9422}
Mike Stump11289f42009-09-09 15:08:12 +00009423
Douglas Gregora16548e2009-08-11 05:31:07 +00009424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009426TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009427 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009428 TypeSourceInfo *TInfo
9429 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9430 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009432
Douglas Gregora16548e2009-08-11 05:31:07 +00009433 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009434 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009435 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009436
Douglas Gregor9da64192010-04-26 22:37:10 +00009437 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9438 E->getLocStart(),
9439 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009440 E->getLocEnd());
9441 }
Mike Stump11289f42009-09-09 15:08:12 +00009442
Eli Friedman456f0182012-01-20 01:26:23 +00009443 // We don't know whether the subexpression is potentially evaluated until
9444 // after we perform semantic analysis. We speculatively assume it is
9445 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009446 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009447 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9448 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009449
John McCalldadc5752010-08-24 06:29:42 +00009450 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009451 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009453
Douglas Gregora16548e2009-08-11 05:31:07 +00009454 if (!getDerived().AlwaysRebuild() &&
9455 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009456 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009457
Douglas Gregor9da64192010-04-26 22:37:10 +00009458 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9459 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009460 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009461 E->getLocEnd());
9462}
9463
9464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009465ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009466TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9467 if (E->isTypeOperand()) {
9468 TypeSourceInfo *TInfo
9469 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9470 if (!TInfo)
9471 return ExprError();
9472
9473 if (!getDerived().AlwaysRebuild() &&
9474 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009475 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009476
Douglas Gregor69735112011-03-06 17:40:41 +00009477 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009478 E->getLocStart(),
9479 TInfo,
9480 E->getLocEnd());
9481 }
9482
Francois Pichet9f4f2072010-09-08 12:20:18 +00009483 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9484
9485 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9486 if (SubExpr.isInvalid())
9487 return ExprError();
9488
9489 if (!getDerived().AlwaysRebuild() &&
9490 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009491 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009492
9493 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9494 E->getLocStart(),
9495 SubExpr.get(),
9496 E->getLocEnd());
9497}
9498
9499template<typename Derived>
9500ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009501TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009502 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009503}
Mike Stump11289f42009-09-09 15:08:12 +00009504
Douglas Gregora16548e2009-08-11 05:31:07 +00009505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009506ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009507TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009508 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009509 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009510}
Mike Stump11289f42009-09-09 15:08:12 +00009511
Douglas Gregora16548e2009-08-11 05:31:07 +00009512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009513ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009514TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009515 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009516
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009517 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9518 // Make sure that we capture 'this'.
9519 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009520 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009522
Douglas Gregorb15af892010-01-07 23:12:05 +00009523 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009524}
Mike Stump11289f42009-09-09 15:08:12 +00009525
Douglas Gregora16548e2009-08-11 05:31:07 +00009526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009527ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009528TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009529 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009530 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009532
Douglas Gregora16548e2009-08-11 05:31:07 +00009533 if (!getDerived().AlwaysRebuild() &&
9534 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009535 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009536
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009537 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9538 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009539}
Mike Stump11289f42009-09-09 15:08:12 +00009540
Douglas Gregora16548e2009-08-11 05:31:07 +00009541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009543TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009544 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009545 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9546 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009547 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009549
Chandler Carruth794da4c2010-02-08 06:42:49 +00009550 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009551 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009552 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009553
Douglas Gregor033f6752009-12-23 23:03:06 +00009554 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009555}
Mike Stump11289f42009-09-09 15:08:12 +00009556
Douglas Gregora16548e2009-08-11 05:31:07 +00009557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009558ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009559TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9560 FieldDecl *Field
9561 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9562 E->getField()));
9563 if (!Field)
9564 return ExprError();
9565
9566 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009567 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009568
9569 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9570}
9571
9572template<typename Derived>
9573ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009574TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9575 CXXScalarValueInitExpr *E) {
9576 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9577 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009578 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009579
Douglas Gregora16548e2009-08-11 05:31:07 +00009580 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009581 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009582 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009583
Chad Rosier1dcde962012-08-08 18:46:20 +00009584 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009585 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009586 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009587}
Mike Stump11289f42009-09-09 15:08:12 +00009588
Douglas Gregora16548e2009-08-11 05:31:07 +00009589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009591TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009592 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009593 TypeSourceInfo *AllocTypeInfo
9594 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9595 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009597
Douglas Gregora16548e2009-08-11 05:31:07 +00009598 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009599 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009600 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009601 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009602
Douglas Gregora16548e2009-08-11 05:31:07 +00009603 // Transform the placement arguments (if any).
9604 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009605 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009606 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009607 E->getNumPlacementArgs(), true,
9608 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009609 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009610
Sebastian Redl6047f072012-02-16 12:22:20 +00009611 // Transform the initializer (if any).
9612 Expr *OldInit = E->getInitializer();
9613 ExprResult NewInit;
9614 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009615 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009616 if (NewInit.isInvalid())
9617 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009618
Sebastian Redl6047f072012-02-16 12:22:20 +00009619 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009620 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009621 if (E->getOperatorNew()) {
9622 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009623 getDerived().TransformDecl(E->getLocStart(),
9624 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009625 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009626 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009627 }
9628
Craig Topperc3ec1492014-05-26 06:22:03 +00009629 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009630 if (E->getOperatorDelete()) {
9631 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009632 getDerived().TransformDecl(E->getLocStart(),
9633 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009634 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009635 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009637
Douglas Gregora16548e2009-08-11 05:31:07 +00009638 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009639 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009640 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009641 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009642 OperatorNew == E->getOperatorNew() &&
9643 OperatorDelete == E->getOperatorDelete() &&
9644 !ArgumentChanged) {
9645 // Mark any declarations we need as referenced.
9646 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009647 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009648 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009649 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009650 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009651
Sebastian Redl6047f072012-02-16 12:22:20 +00009652 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009653 QualType ElementType
9654 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9655 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9656 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9657 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009658 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009659 }
9660 }
9661 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009662
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009663 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009664 }
Mike Stump11289f42009-09-09 15:08:12 +00009665
Douglas Gregor0744ef62010-09-07 21:49:58 +00009666 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009667 if (!ArraySize.get()) {
9668 // If no array size was specified, but the new expression was
9669 // instantiated with an array type (e.g., "new T" where T is
9670 // instantiated with "int[4]"), extract the outer bound from the
9671 // array type as our array size. We do this with constant and
9672 // dependently-sized array types.
9673 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9674 if (!ArrayT) {
9675 // Do nothing
9676 } else if (const ConstantArrayType *ConsArrayT
9677 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009678 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9679 SemaRef.Context.getSizeType(),
9680 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009681 AllocType = ConsArrayT->getElementType();
9682 } else if (const DependentSizedArrayType *DepArrayT
9683 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9684 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009685 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009686 AllocType = DepArrayT->getElementType();
9687 }
9688 }
9689 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009690
Douglas Gregora16548e2009-08-11 05:31:07 +00009691 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9692 E->isGlobalNew(),
9693 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009694 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009695 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009696 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009697 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009698 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009699 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009700 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009701 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009702}
Mike Stump11289f42009-09-09 15:08:12 +00009703
Douglas Gregora16548e2009-08-11 05:31:07 +00009704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009706TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009707 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009710
Douglas Gregord2d9da02010-02-26 00:38:10 +00009711 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009712 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009713 if (E->getOperatorDelete()) {
9714 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009715 getDerived().TransformDecl(E->getLocStart(),
9716 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009717 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009718 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009720
Douglas Gregora16548e2009-08-11 05:31:07 +00009721 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009722 Operand.get() == E->getArgument() &&
9723 OperatorDelete == E->getOperatorDelete()) {
9724 // Mark any declarations we need as referenced.
9725 // FIXME: instantiation-specific.
9726 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009727 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009728
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009729 if (!E->getArgument()->isTypeDependent()) {
9730 QualType Destroyed = SemaRef.Context.getBaseElementType(
9731 E->getDestroyedType());
9732 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9733 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009734 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009735 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009736 }
9737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009738
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009739 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009740 }
Mike Stump11289f42009-09-09 15:08:12 +00009741
Douglas Gregora16548e2009-08-11 05:31:07 +00009742 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9743 E->isGlobalDelete(),
9744 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009745 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009746}
Mike Stump11289f42009-09-09 15:08:12 +00009747
Douglas Gregora16548e2009-08-11 05:31:07 +00009748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009749ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009750TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009751 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009752 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009753 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009755
John McCallba7bf592010-08-24 05:47:05 +00009756 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009757 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009758 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009759 E->getOperatorLoc(),
9760 E->isArrow()? tok::arrow : tok::period,
9761 ObjectTypePtr,
9762 MayBePseudoDestructor);
9763 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009765
John McCallba7bf592010-08-24 05:47:05 +00009766 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009767 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9768 if (QualifierLoc) {
9769 QualifierLoc
9770 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9771 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009772 return ExprError();
9773 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009774 CXXScopeSpec SS;
9775 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009776
Douglas Gregor678f90d2010-02-25 01:56:36 +00009777 PseudoDestructorTypeStorage Destroyed;
9778 if (E->getDestroyedTypeInfo()) {
9779 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009780 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009781 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009782 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009783 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009784 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009785 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009786 // We aren't likely to be able to resolve the identifier down to a type
9787 // now anyway, so just retain the identifier.
9788 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9789 E->getDestroyedTypeLoc());
9790 } else {
9791 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009792 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009793 *E->getDestroyedTypeIdentifier(),
9794 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009795 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009796 SS, ObjectTypePtr,
9797 false);
9798 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009799 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009800
Douglas Gregor678f90d2010-02-25 01:56:36 +00009801 Destroyed
9802 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9803 E->getDestroyedTypeLoc());
9804 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009805
Craig Topperc3ec1492014-05-26 06:22:03 +00009806 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009807 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009808 CXXScopeSpec EmptySS;
9809 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009810 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009811 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009812 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009814
John McCallb268a282010-08-23 23:25:46 +00009815 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009816 E->getOperatorLoc(),
9817 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009818 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009819 ScopeTypeInfo,
9820 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009821 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009822 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009823}
Mike Stump11289f42009-09-09 15:08:12 +00009824
Richard Smith151c4562016-12-20 21:35:28 +00009825template <typename Derived>
9826bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
9827 bool RequiresADL,
9828 LookupResult &R) {
9829 // Transform all the decls.
9830 bool AllEmptyPacks = true;
9831 for (auto *OldD : Old->decls()) {
9832 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
9833 if (!InstD) {
9834 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9835 // This can happen because of dependent hiding.
9836 if (isa<UsingShadowDecl>(OldD))
9837 continue;
9838 else {
9839 R.clear();
9840 return true;
9841 }
9842 }
9843
9844 // Expand using pack declarations.
9845 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
9846 ArrayRef<NamedDecl*> Decls = SingleDecl;
9847 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
9848 Decls = UPD->expansions();
9849
9850 // Expand using declarations.
9851 for (auto *D : Decls) {
9852 if (auto *UD = dyn_cast<UsingDecl>(D)) {
9853 for (auto *SD : UD->shadows())
9854 R.addDecl(SD);
9855 } else {
9856 R.addDecl(D);
9857 }
9858 }
9859
9860 AllEmptyPacks &= Decls.empty();
9861 };
9862
9863 // C++ [temp.res]/8.4.2:
9864 // The program is ill-formed, no diagnostic required, if [...] lookup for
9865 // a name in the template definition found a using-declaration, but the
9866 // lookup in the corresponding scope in the instantiation odoes not find
9867 // any declarations because the using-declaration was a pack expansion and
9868 // the corresponding pack is empty
9869 if (AllEmptyPacks && !RequiresADL) {
9870 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
9871 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
9872 return true;
9873 }
9874
9875 // Resolve a kind, but don't do any further analysis. If it's
9876 // ambiguous, the callee needs to deal with it.
9877 R.resolveKind();
9878 return false;
9879}
9880
Douglas Gregorad8a3362009-09-04 17:36:40 +00009881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009882ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009883TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009884 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009885 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9886 Sema::LookupOrdinaryName);
9887
Richard Smith151c4562016-12-20 21:35:28 +00009888 // Transform the declaration set.
9889 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
9890 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00009891
9892 // Rebuild the nested-name qualifier, if present.
9893 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009894 if (Old->getQualifierLoc()) {
9895 NestedNameSpecifierLoc QualifierLoc
9896 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9897 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009898 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009899
Douglas Gregor0da1d432011-02-28 20:01:57 +00009900 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009901 }
9902
Douglas Gregor9262f472010-04-27 18:19:34 +00009903 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009904 CXXRecordDecl *NamingClass
9905 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9906 Old->getNameLoc(),
9907 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009908 if (!NamingClass) {
9909 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009910 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009912
Douglas Gregorda7be082010-04-27 16:10:10 +00009913 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009914 }
9915
Abramo Bagnara7945c982012-01-27 09:46:47 +00009916 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9917
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009918 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009919 // it's a normal declaration name or member reference.
9920 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9921 NamedDecl *D = R.getAsSingle<NamedDecl>();
9922 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9923 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9924 // give a good diagnostic.
9925 if (D && D->isCXXInstanceMember()) {
9926 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9927 /*TemplateArgs=*/nullptr,
9928 /*Scope=*/nullptr);
9929 }
9930
John McCalle66edc12009-11-24 19:00:30 +00009931 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009932 }
John McCalle66edc12009-11-24 19:00:30 +00009933
9934 // If we have template arguments, rebuild them, then rebuild the
9935 // templateid expression.
9936 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009937 if (Old->hasExplicitTemplateArgs() &&
9938 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009939 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009940 TransArgs)) {
9941 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009942 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009943 }
John McCalle66edc12009-11-24 19:00:30 +00009944
Abramo Bagnara7945c982012-01-27 09:46:47 +00009945 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009946 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009947}
Mike Stump11289f42009-09-09 15:08:12 +00009948
Douglas Gregora16548e2009-08-11 05:31:07 +00009949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009950ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009951TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9952 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009953 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009954 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9955 TypeSourceInfo *From = E->getArg(I);
9956 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009957 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009958 TypeLocBuilder TLB;
9959 TLB.reserve(FromTL.getFullDataSize());
9960 QualType To = getDerived().TransformType(TLB, FromTL);
9961 if (To.isNull())
9962 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009963
Douglas Gregor29c42f22012-02-24 07:38:34 +00009964 if (To == From->getType())
9965 Args.push_back(From);
9966 else {
9967 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9968 ArgChanged = true;
9969 }
9970 continue;
9971 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009972
Douglas Gregor29c42f22012-02-24 07:38:34 +00009973 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009974
Douglas Gregor29c42f22012-02-24 07:38:34 +00009975 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009976 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009977 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9978 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9979 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009980
Douglas Gregor29c42f22012-02-24 07:38:34 +00009981 // Determine whether the set of unexpanded parameter packs can and should
9982 // be expanded.
9983 bool Expand = true;
9984 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009985 Optional<unsigned> OrigNumExpansions =
9986 ExpansionTL.getTypePtr()->getNumExpansions();
9987 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009988 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9989 PatternTL.getSourceRange(),
9990 Unexpanded,
9991 Expand, RetainExpansion,
9992 NumExpansions))
9993 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009994
Douglas Gregor29c42f22012-02-24 07:38:34 +00009995 if (!Expand) {
9996 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009997 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009998 // expansion.
9999 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010000
Douglas Gregor29c42f22012-02-24 07:38:34 +000010001 TypeLocBuilder TLB;
10002 TLB.reserve(From->getTypeLoc().getFullDataSize());
10003
10004 QualType To = getDerived().TransformType(TLB, PatternTL);
10005 if (To.isNull())
10006 return ExprError();
10007
Chad Rosier1dcde962012-08-08 18:46:20 +000010008 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010009 PatternTL.getSourceRange(),
10010 ExpansionTL.getEllipsisLoc(),
10011 NumExpansions);
10012 if (To.isNull())
10013 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010014
Douglas Gregor29c42f22012-02-24 07:38:34 +000010015 PackExpansionTypeLoc ToExpansionTL
10016 = TLB.push<PackExpansionTypeLoc>(To);
10017 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10018 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10019 continue;
10020 }
10021
10022 // Expand the pack expansion by substituting for each argument in the
10023 // pack(s).
10024 for (unsigned I = 0; I != *NumExpansions; ++I) {
10025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10026 TypeLocBuilder TLB;
10027 TLB.reserve(PatternTL.getFullDataSize());
10028 QualType To = getDerived().TransformType(TLB, PatternTL);
10029 if (To.isNull())
10030 return ExprError();
10031
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010032 if (To->containsUnexpandedParameterPack()) {
10033 To = getDerived().RebuildPackExpansionType(To,
10034 PatternTL.getSourceRange(),
10035 ExpansionTL.getEllipsisLoc(),
10036 NumExpansions);
10037 if (To.isNull())
10038 return ExprError();
10039
10040 PackExpansionTypeLoc ToExpansionTL
10041 = TLB.push<PackExpansionTypeLoc>(To);
10042 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10043 }
10044
Douglas Gregor29c42f22012-02-24 07:38:34 +000010045 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10046 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010047
Douglas Gregor29c42f22012-02-24 07:38:34 +000010048 if (!RetainExpansion)
10049 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010050
Douglas Gregor29c42f22012-02-24 07:38:34 +000010051 // If we're supposed to retain a pack expansion, do so by temporarily
10052 // forgetting the partially-substituted parameter pack.
10053 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10054
10055 TypeLocBuilder TLB;
10056 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010057
Douglas Gregor29c42f22012-02-24 07:38:34 +000010058 QualType To = getDerived().TransformType(TLB, PatternTL);
10059 if (To.isNull())
10060 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010061
10062 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010063 PatternTL.getSourceRange(),
10064 ExpansionTL.getEllipsisLoc(),
10065 NumExpansions);
10066 if (To.isNull())
10067 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010068
Douglas Gregor29c42f22012-02-24 07:38:34 +000010069 PackExpansionTypeLoc ToExpansionTL
10070 = TLB.push<PackExpansionTypeLoc>(To);
10071 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10072 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10073 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010074
Douglas Gregor29c42f22012-02-24 07:38:34 +000010075 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010076 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010077
10078 return getDerived().RebuildTypeTrait(E->getTrait(),
10079 E->getLocStart(),
10080 Args,
10081 E->getLocEnd());
10082}
10083
10084template<typename Derived>
10085ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010086TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10087 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10088 if (!T)
10089 return ExprError();
10090
10091 if (!getDerived().AlwaysRebuild() &&
10092 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010093 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010094
10095 ExprResult SubExpr;
10096 {
10097 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10098 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10099 if (SubExpr.isInvalid())
10100 return ExprError();
10101
10102 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010103 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010104 }
10105
10106 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10107 E->getLocStart(),
10108 T,
10109 SubExpr.get(),
10110 E->getLocEnd());
10111}
10112
10113template<typename Derived>
10114ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010115TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10116 ExprResult SubExpr;
10117 {
10118 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10119 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10120 if (SubExpr.isInvalid())
10121 return ExprError();
10122
10123 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010124 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010125 }
10126
10127 return getDerived().RebuildExpressionTrait(
10128 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10129}
10130
Reid Kleckner32506ed2014-06-12 23:03:48 +000010131template <typename Derived>
10132ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10133 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10134 TypeSourceInfo **RecoveryTSI) {
10135 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10136 DRE, AddrTaken, RecoveryTSI);
10137
10138 // Propagate both errors and recovered types, which return ExprEmpty.
10139 if (!NewDRE.isUsable())
10140 return NewDRE;
10141
10142 // We got an expr, wrap it up in parens.
10143 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10144 return PE;
10145 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10146 PE->getRParen());
10147}
10148
10149template <typename Derived>
10150ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10151 DependentScopeDeclRefExpr *E) {
10152 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10153 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010154}
10155
10156template<typename Derived>
10157ExprResult
10158TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10159 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010160 bool IsAddressOfOperand,
10161 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010162 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010163 NestedNameSpecifierLoc QualifierLoc
10164 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10165 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010166 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010167 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010168
John McCall31f82722010-11-12 08:19:04 +000010169 // TODO: If this is a conversion-function-id, verify that the
10170 // destination type name (if present) resolves the same way after
10171 // instantiation as it did in the local scope.
10172
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010173 DeclarationNameInfo NameInfo
10174 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10175 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010176 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010177
John McCalle66edc12009-11-24 19:00:30 +000010178 if (!E->hasExplicitTemplateArgs()) {
10179 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010180 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010181 // Note: it is sufficient to compare the Name component of NameInfo:
10182 // if name has not changed, DNLoc has not changed either.
10183 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010184 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010185
Reid Kleckner32506ed2014-06-12 23:03:48 +000010186 return getDerived().RebuildDependentScopeDeclRefExpr(
10187 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10188 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010189 }
John McCall6b51f282009-11-23 01:53:49 +000010190
10191 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010192 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10193 E->getNumTemplateArgs(),
10194 TransArgs))
10195 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010196
Reid Kleckner32506ed2014-06-12 23:03:48 +000010197 return getDerived().RebuildDependentScopeDeclRefExpr(
10198 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10199 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010200}
10201
10202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010204TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010205 // CXXConstructExprs other than for list-initialization and
10206 // CXXTemporaryObjectExpr are always implicit, so when we have
10207 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010208 if ((E->getNumArgs() == 1 ||
10209 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010210 (!getDerived().DropCallArgument(E->getArg(0))) &&
10211 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010212 return getDerived().TransformExpr(E->getArg(0));
10213
Douglas Gregora16548e2009-08-11 05:31:07 +000010214 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10215
10216 QualType T = getDerived().TransformType(E->getType());
10217 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010218 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010219
10220 CXXConstructorDecl *Constructor
10221 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010222 getDerived().TransformDecl(E->getLocStart(),
10223 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010224 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010226
Douglas Gregora16548e2009-08-11 05:31:07 +000010227 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010228 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010229 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010230 &ArgumentChanged))
10231 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010232
Douglas Gregora16548e2009-08-11 05:31:07 +000010233 if (!getDerived().AlwaysRebuild() &&
10234 T == E->getType() &&
10235 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010236 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010237 // Mark the constructor as referenced.
10238 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010239 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010240 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010241 }
Mike Stump11289f42009-09-09 15:08:12 +000010242
Douglas Gregordb121ba2009-12-14 16:27:04 +000010243 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010244 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010245 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010246 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010247 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010248 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010249 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010250 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010251 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010252}
Mike Stump11289f42009-09-09 15:08:12 +000010253
Richard Smith5179eb72016-06-28 19:03:57 +000010254template<typename Derived>
10255ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10256 CXXInheritedCtorInitExpr *E) {
10257 QualType T = getDerived().TransformType(E->getType());
10258 if (T.isNull())
10259 return ExprError();
10260
10261 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10262 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10263 if (!Constructor)
10264 return ExprError();
10265
10266 if (!getDerived().AlwaysRebuild() &&
10267 T == E->getType() &&
10268 Constructor == E->getConstructor()) {
10269 // Mark the constructor as referenced.
10270 // FIXME: Instantiation-specific
10271 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10272 return E;
10273 }
10274
10275 return getDerived().RebuildCXXInheritedCtorInitExpr(
10276 T, E->getLocation(), Constructor,
10277 E->constructsVBase(), E->inheritedFromVBase());
10278}
10279
Douglas Gregora16548e2009-08-11 05:31:07 +000010280/// \brief Transform a C++ temporary-binding expression.
10281///
Douglas Gregor363b1512009-12-24 18:51:59 +000010282/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10283/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010286TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010287 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010288}
Mike Stump11289f42009-09-09 15:08:12 +000010289
John McCall5d413782010-12-06 08:20:24 +000010290/// \brief Transform a C++ expression that contains cleanups that should
10291/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010292///
John McCall5d413782010-12-06 08:20:24 +000010293/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010294/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010296ExprResult
John McCall5d413782010-12-06 08:20:24 +000010297TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010298 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010299}
Mike Stump11289f42009-09-09 15:08:12 +000010300
Douglas Gregora16548e2009-08-11 05:31:07 +000010301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010302ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010303TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010304 CXXTemporaryObjectExpr *E) {
10305 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10306 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010308
Douglas Gregora16548e2009-08-11 05:31:07 +000010309 CXXConstructorDecl *Constructor
10310 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010311 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010312 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010313 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010314 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010315
Douglas Gregora16548e2009-08-11 05:31:07 +000010316 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010317 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010318 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010319 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010320 &ArgumentChanged))
10321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010322
Douglas Gregora16548e2009-08-11 05:31:07 +000010323 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010324 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010325 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010326 !ArgumentChanged) {
10327 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010328 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010329 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010330 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010331
Richard Smithd59b8322012-12-19 01:39:02 +000010332 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010333 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10334 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010335 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010336 E->getLocEnd());
10337}
Mike Stump11289f42009-09-09 15:08:12 +000010338
Douglas Gregora16548e2009-08-11 05:31:07 +000010339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010340ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010341TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010342 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010343 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010344 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010345 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10346 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010347 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010348 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010349 CEnd = E->capture_end();
10350 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010351 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010352 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010353 EnterExpressionEvaluationContext EEEC(getSema(),
10354 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010355 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10356 C->getCapturedVar()->getInit(),
10357 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010358
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010359 if (NewExprInitResult.isInvalid())
10360 return ExprError();
10361 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010362
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010363 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010364 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010365 getSema().buildLambdaInitCaptureInitialization(
10366 C->getLocation(), OldVD->getType()->isReferenceType(),
10367 OldVD->getIdentifier(),
10368 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010369 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010370 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10371 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010372 }
10373
Faisal Vali2cba1332013-10-23 06:44:28 +000010374 // Transform the template parameters, and add them to the current
10375 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010376 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010377 E->getTemplateParameterList());
10378
Richard Smith01014ce2014-11-20 23:53:14 +000010379 // Transform the type of the original lambda's call operator.
10380 // The transformation MUST be done in the CurrentInstantiationScope since
10381 // it introduces a mapping of the original to the newly created
10382 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010383 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010384 {
10385 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10386 FunctionProtoTypeLoc OldCallOpFPTL =
10387 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010388
10389 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010390 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010391 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010392 QualType NewCallOpType = TransformFunctionProtoType(
10393 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010394 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10395 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10396 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010397 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010398 if (NewCallOpType.isNull())
10399 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010400 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10401 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010402 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010403
Richard Smithc38498f2015-04-27 21:27:54 +000010404 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10405 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10406 LSI->GLTemplateParameterList = TPL;
10407
Eli Friedmand564afb2012-09-19 01:18:11 +000010408 // Create the local class that will describe the lambda.
10409 CXXRecordDecl *Class
10410 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010411 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010412 /*KnownDependent=*/false,
10413 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010414 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10415
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010416 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010417 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10418 Class, E->getIntroducerRange(), NewCallOpTSI,
10419 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010420 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10421 E->getCallOperator()->isConstexpr());
10422
Faisal Vali2cba1332013-10-23 06:44:28 +000010423 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010424
Akira Hatanaka402818462016-12-16 21:16:57 +000010425 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10426 I != NumParams; ++I) {
10427 auto *P = NewCallOperator->getParamDecl(I);
10428 if (P->hasUninstantiatedDefaultArg()) {
10429 EnterExpressionEvaluationContext Eval(
10430 getSema(), Sema::PotentiallyEvaluatedIfUsed, P);
10431 ExprResult R = getDerived().TransformExpr(
10432 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10433 P->setDefaultArg(R.get());
10434 }
10435 }
10436
Faisal Vali2cba1332013-10-23 06:44:28 +000010437 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010438 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010439
Douglas Gregorb4328232012-02-14 00:00:48 +000010440 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010441 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010442 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010443
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010444 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010445 getSema().buildLambdaScope(LSI, NewCallOperator,
10446 E->getIntroducerRange(),
10447 E->getCaptureDefault(),
10448 E->getCaptureDefaultLoc(),
10449 E->hasExplicitParameters(),
10450 E->hasExplicitResultType(),
10451 E->isMutable());
10452
10453 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010454
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010455 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010456 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010457 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010458 CEnd = E->capture_end();
10459 C != CEnd; ++C) {
10460 // When we hit the first implicit capture, tell Sema that we've finished
10461 // the list of explicit captures.
10462 if (!FinishedExplicitCaptures && C->isImplicit()) {
10463 getSema().finishLambdaExplicitCaptures(LSI);
10464 FinishedExplicitCaptures = true;
10465 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010466
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010467 // Capturing 'this' is trivial.
10468 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010469 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10470 /*BuildAndDiagnose*/ true, nullptr,
10471 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010472 continue;
10473 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010474 // Captured expression will be recaptured during captured variables
10475 // rebuilding.
10476 if (C->capturesVLAType())
10477 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010478
Richard Smithba71c082013-05-16 06:20:58 +000010479 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010480 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010481 InitCaptureInfoTy InitExprTypePair =
10482 InitCaptureExprsAndTypes[C - E->capture_begin()];
10483 ExprResult Init = InitExprTypePair.first;
10484 QualType InitQualType = InitExprTypePair.second;
10485 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010486 Invalid = true;
10487 continue;
10488 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010489 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010490 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010491 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10492 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010493 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010494 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010495 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010496 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010497 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010498 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010499 continue;
10500 }
10501
10502 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10503
Douglas Gregor3e308b12012-02-14 19:27:52 +000010504 // Determine the capture kind for Sema.
10505 Sema::TryCaptureKind Kind
10506 = C->isImplicit()? Sema::TryCapture_Implicit
10507 : C->getCaptureKind() == LCK_ByCopy
10508 ? Sema::TryCapture_ExplicitByVal
10509 : Sema::TryCapture_ExplicitByRef;
10510 SourceLocation EllipsisLoc;
10511 if (C->isPackExpansion()) {
10512 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10513 bool ShouldExpand = false;
10514 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010515 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010516 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10517 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010518 Unexpanded,
10519 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010520 NumExpansions)) {
10521 Invalid = true;
10522 continue;
10523 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010524
Douglas Gregor3e308b12012-02-14 19:27:52 +000010525 if (ShouldExpand) {
10526 // The transform has determined that we should perform an expansion;
10527 // transform and capture each of the arguments.
10528 // expansion of the pattern. Do so.
10529 VarDecl *Pack = C->getCapturedVar();
10530 for (unsigned I = 0; I != *NumExpansions; ++I) {
10531 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10532 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010533 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010534 Pack));
10535 if (!CapturedVar) {
10536 Invalid = true;
10537 continue;
10538 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010539
Douglas Gregor3e308b12012-02-14 19:27:52 +000010540 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010541 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10542 }
Richard Smith9467be42014-06-06 17:33:35 +000010543
10544 // FIXME: Retain a pack expansion if RetainExpansion is true.
10545
Douglas Gregor3e308b12012-02-14 19:27:52 +000010546 continue;
10547 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010548
Douglas Gregor3e308b12012-02-14 19:27:52 +000010549 EllipsisLoc = C->getEllipsisLoc();
10550 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010551
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010552 // Transform the captured variable.
10553 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010554 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010555 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010556 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010557 Invalid = true;
10558 continue;
10559 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010560
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010561 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010562 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10563 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010564 }
10565 if (!FinishedExplicitCaptures)
10566 getSema().finishLambdaExplicitCaptures(LSI);
10567
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010568 // Enter a new evaluation context to insulate the lambda from any
10569 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010570 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010571
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010572 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010573 StmtResult Body =
10574 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10575
10576 // ActOnLambda* will pop the function scope for us.
10577 FuncScopeCleanup.disable();
10578
Douglas Gregorb4328232012-02-14 00:00:48 +000010579 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010580 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010581 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010582 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010583 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010584 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010585
Richard Smithc38498f2015-04-27 21:27:54 +000010586 // Copy the LSI before ActOnFinishFunctionBody removes it.
10587 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10588 // the call operator.
10589 auto LSICopy = *LSI;
10590 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10591 /*IsInstantiation*/ true);
10592 SavedContext.pop();
10593
10594 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10595 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010596}
10597
10598template<typename Derived>
10599ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010600TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010601 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010602 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10603 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010605
Douglas Gregora16548e2009-08-11 05:31:07 +000010606 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010607 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010608 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010609 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010610 &ArgumentChanged))
10611 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010612
Douglas Gregora16548e2009-08-11 05:31:07 +000010613 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010614 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010615 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010616 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010617
Douglas Gregora16548e2009-08-11 05:31:07 +000010618 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010619 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010620 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010621 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010622 E->getRParenLoc());
10623}
Mike Stump11289f42009-09-09 15:08:12 +000010624
Douglas Gregora16548e2009-08-11 05:31:07 +000010625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010626ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010627TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010628 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010629 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010630 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010631 Expr *OldBase;
10632 QualType BaseType;
10633 QualType ObjectType;
10634 if (!E->isImplicitAccess()) {
10635 OldBase = E->getBase();
10636 Base = getDerived().TransformExpr(OldBase);
10637 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010639
John McCall2d74de92009-12-01 22:10:20 +000010640 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010641 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010642 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010643 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010644 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010645 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010646 ObjectTy,
10647 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010648 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010649 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010650
John McCallba7bf592010-08-24 05:47:05 +000010651 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010652 BaseType = ((Expr*) Base.get())->getType();
10653 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010654 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010655 BaseType = getDerived().TransformType(E->getBaseType());
10656 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10657 }
Mike Stump11289f42009-09-09 15:08:12 +000010658
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010659 // Transform the first part of the nested-name-specifier that qualifies
10660 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010661 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010662 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010663 E->getFirstQualifierFoundInScope(),
10664 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010665
Douglas Gregore16af532011-02-28 18:50:33 +000010666 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010667 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010668 QualifierLoc
10669 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10670 ObjectType,
10671 FirstQualifierInScope);
10672 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010673 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010674 }
Mike Stump11289f42009-09-09 15:08:12 +000010675
Abramo Bagnara7945c982012-01-27 09:46:47 +000010676 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10677
John McCall31f82722010-11-12 08:19:04 +000010678 // TODO: If this is a conversion-function-id, verify that the
10679 // destination type name (if present) resolves the same way after
10680 // instantiation as it did in the local scope.
10681
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010682 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010683 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010684 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010686
John McCall2d74de92009-12-01 22:10:20 +000010687 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010688 // This is a reference to a member without an explicitly-specified
10689 // template argument list. Optimize for this common case.
10690 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010691 Base.get() == OldBase &&
10692 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010693 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010694 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010695 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010696 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010697
John McCallb268a282010-08-23 23:25:46 +000010698 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010699 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010700 E->isArrow(),
10701 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010702 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010703 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010704 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010705 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010706 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010707 }
10708
John McCall6b51f282009-11-23 01:53:49 +000010709 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010710 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10711 E->getNumTemplateArgs(),
10712 TransArgs))
10713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010714
John McCallb268a282010-08-23 23:25:46 +000010715 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010716 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010717 E->isArrow(),
10718 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010719 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010720 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010721 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010722 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010723 &TransArgs);
10724}
10725
10726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010727ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010728TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010729 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010730 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010731 QualType BaseType;
10732 if (!Old->isImplicitAccess()) {
10733 Base = getDerived().TransformExpr(Old->getBase());
10734 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010735 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010736 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010737 Old->isArrow());
10738 if (Base.isInvalid())
10739 return ExprError();
10740 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010741 } else {
10742 BaseType = getDerived().TransformType(Old->getBaseType());
10743 }
John McCall10eae182009-11-30 22:42:35 +000010744
Douglas Gregor0da1d432011-02-28 20:01:57 +000010745 NestedNameSpecifierLoc QualifierLoc;
10746 if (Old->getQualifierLoc()) {
10747 QualifierLoc
10748 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10749 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010750 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010751 }
10752
Abramo Bagnara7945c982012-01-27 09:46:47 +000010753 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10754
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010755 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010756 Sema::LookupOrdinaryName);
10757
Richard Smith151c4562016-12-20 21:35:28 +000010758 // Transform the declaration set.
10759 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
10760 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010761
Douglas Gregor9262f472010-04-27 18:19:34 +000010762 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010763 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010764 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010765 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010766 Old->getMemberLoc(),
10767 Old->getNamingClass()));
10768 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010769 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010770
Douglas Gregorda7be082010-04-27 16:10:10 +000010771 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010772 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010773
John McCall10eae182009-11-30 22:42:35 +000010774 TemplateArgumentListInfo TransArgs;
10775 if (Old->hasExplicitTemplateArgs()) {
10776 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10777 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010778 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10779 Old->getNumTemplateArgs(),
10780 TransArgs))
10781 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010782 }
John McCall38836f02010-01-15 08:34:02 +000010783
10784 // FIXME: to do this check properly, we will need to preserve the
10785 // first-qualifier-in-scope here, just in case we had a dependent
10786 // base (and therefore couldn't do the check) and a
10787 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010788 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010789
John McCallb268a282010-08-23 23:25:46 +000010790 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010791 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010792 Old->getOperatorLoc(),
10793 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010794 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010795 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010796 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010797 R,
10798 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010799 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010800}
10801
10802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010803ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010804TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010805 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010806 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10807 if (SubExpr.isInvalid())
10808 return ExprError();
10809
10810 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010811 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010812
10813 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10814}
10815
10816template<typename Derived>
10817ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010818TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010819 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10820 if (Pattern.isInvalid())
10821 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010822
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010823 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010824 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010825
Douglas Gregorb8840002011-01-14 21:20:45 +000010826 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10827 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010828}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010829
10830template<typename Derived>
10831ExprResult
10832TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10833 // If E is not value-dependent, then nothing will change when we transform it.
10834 // Note: This is an instantiation-centric view.
10835 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010836 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010837
Richard Smithd784e682015-09-23 21:41:42 +000010838 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010839
Richard Smithd784e682015-09-23 21:41:42 +000010840 ArrayRef<TemplateArgument> PackArgs;
10841 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010842
Richard Smithd784e682015-09-23 21:41:42 +000010843 // Find the argument list to transform.
10844 if (E->isPartiallySubstituted()) {
10845 PackArgs = E->getPartialArguments();
10846 } else if (E->isValueDependent()) {
10847 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10848 bool ShouldExpand = false;
10849 bool RetainExpansion = false;
10850 Optional<unsigned> NumExpansions;
10851 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10852 Unexpanded,
10853 ShouldExpand, RetainExpansion,
10854 NumExpansions))
10855 return ExprError();
10856
10857 // If we need to expand the pack, build a template argument from it and
10858 // expand that.
10859 if (ShouldExpand) {
10860 auto *Pack = E->getPack();
10861 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10862 ArgStorage = getSema().Context.getPackExpansionType(
10863 getSema().Context.getTypeDeclType(TTPD), None);
10864 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10865 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10866 } else {
10867 auto *VD = cast<ValueDecl>(Pack);
10868 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10869 VK_RValue, E->getPackLoc());
10870 if (DRE.isInvalid())
10871 return ExprError();
10872 ArgStorage = new (getSema().Context) PackExpansionExpr(
10873 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10874 }
10875 PackArgs = ArgStorage;
10876 }
10877 }
10878
10879 // If we're not expanding the pack, just transform the decl.
10880 if (!PackArgs.size()) {
10881 auto *Pack = cast_or_null<NamedDecl>(
10882 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010883 if (!Pack)
10884 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010885 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10886 E->getPackLoc(),
10887 E->getRParenLoc(), None, None);
10888 }
10889
Richard Smithc5452ed2016-10-19 22:18:42 +000010890 // Try to compute the result without performing a partial substitution.
10891 Optional<unsigned> Result = 0;
10892 for (const TemplateArgument &Arg : PackArgs) {
10893 if (!Arg.isPackExpansion()) {
10894 Result = *Result + 1;
10895 continue;
10896 }
10897
10898 TemplateArgumentLoc ArgLoc;
10899 InventTemplateArgumentLoc(Arg, ArgLoc);
10900
10901 // Find the pattern of the pack expansion.
10902 SourceLocation Ellipsis;
10903 Optional<unsigned> OrigNumExpansions;
10904 TemplateArgumentLoc Pattern =
10905 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
10906 OrigNumExpansions);
10907
10908 // Substitute under the pack expansion. Do not expand the pack (yet).
10909 TemplateArgumentLoc OutPattern;
10910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10911 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
10912 /*Uneval*/ true))
10913 return true;
10914
10915 // See if we can determine the number of arguments from the result.
10916 Optional<unsigned> NumExpansions =
10917 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
10918 if (!NumExpansions) {
10919 // No: we must be in an alias template expansion, and we're going to need
10920 // to actually expand the packs.
10921 Result = None;
10922 break;
10923 }
10924
10925 Result = *Result + *NumExpansions;
10926 }
10927
10928 // Common case: we could determine the number of expansions without
10929 // substituting.
10930 if (Result)
10931 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10932 E->getPackLoc(),
10933 E->getRParenLoc(), *Result, None);
10934
Richard Smithd784e682015-09-23 21:41:42 +000010935 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10936 E->getPackLoc());
10937 {
10938 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10939 typedef TemplateArgumentLocInventIterator<
10940 Derived, const TemplateArgument*> PackLocIterator;
10941 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10942 PackLocIterator(*this, PackArgs.end()),
10943 TransformedPackArgs, /*Uneval*/true))
10944 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010945 }
10946
Richard Smithc5452ed2016-10-19 22:18:42 +000010947 // Check whether we managed to fully-expand the pack.
10948 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000010949 SmallVector<TemplateArgument, 8> Args;
10950 bool PartialSubstitution = false;
10951 for (auto &Loc : TransformedPackArgs.arguments()) {
10952 Args.push_back(Loc.getArgument());
10953 if (Loc.getArgument().isPackExpansion())
10954 PartialSubstitution = true;
10955 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010956
Richard Smithd784e682015-09-23 21:41:42 +000010957 if (PartialSubstitution)
10958 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10959 E->getPackLoc(),
10960 E->getRParenLoc(), None, Args);
10961
10962 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010963 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010964 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010965}
10966
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010967template<typename Derived>
10968ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010969TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10970 SubstNonTypeTemplateParmPackExpr *E) {
10971 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010972 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010973}
10974
10975template<typename Derived>
10976ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010977TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10978 SubstNonTypeTemplateParmExpr *E) {
10979 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010980 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010981}
10982
10983template<typename Derived>
10984ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010985TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10986 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010987 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010988}
10989
10990template<typename Derived>
10991ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010992TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10993 MaterializeTemporaryExpr *E) {
10994 return getDerived().TransformExpr(E->GetTemporaryExpr());
10995}
Chad Rosier1dcde962012-08-08 18:46:20 +000010996
Douglas Gregorfe314812011-06-21 17:03:29 +000010997template<typename Derived>
10998ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010999TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11000 Expr *Pattern = E->getPattern();
11001
11002 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11003 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11004 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11005
11006 // Determine whether the set of unexpanded parameter packs can and should
11007 // be expanded.
11008 bool Expand = true;
11009 bool RetainExpansion = false;
11010 Optional<unsigned> NumExpansions;
11011 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11012 Pattern->getSourceRange(),
11013 Unexpanded,
11014 Expand, RetainExpansion,
11015 NumExpansions))
11016 return true;
11017
11018 if (!Expand) {
11019 // Do not expand any packs here, just transform and rebuild a fold
11020 // expression.
11021 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11022
11023 ExprResult LHS =
11024 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11025 if (LHS.isInvalid())
11026 return true;
11027
11028 ExprResult RHS =
11029 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11030 if (RHS.isInvalid())
11031 return true;
11032
11033 if (!getDerived().AlwaysRebuild() &&
11034 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11035 return E;
11036
11037 return getDerived().RebuildCXXFoldExpr(
11038 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11039 RHS.get(), E->getLocEnd());
11040 }
11041
11042 // The transform has determined that we should perform an elementwise
11043 // expansion of the pattern. Do so.
11044 ExprResult Result = getDerived().TransformExpr(E->getInit());
11045 if (Result.isInvalid())
11046 return true;
11047 bool LeftFold = E->isLeftFold();
11048
11049 // If we're retaining an expansion for a right fold, it is the innermost
11050 // component and takes the init (if any).
11051 if (!LeftFold && RetainExpansion) {
11052 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11053
11054 ExprResult Out = getDerived().TransformExpr(Pattern);
11055 if (Out.isInvalid())
11056 return true;
11057
11058 Result = getDerived().RebuildCXXFoldExpr(
11059 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11060 Result.get(), E->getLocEnd());
11061 if (Result.isInvalid())
11062 return true;
11063 }
11064
11065 for (unsigned I = 0; I != *NumExpansions; ++I) {
11066 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11067 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11068 ExprResult Out = getDerived().TransformExpr(Pattern);
11069 if (Out.isInvalid())
11070 return true;
11071
11072 if (Out.get()->containsUnexpandedParameterPack()) {
11073 // We still have a pack; retain a pack expansion for this slice.
11074 Result = getDerived().RebuildCXXFoldExpr(
11075 E->getLocStart(),
11076 LeftFold ? Result.get() : Out.get(),
11077 E->getOperator(), E->getEllipsisLoc(),
11078 LeftFold ? Out.get() : Result.get(),
11079 E->getLocEnd());
11080 } else if (Result.isUsable()) {
11081 // We've got down to a single element; build a binary operator.
11082 Result = getDerived().RebuildBinaryOperator(
11083 E->getEllipsisLoc(), E->getOperator(),
11084 LeftFold ? Result.get() : Out.get(),
11085 LeftFold ? Out.get() : Result.get());
11086 } else
11087 Result = Out;
11088
11089 if (Result.isInvalid())
11090 return true;
11091 }
11092
11093 // If we're retaining an expansion for a left fold, it is the outermost
11094 // component and takes the complete expansion so far as its init (if any).
11095 if (LeftFold && RetainExpansion) {
11096 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11097
11098 ExprResult Out = getDerived().TransformExpr(Pattern);
11099 if (Out.isInvalid())
11100 return true;
11101
11102 Result = getDerived().RebuildCXXFoldExpr(
11103 E->getLocStart(), Result.get(),
11104 E->getOperator(), E->getEllipsisLoc(),
11105 Out.get(), E->getLocEnd());
11106 if (Result.isInvalid())
11107 return true;
11108 }
11109
11110 // If we had no init and an empty pack, and we're not retaining an expansion,
11111 // then produce a fallback value or error.
11112 if (Result.isUnset())
11113 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11114 E->getOperator());
11115
11116 return Result;
11117}
11118
11119template<typename Derived>
11120ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011121TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11122 CXXStdInitializerListExpr *E) {
11123 return getDerived().TransformExpr(E->getSubExpr());
11124}
11125
11126template<typename Derived>
11127ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011128TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011129 return SemaRef.MaybeBindToTemporary(E);
11130}
11131
11132template<typename Derived>
11133ExprResult
11134TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011135 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011136}
11137
11138template<typename Derived>
11139ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011140TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11141 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11142 if (SubExpr.isInvalid())
11143 return ExprError();
11144
11145 if (!getDerived().AlwaysRebuild() &&
11146 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011147 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011148
11149 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011150}
11151
11152template<typename Derived>
11153ExprResult
11154TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11155 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011156 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011157 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011158 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011159 /*IsCall=*/false, Elements, &ArgChanged))
11160 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011161
Ted Kremeneke65b0862012-03-06 20:05:56 +000011162 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11163 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011164
Ted Kremeneke65b0862012-03-06 20:05:56 +000011165 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11166 Elements.data(),
11167 Elements.size());
11168}
11169
11170template<typename Derived>
11171ExprResult
11172TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011173 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011174 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011175 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011176 bool ArgChanged = false;
11177 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11178 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011179
Ted Kremeneke65b0862012-03-06 20:05:56 +000011180 if (OrigElement.isPackExpansion()) {
11181 // This key/value element is a pack expansion.
11182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11183 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11184 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11185 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11186
11187 // Determine whether the set of unexpanded parameter packs can
11188 // and should be expanded.
11189 bool Expand = true;
11190 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011191 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11192 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011193 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11194 OrigElement.Value->getLocEnd());
11195 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11196 PatternRange,
11197 Unexpanded,
11198 Expand, RetainExpansion,
11199 NumExpansions))
11200 return ExprError();
11201
11202 if (!Expand) {
11203 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011204 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011205 // expansion.
11206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11207 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11208 if (Key.isInvalid())
11209 return ExprError();
11210
11211 if (Key.get() != OrigElement.Key)
11212 ArgChanged = true;
11213
11214 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11215 if (Value.isInvalid())
11216 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011217
Ted Kremeneke65b0862012-03-06 20:05:56 +000011218 if (Value.get() != OrigElement.Value)
11219 ArgChanged = true;
11220
Chad Rosier1dcde962012-08-08 18:46:20 +000011221 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011222 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11223 };
11224 Elements.push_back(Expansion);
11225 continue;
11226 }
11227
11228 // Record right away that the argument was changed. This needs
11229 // to happen even if the array expands to nothing.
11230 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011231
Ted Kremeneke65b0862012-03-06 20:05:56 +000011232 // The transform has determined that we should perform an elementwise
11233 // expansion of the pattern. Do so.
11234 for (unsigned I = 0; I != *NumExpansions; ++I) {
11235 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11236 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11237 if (Key.isInvalid())
11238 return ExprError();
11239
11240 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11241 if (Value.isInvalid())
11242 return ExprError();
11243
Chad Rosier1dcde962012-08-08 18:46:20 +000011244 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011245 Key.get(), Value.get(), SourceLocation(), NumExpansions
11246 };
11247
11248 // If any unexpanded parameter packs remain, we still have a
11249 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011250 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011251 if (Key.get()->containsUnexpandedParameterPack() ||
11252 Value.get()->containsUnexpandedParameterPack())
11253 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011254
Ted Kremeneke65b0862012-03-06 20:05:56 +000011255 Elements.push_back(Element);
11256 }
11257
Richard Smith9467be42014-06-06 17:33:35 +000011258 // FIXME: Retain a pack expansion if RetainExpansion is true.
11259
Ted Kremeneke65b0862012-03-06 20:05:56 +000011260 // We've finished with this pack expansion.
11261 continue;
11262 }
11263
11264 // Transform and check key.
11265 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11266 if (Key.isInvalid())
11267 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011268
Ted Kremeneke65b0862012-03-06 20:05:56 +000011269 if (Key.get() != OrigElement.Key)
11270 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011271
Ted Kremeneke65b0862012-03-06 20:05:56 +000011272 // Transform and check value.
11273 ExprResult Value
11274 = getDerived().TransformExpr(OrigElement.Value);
11275 if (Value.isInvalid())
11276 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011277
Ted Kremeneke65b0862012-03-06 20:05:56 +000011278 if (Value.get() != OrigElement.Value)
11279 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011280
11281 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011282 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011283 };
11284 Elements.push_back(Element);
11285 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011286
Ted Kremeneke65b0862012-03-06 20:05:56 +000011287 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11288 return SemaRef.MaybeBindToTemporary(E);
11289
11290 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011291 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011292}
11293
Mike Stump11289f42009-09-09 15:08:12 +000011294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011295ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011296TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011297 TypeSourceInfo *EncodedTypeInfo
11298 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11299 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011301
Douglas Gregora16548e2009-08-11 05:31:07 +000011302 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011303 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011304 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011305
11306 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011307 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011308 E->getRParenLoc());
11309}
Mike Stump11289f42009-09-09 15:08:12 +000011310
Douglas Gregora16548e2009-08-11 05:31:07 +000011311template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011312ExprResult TreeTransform<Derived>::
11313TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011314 // This is a kind of implicit conversion, and it needs to get dropped
11315 // and recomputed for the same general reasons that ImplicitCastExprs
11316 // do, as well a more specific one: this expression is only valid when
11317 // it appears *immediately* as an argument expression.
11318 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011319}
11320
11321template<typename Derived>
11322ExprResult TreeTransform<Derived>::
11323TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011324 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011325 = getDerived().TransformType(E->getTypeInfoAsWritten());
11326 if (!TSInfo)
11327 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011328
John McCall31168b02011-06-15 23:02:42 +000011329 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011330 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011331 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011332
John McCall31168b02011-06-15 23:02:42 +000011333 if (!getDerived().AlwaysRebuild() &&
11334 TSInfo == E->getTypeInfoAsWritten() &&
11335 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011336 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011337
John McCall31168b02011-06-15 23:02:42 +000011338 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011339 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011340 Result.get());
11341}
11342
Erik Pilkington29099de2016-07-16 00:35:23 +000011343template <typename Derived>
11344ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11345 ObjCAvailabilityCheckExpr *E) {
11346 return E;
11347}
11348
John McCall31168b02011-06-15 23:02:42 +000011349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011351TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011352 // Transform arguments.
11353 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011354 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011355 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011356 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011357 &ArgChanged))
11358 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011359
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011360 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11361 // Class message: transform the receiver type.
11362 TypeSourceInfo *ReceiverTypeInfo
11363 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11364 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011365 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011366
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011367 // If nothing changed, just retain the existing message send.
11368 if (!getDerived().AlwaysRebuild() &&
11369 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011370 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011371
11372 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011373 SmallVector<SourceLocation, 16> SelLocs;
11374 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011375 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11376 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011377 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011378 E->getMethodDecl(),
11379 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011380 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011381 E->getRightLoc());
11382 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011383 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11384 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011385 if (!E->getMethodDecl())
11386 return ExprError();
11387
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011388 // Build a new class message send to 'super'.
11389 SmallVector<SourceLocation, 16> SelLocs;
11390 E->getSelectorLocs(SelLocs);
11391 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11392 E->getSelector(),
11393 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011394 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011395 E->getMethodDecl(),
11396 E->getLeftLoc(),
11397 Args,
11398 E->getRightLoc());
11399 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011400
11401 // Instance message: transform the receiver
11402 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11403 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011404 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011405 = getDerived().TransformExpr(E->getInstanceReceiver());
11406 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011407 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011408
11409 // If nothing changed, just retain the existing message send.
11410 if (!getDerived().AlwaysRebuild() &&
11411 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011412 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011413
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011414 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011415 SmallVector<SourceLocation, 16> SelLocs;
11416 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011417 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011418 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011419 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011420 E->getMethodDecl(),
11421 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011422 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011423 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011424}
11425
Mike Stump11289f42009-09-09 15:08:12 +000011426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011428TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011429 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011430}
11431
Mike Stump11289f42009-09-09 15:08:12 +000011432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011434TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011435 return E;
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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011441 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011442 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011443 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011444 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011445
11446 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011447
Douglas Gregord51d90d2010-04-26 20:11:03 +000011448 // If nothing changed, just retain the existing expression.
11449 if (!getDerived().AlwaysRebuild() &&
11450 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011451 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011452
John McCallb268a282010-08-23 23:25:46 +000011453 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011454 E->getLocation(),
11455 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011456}
11457
Mike Stump11289f42009-09-09 15:08:12 +000011458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011459ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011460TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011461 // 'super' and types never change. Property never changes. Just
11462 // retain the existing expression.
11463 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011464 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011465
Douglas Gregor9faee212010-04-26 20:47:02 +000011466 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011467 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011468 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011469 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011470
Douglas Gregor9faee212010-04-26 20:47:02 +000011471 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011472
Douglas Gregor9faee212010-04-26 20:47:02 +000011473 // If nothing changed, just retain the existing expression.
11474 if (!getDerived().AlwaysRebuild() &&
11475 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011476 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011477
John McCallb7bd14f2010-12-02 01:19:52 +000011478 if (E->isExplicitProperty())
11479 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11480 E->getExplicitProperty(),
11481 E->getLocation());
11482
11483 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011484 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011485 E->getImplicitPropertyGetter(),
11486 E->getImplicitPropertySetter(),
11487 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011488}
11489
Mike Stump11289f42009-09-09 15:08:12 +000011490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011491ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011492TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11493 // Transform the base expression.
11494 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11495 if (Base.isInvalid())
11496 return ExprError();
11497
11498 // Transform the key expression.
11499 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11500 if (Key.isInvalid())
11501 return ExprError();
11502
11503 // If nothing changed, just retain the existing expression.
11504 if (!getDerived().AlwaysRebuild() &&
11505 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011506 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011507
Chad Rosier1dcde962012-08-08 18:46:20 +000011508 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011509 Base.get(), Key.get(),
11510 E->getAtIndexMethodDecl(),
11511 E->setAtIndexMethodDecl());
11512}
11513
11514template<typename Derived>
11515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011516TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011517 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011518 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011519 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011520 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011521
Douglas Gregord51d90d2010-04-26 20:11:03 +000011522 // If nothing changed, just retain the existing expression.
11523 if (!getDerived().AlwaysRebuild() &&
11524 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011525 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011526
John McCallb268a282010-08-23 23:25:46 +000011527 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011528 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011529 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011530}
11531
Mike Stump11289f42009-09-09 15:08:12 +000011532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011534TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011535 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011536 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011537 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011538 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011539 SubExprs, &ArgumentChanged))
11540 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011541
Douglas Gregora16548e2009-08-11 05:31:07 +000011542 if (!getDerived().AlwaysRebuild() &&
11543 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011544 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011545
Douglas Gregora16548e2009-08-11 05:31:07 +000011546 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011547 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011548 E->getRParenLoc());
11549}
11550
Mike Stump11289f42009-09-09 15:08:12 +000011551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011552ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011553TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11554 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11555 if (SrcExpr.isInvalid())
11556 return ExprError();
11557
11558 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11559 if (!Type)
11560 return ExprError();
11561
11562 if (!getDerived().AlwaysRebuild() &&
11563 Type == E->getTypeSourceInfo() &&
11564 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011565 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011566
11567 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11568 SrcExpr.get(), Type,
11569 E->getRParenLoc());
11570}
11571
11572template<typename Derived>
11573ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011574TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011575 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011576
Craig Topperc3ec1492014-05-26 06:22:03 +000011577 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011578 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11579
11580 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011581 blockScope->TheDecl->setBlockMissingReturnType(
11582 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011583
Chris Lattner01cf8db2011-07-20 06:58:45 +000011584 SmallVector<ParmVarDecl*, 4> params;
11585 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011586
John McCallc8e321d2016-03-01 02:09:25 +000011587 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11588
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011589 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011590 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011591 if (getDerived().TransformFunctionTypeParams(
11592 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11593 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11594 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011595 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011596 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011597 }
John McCall490112f2011-02-04 18:33:18 +000011598
Eli Friedman34b49062012-01-26 03:00:14 +000011599 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011600 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011601
John McCallc8e321d2016-03-01 02:09:25 +000011602 auto epi = exprFunctionType->getExtProtoInfo();
11603 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11604
Jordan Rose5c382722013-03-08 21:51:21 +000011605 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011606 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011607 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011608
11609 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011610 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011611 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011612
11613 if (!oldBlock->blockMissingReturnType()) {
11614 blockScope->HasImplicitReturnType = false;
11615 blockScope->ReturnType = exprResultType;
11616 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011617
John McCall3882ace2011-01-05 12:14:39 +000011618 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011619 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011620 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011621 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011622 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011623 }
John McCall3882ace2011-01-05 12:14:39 +000011624
John McCall490112f2011-02-04 18:33:18 +000011625#ifndef NDEBUG
11626 // In builds with assertions, make sure that we captured everything we
11627 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011628 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011629 for (const auto &I : oldBlock->captures()) {
11630 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011631
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011632 // Ignore parameter packs.
11633 if (isa<ParmVarDecl>(oldCapture) &&
11634 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11635 continue;
John McCall490112f2011-02-04 18:33:18 +000011636
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011637 VarDecl *newCapture =
11638 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11639 oldCapture));
11640 assert(blockScope->CaptureMap.count(newCapture));
11641 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011642 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011643 }
11644#endif
11645
11646 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011647 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011648}
11649
Mike Stump11289f42009-09-09 15:08:12 +000011650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011651ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011652TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011653 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011654}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011655
11656template<typename Derived>
11657ExprResult
11658TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011659 QualType RetTy = getDerived().TransformType(E->getType());
11660 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011661 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011662 SubExprs.reserve(E->getNumSubExprs());
11663 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11664 SubExprs, &ArgumentChanged))
11665 return ExprError();
11666
11667 if (!getDerived().AlwaysRebuild() &&
11668 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011669 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011670
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011671 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011672 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011673}
Chad Rosier1dcde962012-08-08 18:46:20 +000011674
Douglas Gregora16548e2009-08-11 05:31:07 +000011675//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011676// Type reconstruction
11677//===----------------------------------------------------------------------===//
11678
Mike Stump11289f42009-09-09 15:08:12 +000011679template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011680QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11681 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011682 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011683 getDerived().getBaseEntity());
11684}
11685
Mike Stump11289f42009-09-09 15:08:12 +000011686template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011687QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11688 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011689 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011690 getDerived().getBaseEntity());
11691}
11692
Mike Stump11289f42009-09-09 15:08:12 +000011693template<typename Derived>
11694QualType
John McCall70dd5f62009-10-30 00:06:24 +000011695TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11696 bool WrittenAsLValue,
11697 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011698 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011699 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011700}
11701
11702template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011703QualType
John McCall70dd5f62009-10-30 00:06:24 +000011704TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11705 QualType ClassType,
11706 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011707 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11708 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011709}
11710
11711template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000011712QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11713 const ObjCTypeParamDecl *Decl,
11714 SourceLocation ProtocolLAngleLoc,
11715 ArrayRef<ObjCProtocolDecl *> Protocols,
11716 ArrayRef<SourceLocation> ProtocolLocs,
11717 SourceLocation ProtocolRAngleLoc) {
11718 return SemaRef.BuildObjCTypeParamType(Decl,
11719 ProtocolLAngleLoc, Protocols,
11720 ProtocolLocs, ProtocolRAngleLoc,
11721 /*FailOnError=*/true);
11722}
11723
11724template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011725QualType TreeTransform<Derived>::RebuildObjCObjectType(
11726 QualType BaseType,
11727 SourceLocation Loc,
11728 SourceLocation TypeArgsLAngleLoc,
11729 ArrayRef<TypeSourceInfo *> TypeArgs,
11730 SourceLocation TypeArgsRAngleLoc,
11731 SourceLocation ProtocolLAngleLoc,
11732 ArrayRef<ObjCProtocolDecl *> Protocols,
11733 ArrayRef<SourceLocation> ProtocolLocs,
11734 SourceLocation ProtocolRAngleLoc) {
11735 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11736 TypeArgs, TypeArgsRAngleLoc,
11737 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11738 ProtocolRAngleLoc,
11739 /*FailOnError=*/true);
11740}
11741
11742template<typename Derived>
11743QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11744 QualType PointeeType,
11745 SourceLocation Star) {
11746 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11747}
11748
11749template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011750QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011751TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11752 ArrayType::ArraySizeModifier SizeMod,
11753 const llvm::APInt *Size,
11754 Expr *SizeExpr,
11755 unsigned IndexTypeQuals,
11756 SourceRange BracketsRange) {
11757 if (SizeExpr || !Size)
11758 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11759 IndexTypeQuals, BracketsRange,
11760 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011761
11762 QualType Types[] = {
11763 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11764 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11765 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011766 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011767 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011768 QualType SizeType;
11769 for (unsigned I = 0; I != NumTypes; ++I)
11770 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11771 SizeType = Types[I];
11772 break;
11773 }
Mike Stump11289f42009-09-09 15:08:12 +000011774
Eli Friedman9562f392012-01-25 23:20:27 +000011775 // Note that we can return a VariableArrayType here in the case where
11776 // the element type was a dependent VariableArrayType.
11777 IntegerLiteral *ArraySize
11778 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11779 /*FIXME*/BracketsRange.getBegin());
11780 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011781 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011782 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011783}
Mike Stump11289f42009-09-09 15:08:12 +000011784
Douglas Gregord6ff3322009-08-04 16:50:30 +000011785template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011786QualType
11787TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011788 ArrayType::ArraySizeModifier SizeMod,
11789 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011790 unsigned IndexTypeQuals,
11791 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011792 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011793 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011794}
11795
11796template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011797QualType
Mike Stump11289f42009-09-09 15:08:12 +000011798TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011799 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011800 unsigned IndexTypeQuals,
11801 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011802 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011803 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011804}
Mike Stump11289f42009-09-09 15:08:12 +000011805
Douglas Gregord6ff3322009-08-04 16:50:30 +000011806template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011807QualType
11808TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011809 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011810 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011811 unsigned IndexTypeQuals,
11812 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011813 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011814 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011815 IndexTypeQuals, BracketsRange);
11816}
11817
11818template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011819QualType
11820TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011821 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011822 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011823 unsigned IndexTypeQuals,
11824 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011825 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011826 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011827 IndexTypeQuals, BracketsRange);
11828}
11829
11830template<typename Derived>
11831QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011832 unsigned NumElements,
11833 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011834 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011835 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011836}
Mike Stump11289f42009-09-09 15:08:12 +000011837
Douglas Gregord6ff3322009-08-04 16:50:30 +000011838template<typename Derived>
11839QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11840 unsigned NumElements,
11841 SourceLocation AttributeLoc) {
11842 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11843 NumElements, true);
11844 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011845 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11846 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011847 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011848}
Mike Stump11289f42009-09-09 15:08:12 +000011849
Douglas Gregord6ff3322009-08-04 16:50:30 +000011850template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011851QualType
11852TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011853 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011854 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011855 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011856}
Mike Stump11289f42009-09-09 15:08:12 +000011857
Douglas Gregord6ff3322009-08-04 16:50:30 +000011858template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011859QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11860 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011861 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011862 const FunctionProtoType::ExtProtoInfo &EPI) {
11863 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011864 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011865 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011866 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011867}
Mike Stump11289f42009-09-09 15:08:12 +000011868
Douglas Gregord6ff3322009-08-04 16:50:30 +000011869template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011870QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11871 return SemaRef.Context.getFunctionNoProtoType(T);
11872}
11873
11874template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000011875QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
11876 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000011877 assert(D && "no decl found");
11878 if (D->isInvalidDecl()) return QualType();
11879
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011880 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011881 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000011882 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
11883 // A valid resolved using typename pack expansion decl can have multiple
11884 // UsingDecls, but they must each have exactly one type, and it must be
11885 // the same type in every case. But we must have at least one expansion!
11886 if (UPD->expansions().empty()) {
11887 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
11888 << UPD->isCXXClassMember() << UPD;
11889 return QualType();
11890 }
11891
11892 // We might still have some unresolved types. Try to pick a resolved type
11893 // if we can. The final instantiation will check that the remaining
11894 // unresolved types instantiate to the type we pick.
11895 QualType FallbackT;
11896 QualType T;
11897 for (auto *E : UPD->expansions()) {
11898 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
11899 if (ThisT.isNull())
11900 continue;
11901 else if (ThisT->getAs<UnresolvedUsingType>())
11902 FallbackT = ThisT;
11903 else if (T.isNull())
11904 T = ThisT;
11905 else
11906 assert(getSema().Context.hasSameType(ThisT, T) &&
11907 "mismatched resolved types in using pack expansion");
11908 }
11909 return T.isNull() ? FallbackT : T;
11910 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011911 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011912 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11913
11914 // A valid resolved using typename decl points to exactly one type decl.
11915 assert(++Using->shadow_begin() == Using->shadow_end());
11916 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000011917 } else {
11918 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11919 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11920 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11921 }
11922
11923 return SemaRef.Context.getTypeDeclType(Ty);
11924}
11925
11926template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011927QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11928 SourceLocation Loc) {
11929 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011930}
11931
11932template<typename Derived>
11933QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11934 return SemaRef.Context.getTypeOfType(Underlying);
11935}
11936
11937template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011938QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11939 SourceLocation Loc) {
11940 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011941}
11942
11943template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011944QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11945 UnaryTransformType::UTTKind UKind,
11946 SourceLocation Loc) {
11947 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11948}
11949
11950template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011951QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011952 TemplateName Template,
11953 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011954 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011955 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011956}
Mike Stump11289f42009-09-09 15:08:12 +000011957
Douglas Gregor1135c352009-08-06 05:28:30 +000011958template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011959QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11960 SourceLocation KWLoc) {
11961 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11962}
11963
11964template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011965QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000011966 SourceLocation KWLoc,
11967 bool isReadPipe) {
11968 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
11969 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000011970}
11971
11972template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011973TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011974TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011975 bool TemplateKW,
11976 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011977 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011978 Template);
11979}
11980
11981template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011982TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011983TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11984 const IdentifierInfo &Name,
11985 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011986 QualType ObjectType,
11987 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011988 UnqualifiedId TemplateName;
11989 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011990 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011991 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011992 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011993 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011994 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011995 /*EnteringContext=*/false,
11996 Template);
John McCall31f82722010-11-12 08:19:04 +000011997 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011998}
Mike Stump11289f42009-09-09 15:08:12 +000011999
Douglas Gregora16548e2009-08-11 05:31:07 +000012000template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012001TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012002TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012003 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012004 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012005 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012006 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012007 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012008 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012009 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000012010 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000012011 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012012 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012013 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012014 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012015 /*EnteringContext=*/false,
12016 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012017 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012018}
Chad Rosier1dcde962012-08-08 18:46:20 +000012019
Douglas Gregor71395fa2009-11-04 00:56:37 +000012020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012021ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012022TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12023 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012024 Expr *OrigCallee,
12025 Expr *First,
12026 Expr *Second) {
12027 Expr *Callee = OrigCallee->IgnoreParenCasts();
12028 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012029
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012030 if (First->getObjectKind() == OK_ObjCProperty) {
12031 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12032 if (BinaryOperator::isAssignmentOp(Opc))
12033 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12034 First, Second);
12035 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12036 if (Result.isInvalid())
12037 return ExprError();
12038 First = Result.get();
12039 }
12040
12041 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12042 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12043 if (Result.isInvalid())
12044 return ExprError();
12045 Second = Result.get();
12046 }
12047
Douglas Gregora16548e2009-08-11 05:31:07 +000012048 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012049 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012050 if (!First->getType()->isOverloadableType() &&
12051 !Second->getType()->isOverloadableType())
12052 return getSema().CreateBuiltinArraySubscriptExpr(First,
12053 Callee->getLocStart(),
12054 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012055 } else if (Op == OO_Arrow) {
12056 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012057 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12058 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012059 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012060 // The argument is not of overloadable type, so try to create a
12061 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012062 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012063 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012064
John McCallb268a282010-08-23 23:25:46 +000012065 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012066 }
12067 } else {
John McCallb268a282010-08-23 23:25:46 +000012068 if (!First->getType()->isOverloadableType() &&
12069 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012070 // Neither of the arguments is an overloadable type, so try to
12071 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012072 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012073 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012074 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012075 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012077
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012078 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012079 }
12080 }
Mike Stump11289f42009-09-09 15:08:12 +000012081
12082 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012083 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012084 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000012085
John McCallb268a282010-08-23 23:25:46 +000012086 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000012087 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000012088 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000012089 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012090 // If we've resolved this to a particular non-member function, just call
12091 // that function. If we resolved it to a member function,
12092 // CreateOverloaded* will find that function for us.
12093 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12094 if (!isa<CXXMethodDecl>(ND))
12095 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000012096 }
Mike Stump11289f42009-09-09 15:08:12 +000012097
Douglas Gregora16548e2009-08-11 05:31:07 +000012098 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012099 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012100 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012101
Douglas Gregora16548e2009-08-11 05:31:07 +000012102 // Create the overloaded operator invocation for unary operators.
12103 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012104 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012105 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000012106 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012107 }
Mike Stump11289f42009-09-09 15:08:12 +000012108
Douglas Gregore9d62932011-07-15 16:25:15 +000012109 if (Op == OO_Subscript) {
12110 SourceLocation LBrace;
12111 SourceLocation RBrace;
12112
12113 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012114 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012115 LBrace = SourceLocation::getFromRawEncoding(
12116 NameLoc.CXXOperatorName.BeginOpNameLoc);
12117 RBrace = SourceLocation::getFromRawEncoding(
12118 NameLoc.CXXOperatorName.EndOpNameLoc);
12119 } else {
12120 LBrace = Callee->getLocStart();
12121 RBrace = OpLoc;
12122 }
12123
12124 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12125 First, Second);
12126 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012127
Douglas Gregora16548e2009-08-11 05:31:07 +000012128 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012129 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012130 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012131 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12132 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012134
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012135 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012136}
Mike Stump11289f42009-09-09 15:08:12 +000012137
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012138template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012139ExprResult
John McCallb268a282010-08-23 23:25:46 +000012140TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012141 SourceLocation OperatorLoc,
12142 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012143 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012144 TypeSourceInfo *ScopeType,
12145 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012146 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012147 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012148 QualType BaseType = Base->getType();
12149 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012150 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012151 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012152 !BaseType->getAs<PointerType>()->getPointeeType()
12153 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012154 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012155 return SemaRef.BuildPseudoDestructorExpr(
12156 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12157 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012158 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012159
Douglas Gregor678f90d2010-02-25 01:56:36 +000012160 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012161 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12162 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12163 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12164 NameInfo.setNamedTypeInfo(DestroyedType);
12165
Richard Smith8e4a3862012-05-15 06:15:11 +000012166 // The scope type is now known to be a valid nested name specifier
12167 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012168 if (ScopeType) {
12169 if (!ScopeType->getType()->getAs<TagType>()) {
12170 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12171 diag::err_expected_class_or_namespace)
12172 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12173 return ExprError();
12174 }
12175 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12176 CCLoc);
12177 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012178
Abramo Bagnara7945c982012-01-27 09:46:47 +000012179 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012180 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012181 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012182 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012183 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012184 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012185 /*TemplateArgs*/ nullptr,
12186 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012187}
12188
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012189template<typename Derived>
12190StmtResult
12191TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012192 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012193 CapturedDecl *CD = S->getCapturedDecl();
12194 unsigned NumParams = CD->getNumParams();
12195 unsigned ContextParamPos = CD->getContextParamPosition();
12196 SmallVector<Sema::CapturedParamNameType, 4> Params;
12197 for (unsigned I = 0; I < NumParams; ++I) {
12198 if (I != ContextParamPos) {
12199 Params.push_back(
12200 std::make_pair(
12201 CD->getParam(I)->getName(),
12202 getDerived().TransformType(CD->getParam(I)->getType())));
12203 } else {
12204 Params.push_back(std::make_pair(StringRef(), QualType()));
12205 }
12206 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012207 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012208 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012209 StmtResult Body;
12210 {
12211 Sema::CompoundScopeRAII CompoundScope(getSema());
12212 Body = getDerived().TransformStmt(S->getCapturedStmt());
12213 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012214
12215 if (Body.isInvalid()) {
12216 getSema().ActOnCapturedRegionError();
12217 return StmtError();
12218 }
12219
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012220 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012221}
12222
Douglas Gregord6ff3322009-08-04 16:50:30 +000012223} // end namespace clang
12224
Hans Wennborg59dbe862015-09-29 20:56:43 +000012225#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H