blob: c54e194e838c93b49daae6cce5bb2c877ceba8c4 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Richard Smith03a4aa32016-06-23 19:02:52 +0000413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000431 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregorebe10102009-08-20 07:17:43 +0000439 /// \brief Transform the definition of the given declaration.
440 ///
Mike Stump11289f42009-09-09 15:08:12 +0000441 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000442 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000445 }
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000450 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000459
Douglas Gregor14454802011-02-25 02:25:35 +0000460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000470
Douglas Gregorf816bd72009-09-03 22:13:48 +0000471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000477 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000481 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000505
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// \brief Transform the given template argument.
507 ///
Mike Stump11289f42009-09-09 15:08:12 +0000508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000517
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \brief Transform the given set of template arguments.
519 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000520 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000543
544 /// \brief Transform the given set of template arguments.
545 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000546 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000548 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000549 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563
John McCall0ad16662009-10-29 08:12:44 +0000564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
John McCallbcd03502009-12-07 02:54:59 +0000568 /// \brief Fakes up a TypeSourceInfo for a type.
569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000571 getDerived().getBaseLocation());
572 }
Mike Stump11289f42009-09-09 15:08:12 +0000573
John McCall550e0c22009-10-21 00:40:46 +0000574#define ABSTRACT_TYPELOC(CLASS, PARENT)
575#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000577#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Richard Smith2e321552014-11-12 02:00:47 +0000579 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000590
David Majnemerfad8f482013-10-15 09:33:02 +0000591 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000592
Chad Rosier1dcde962012-08-08 18:46:20 +0000593 QualType
John McCall31f82722010-11-12 08:19:04 +0000594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
Chad Rosier1dcde962012-08-08 18:46:20 +0000598 QualType
John McCall31f82722010-11-12 08:19:04 +0000599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000601 TemplateName Template,
602 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000603
Nico Weberc153d242014-07-28 00:02:09 +0000604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000607
John McCall58f10c32010-03-11 09:03:00 +0000608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000615 bool TransformFunctionTypeParams(
616 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617 const QualType *ParamTypes,
618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
619 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000621
622 /// \brief Transforms a single function-type parameter. Return null
623 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000624 ///
625 /// \param indexAdjustment - A number to add to the parameter's
626 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000627 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000628 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000629 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000630 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000631
John McCall31f82722010-11-12 08:19:04 +0000632 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000633
John McCalldadc5752010-08-24 06:29:42 +0000634 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000636
Faisal Vali2cba1332013-10-23 06:44:28 +0000637 TemplateParameterList *TransformTemplateParameterList(
638 TemplateParameterList *TPL) {
639 return TPL;
640 }
641
Richard Smithdb2630f2012-10-21 03:28:35 +0000642 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000643
Richard Smithdb2630f2012-10-21 03:28:35 +0000644 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000645 bool IsAddressOfOperand,
646 TypeSourceInfo **RecoveryTSI);
647
648 ExprResult TransformParenDependentScopeDeclRefExpr(
649 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000652 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000653
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000654// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000656#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000658 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000659#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000660 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000661 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000662#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000663#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000664
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000665#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000666 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667 OMPClause *Transform ## Class(Class *S);
668#include "clang/Basic/OpenMPKinds.def"
669
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// \brief Build a new pointer type given its pointee type.
671 ///
672 /// By default, performs semantic analysis when building the pointer type.
673 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000674 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675
676 /// \brief Build a new block pointer type given its pointee type.
677 ///
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000680 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681
John McCall70dd5f62009-10-30 00:06:24 +0000682 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683 ///
John McCall70dd5f62009-10-30 00:06:24 +0000684 /// By default, performs semantic analysis when building the
685 /// reference type. Subclasses may override this routine to provide
686 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
John McCall70dd5f62009-10-30 00:06:24 +0000688 /// \param LValue whether the type was written with an lvalue sigil
689 /// or an rvalue sigil.
690 QualType RebuildReferenceType(QualType ReferentType,
691 bool LValue,
692 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new member pointer type given the pointee type and the
695 /// class type it refers into.
696 ///
697 /// By default, performs semantic analysis when building the member pointer
698 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000699 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Manman Rene6be26c2016-09-13 17:25:08 +0000702 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
703 SourceLocation ProtocolLAngleLoc,
704 ArrayRef<ObjCProtocolDecl *> Protocols,
705 ArrayRef<SourceLocation> ProtocolLocs,
706 SourceLocation ProtocolRAngleLoc);
707
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000708 /// \brief Build an Objective-C object type.
709 ///
710 /// By default, performs semantic analysis when building the object type.
711 /// Subclasses may override this routine to provide different behavior.
712 QualType RebuildObjCObjectType(QualType BaseType,
713 SourceLocation Loc,
714 SourceLocation TypeArgsLAngleLoc,
715 ArrayRef<TypeSourceInfo *> TypeArgs,
716 SourceLocation TypeArgsRAngleLoc,
717 SourceLocation ProtocolLAngleLoc,
718 ArrayRef<ObjCProtocolDecl *> Protocols,
719 ArrayRef<SourceLocation> ProtocolLocs,
720 SourceLocation ProtocolRAngleLoc);
721
722 /// \brief Build a new Objective-C object pointer type given the pointee type.
723 ///
724 /// By default, directly builds the pointer type, with no additional semantic
725 /// analysis.
726 QualType RebuildObjCObjectPointerType(QualType PointeeType,
727 SourceLocation Star);
728
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 /// \brief Build a new array type given the element type, size
730 /// modifier, size of the array (if known), size expression, and index type
731 /// qualifiers.
732 ///
733 /// By default, performs semantic analysis when building the array type.
734 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000735 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000736 QualType RebuildArrayType(QualType ElementType,
737 ArrayType::ArraySizeModifier SizeMod,
738 const llvm::APInt *Size,
739 Expr *SizeExpr,
740 unsigned IndexTypeQuals,
741 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000742
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 /// \brief Build a new constant array type given the element type, size
744 /// modifier, (known) size of the array, and index type qualifiers.
745 ///
746 /// By default, performs semantic analysis when building the array type.
747 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000748 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000749 ArrayType::ArraySizeModifier SizeMod,
750 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000751 unsigned IndexTypeQuals,
752 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 /// \brief Build a new incomplete array type given the element type, size
755 /// modifier, and index type qualifiers.
756 ///
757 /// By default, performs semantic analysis when building the array type.
758 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000759 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000761 unsigned IndexTypeQuals,
762 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763
Mike Stump11289f42009-09-09 15:08:12 +0000764 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 /// size modifier, size expression, and index type qualifiers.
766 ///
767 /// By default, performs semantic analysis when building the array type.
768 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000769 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000771 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 unsigned IndexTypeQuals,
773 SourceRange BracketsRange);
774
Mike Stump11289f42009-09-09 15:08:12 +0000775 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 /// size modifier, size expression, and index type qualifiers.
777 ///
778 /// By default, performs semantic analysis when building the array type.
779 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000780 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000781 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000782 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 unsigned IndexTypeQuals,
784 SourceRange BracketsRange);
785
786 /// \brief Build a new vector type given the element type and
787 /// number of elements.
788 ///
789 /// By default, performs semantic analysis when building the vector type.
790 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000791 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000792 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000793
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 /// \brief Build a new extended vector type given the element type and
795 /// number of elements.
796 ///
797 /// By default, performs semantic analysis when building the vector type.
798 /// Subclasses may override this routine to provide different behavior.
799 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
800 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000801
802 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 /// given the element type and number of elements.
804 ///
805 /// By default, performs semantic analysis when building the vector type.
806 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000807 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000808 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000809 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new function type.
812 ///
813 /// By default, performs semantic analysis when building the function type.
814 /// Subclasses may override this routine to provide different behavior.
815 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000816 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000817 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000818
John McCall550e0c22009-10-21 00:40:46 +0000819 /// \brief Build a new unprototyped function type.
820 QualType RebuildFunctionNoProtoType(QualType ResultType);
821
John McCallb96ec562009-12-04 22:46:56 +0000822 /// \brief Rebuild an unresolved typename type, given the decl that
823 /// the UnresolvedUsingTypenameDecl was transformed to.
824 QualType RebuildUnresolvedUsingType(Decl *D);
825
Douglas Gregord6ff3322009-08-04 16:50:30 +0000826 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000827 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 return SemaRef.Context.getTypeDeclType(Typedef);
829 }
830
831 /// \brief Build a new class/struct/union type.
832 QualType RebuildRecordType(RecordDecl *Record) {
833 return SemaRef.Context.getTypeDeclType(Record);
834 }
835
836 /// \brief Build a new Enum type.
837 QualType RebuildEnumType(EnumDecl *Enum) {
838 return SemaRef.Context.getTypeDeclType(Enum);
839 }
John McCallfcc33b02009-09-05 00:15:47 +0000840
Mike Stump11289f42009-09-09 15:08:12 +0000841 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000842 ///
843 /// By default, performs semantic analysis when building the typeof type.
844 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000845 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000846
Mike Stump11289f42009-09-09 15:08:12 +0000847 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000848 ///
849 /// By default, builds a new TypeOfType with the given underlying type.
850 QualType RebuildTypeOfType(QualType Underlying);
851
Alexis Hunte852b102011-05-24 22:41:36 +0000852 /// \brief Build a new unary transform type.
853 QualType RebuildUnaryTransformType(QualType BaseType,
854 UnaryTransformType::UTTKind UKind,
855 SourceLocation Loc);
856
Richard Smith74aeef52013-04-26 16:15:35 +0000857 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000858 ///
859 /// By default, performs semantic analysis when building the decltype type.
860 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000861 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000862
Richard Smith74aeef52013-04-26 16:15:35 +0000863 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000864 ///
865 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000866 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000867 // Note, IsDependent is always false here: we implicitly convert an 'auto'
868 // which has been deduced to a dependent type into an undeduced 'auto', so
869 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000870 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000871 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000872 }
873
Douglas Gregord6ff3322009-08-04 16:50:30 +0000874 /// \brief Build a new template specialization type.
875 ///
876 /// By default, performs semantic analysis when building the template
877 /// specialization type. Subclasses may override this routine to provide
878 /// different behavior.
879 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000880 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000881 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000882
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000883 /// \brief Build a new parenthesized type.
884 ///
885 /// By default, builds a new ParenType type from the inner type.
886 /// Subclasses may override this routine to provide different behavior.
887 QualType RebuildParenType(QualType InnerType) {
888 return SemaRef.Context.getParenType(InnerType);
889 }
890
Douglas Gregord6ff3322009-08-04 16:50:30 +0000891 /// \brief Build a new qualified name type.
892 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000893 /// By default, builds a new ElaboratedType type from the keyword,
894 /// the nested-name-specifier and the named type.
895 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000896 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
897 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000898 NestedNameSpecifierLoc QualifierLoc,
899 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 return SemaRef.Context.getElaboratedType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000902 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000903 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000904
905 /// \brief Build a new typename type that refers to a template-id.
906 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000907 /// By default, builds a new DependentNameType type from the
908 /// nested-name-specifier and the given type. Subclasses may override
909 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000910 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000911 ElaboratedTypeKeyword Keyword,
912 NestedNameSpecifierLoc QualifierLoc,
913 const IdentifierInfo *Name,
914 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000915 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000916 // Rebuild the template name.
917 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000918 CXXScopeSpec SS;
919 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000920 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000921 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
922 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000923
Douglas Gregora7a795b2011-03-01 20:11:18 +0000924 if (InstName.isNull())
925 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregora7a795b2011-03-01 20:11:18 +0000927 // If it's still dependent, make a dependent specialization.
928 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000929 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
930 QualifierLoc.getNestedNameSpecifier(),
931 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000932 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Douglas Gregora7a795b2011-03-01 20:11:18 +0000934 // Otherwise, make an elaborated type wrapping a non-dependent
935 // specialization.
936 QualType T =
937 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
938 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000939
Craig Topperc3ec1492014-05-26 06:22:03 +0000940 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000941 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000942
943 return SemaRef.Context.getElaboratedType(Keyword,
944 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000945 T);
946 }
947
Douglas Gregord6ff3322009-08-04 16:50:30 +0000948 /// \brief Build a new typename type that refers to an identifier.
949 ///
950 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000951 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000952 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000953 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 NestedNameSpecifierLoc QualifierLoc,
956 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000957 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000958 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000959 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000961 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000962 // If the name is still dependent, just build a new dependent name type.
963 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000964 return SemaRef.Context.getDependentNameType(Keyword,
965 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000966 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000967 }
968
Abramo Bagnara6150c882010-05-11 21:36:43 +0000969 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000970 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000971 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000972
973 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
974
Abramo Bagnarad7548482010-05-19 21:37:53 +0000975 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000976 // into a non-dependent elaborated-type-specifier. Find the tag we're
977 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000978 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000979 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
980 if (!DC)
981 return QualType();
982
John McCallbf8c5192010-05-27 06:40:31 +0000983 if (SemaRef.RequireCompleteDeclContext(SS, DC))
984 return QualType();
985
Craig Topperc3ec1492014-05-26 06:22:03 +0000986 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000987 SemaRef.LookupQualifiedName(Result, DC);
988 switch (Result.getResultKind()) {
989 case LookupResult::NotFound:
990 case LookupResult::NotFoundInCurrentInstantiation:
991 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000992
Douglas Gregore677daf2010-03-31 22:19:08 +0000993 case LookupResult::Found:
994 Tag = Result.getAsSingle<TagDecl>();
995 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000996
Douglas Gregore677daf2010-03-31 22:19:08 +0000997 case LookupResult::FoundOverloaded:
998 case LookupResult::FoundUnresolvedValue:
999 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001000
Douglas Gregore677daf2010-03-31 22:19:08 +00001001 case LookupResult::Ambiguous:
1002 // Let the LookupResult structure handle ambiguities.
1003 return QualType();
1004 }
1005
1006 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001007 // Check where the name exists but isn't a tag type and use that to emit
1008 // better diagnostics.
1009 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1010 SemaRef.LookupQualifiedName(Result, DC);
1011 switch (Result.getResultKind()) {
1012 case LookupResult::Found:
1013 case LookupResult::FoundOverloaded:
1014 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001015 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00001016 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl);
1017 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << NTK;
Nick Lewycky0c438082011-01-24 19:01:04 +00001018 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1019 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001020 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001021 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001022 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001023 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001024 break;
1025 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001026 return QualType();
1027 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001028
Richard Trieucaa33d32011-06-10 03:11:26 +00001029 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001030 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001031 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001032 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1033 return QualType();
1034 }
1035
1036 // Build the elaborated-type-specifier type.
1037 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001038 return SemaRef.Context.getElaboratedType(Keyword,
1039 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001040 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001041 }
Mike Stump11289f42009-09-09 15:08:12 +00001042
Douglas Gregor822d0302011-01-12 17:07:58 +00001043 /// \brief Build a new pack expansion type.
1044 ///
1045 /// By default, builds a new PackExpansionType type from the given pattern.
1046 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001047 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001048 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001049 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001050 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001051 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1052 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001053 }
1054
Eli Friedman0dfb8892011-10-06 23:00:33 +00001055 /// \brief Build a new atomic type given its value type.
1056 ///
1057 /// By default, performs semantic analysis when building the atomic type.
1058 /// Subclasses may override this routine to provide different behavior.
1059 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1060
Xiuli Pan9c14e282016-01-09 12:53:17 +00001061 /// \brief Build a new pipe type given its value type.
1062 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1063
Douglas Gregor71dc5092009-08-06 06:41:21 +00001064 /// \brief Build a new template name given a nested name specifier, a flag
1065 /// indicating whether the "template" keyword was provided, and the template
1066 /// that the template name refers to.
1067 ///
1068 /// By default, builds the new template name directly. Subclasses may override
1069 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001070 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001071 bool TemplateKW,
1072 TemplateDecl *Template);
1073
Douglas Gregor71dc5092009-08-06 06:41:21 +00001074 /// \brief Build a new template name given a nested name specifier and the
1075 /// name that is referred to as a template.
1076 ///
1077 /// By default, performs semantic analysis to determine whether the name can
1078 /// be resolved to a specific template, then builds the appropriate kind of
1079 /// template name. Subclasses may override this routine to provide different
1080 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001081 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1082 const IdentifierInfo &Name,
1083 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001084 QualType ObjectType,
1085 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001086
Douglas Gregor71395fa2009-11-04 00:56:37 +00001087 /// \brief Build a new template name given a nested name specifier and the
1088 /// overloaded operator name that is referred to as a template.
1089 ///
1090 /// By default, performs semantic analysis to determine whether the name can
1091 /// be resolved to a specific template, then builds the appropriate kind of
1092 /// template name. Subclasses may override this routine to provide different
1093 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001094 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001095 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001096 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001097 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001098
1099 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001100 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001101 ///
1102 /// By default, performs semantic analysis to determine whether the name can
1103 /// be resolved to a specific template, then builds the appropriate kind of
1104 /// template name. Subclasses may override this routine to provide different
1105 /// behavior.
1106 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1107 const TemplateArgument &ArgPack) {
1108 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1109 }
1110
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 /// \brief Build a new compound statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001115 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 MultiStmtArg Statements,
1117 SourceLocation RBraceLoc,
1118 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001119 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 IsStmtExpr);
1121 }
1122
1123 /// \brief Build a new case statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001127 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001128 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001129 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001130 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001132 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 ColonLoc);
1134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregorebe10102009-08-20 07:17:43 +00001136 /// \brief Attach the body to a new case statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001141 getSema().ActOnCaseStmtBody(S, Body);
1142 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 }
Mike Stump11289f42009-09-09 15:08:12 +00001144
Douglas Gregorebe10102009-08-20 07:17:43 +00001145 /// \brief Build a new default statement.
1146 ///
1147 /// By default, performs semantic analysis to build the new statement.
1148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001149 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001150 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001151 Stmt *SubStmt) {
1152 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001153 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001154 }
Mike Stump11289f42009-09-09 15:08:12 +00001155
Douglas Gregorebe10102009-08-20 07:17:43 +00001156 /// \brief Build a new label statement.
1157 ///
1158 /// By default, performs semantic analysis to build the new statement.
1159 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001160 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1161 SourceLocation ColonLoc, Stmt *SubStmt) {
1162 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Richard Smithc202b282012-04-14 00:33:13 +00001165 /// \brief Build a new label statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001169 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1170 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001171 Stmt *SubStmt) {
1172 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1173 }
1174
Douglas Gregorebe10102009-08-20 07:17:43 +00001175 /// \brief Build a new "if" statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001179 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001180 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001181 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001182 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001183 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001184 }
Mike Stump11289f42009-09-09 15:08:12 +00001185
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 /// \brief Start building a new switch statement.
1187 ///
1188 /// By default, performs semantic analysis to build the new statement.
1189 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001190 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001191 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001192 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 }
Mike Stump11289f42009-09-09 15:08:12 +00001194
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 /// \brief Attach the body to the switch statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001199 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001200 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001201 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new while statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001208 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1209 Sema::ConditionResult Cond, Stmt *Body) {
1210 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001211 }
Mike Stump11289f42009-09-09 15:08:12 +00001212
Douglas Gregorebe10102009-08-20 07:17:43 +00001213 /// \brief Build a new do-while statement.
1214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001217 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 SourceLocation WhileLoc, SourceLocation LParenLoc,
1219 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001220 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1221 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 }
1223
1224 /// \brief Build a new for statement.
1225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001228 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001229 Stmt *Init, Sema::ConditionResult Cond,
1230 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1231 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001232 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001233 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001234 }
Mike Stump11289f42009-09-09 15:08:12 +00001235
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 /// \brief Build a new goto statement.
1237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001240 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1241 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001242 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 }
1244
1245 /// \brief Build a new indirect goto statement.
1246 ///
1247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001249 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001250 SourceLocation StarLoc,
1251 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001252 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregorebe10102009-08-20 07:17:43 +00001255 /// \brief Build a new return statement.
1256 ///
1257 /// By default, performs semantic analysis to build the new statement.
1258 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001259 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001260 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001261 }
Mike Stump11289f42009-09-09 15:08:12 +00001262
Douglas Gregorebe10102009-08-20 07:17:43 +00001263 /// \brief Build a new declaration statement.
1264 ///
1265 /// By default, performs semantic analysis to build the new statement.
1266 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001267 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001268 SourceLocation StartLoc, SourceLocation EndLoc) {
1269 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001270 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 }
Mike Stump11289f42009-09-09 15:08:12 +00001272
Anders Carlssonaaeef072010-01-24 05:50:09 +00001273 /// \brief Build a new inline asm statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001277 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1278 bool IsVolatile, unsigned NumOutputs,
1279 unsigned NumInputs, IdentifierInfo **Names,
1280 MultiExprArg Constraints, MultiExprArg Exprs,
1281 Expr *AsmString, MultiExprArg Clobbers,
1282 SourceLocation RParenLoc) {
1283 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1284 NumInputs, Names, Constraints, Exprs,
1285 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001286 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001287
Chad Rosier32503022012-06-11 20:47:18 +00001288 /// \brief Build a new MS style inline asm statement.
1289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001292 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001293 ArrayRef<Token> AsmToks,
1294 StringRef AsmString,
1295 unsigned NumOutputs, unsigned NumInputs,
1296 ArrayRef<StringRef> Constraints,
1297 ArrayRef<StringRef> Clobbers,
1298 ArrayRef<Expr*> Exprs,
1299 SourceLocation EndLoc) {
1300 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1301 NumOutputs, NumInputs,
1302 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001303 }
1304
Richard Smith9f690bd2015-10-27 06:02:45 +00001305 /// \brief Build a new co_return statement.
1306 ///
1307 /// By default, performs semantic analysis to build the new statement.
1308 /// Subclasses may override this routine to provide different behavior.
1309 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1310 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1311 }
1312
1313 /// \brief Build a new co_await expression.
1314 ///
1315 /// By default, performs semantic analysis to build the new expression.
1316 /// Subclasses may override this routine to provide different behavior.
1317 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1318 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1319 }
1320
1321 /// \brief Build a new co_yield expression.
1322 ///
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
1325 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1326 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1327 }
1328
James Dennett2a4d13c2012-06-15 07:13:21 +00001329 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001330 ///
1331 /// By default, performs semantic analysis to build the new statement.
1332 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001333 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001334 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001335 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001336 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001337 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001338 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001339 }
1340
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001341 /// \brief Rebuild an Objective-C exception declaration.
1342 ///
1343 /// By default, performs semantic analysis to build the new declaration.
1344 /// Subclasses may override this routine to provide different behavior.
1345 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1346 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001347 return getSema().BuildObjCExceptionDecl(TInfo, T,
1348 ExceptionDecl->getInnerLocStart(),
1349 ExceptionDecl->getLocation(),
1350 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001351 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001352
James Dennett2a4d13c2012-06-15 07:13:21 +00001353 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001354 ///
1355 /// By default, performs semantic analysis to build the new statement.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001358 SourceLocation RParenLoc,
1359 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001360 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001361 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001362 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001364
James Dennett2a4d13c2012-06-15 07:13:21 +00001365 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001366 ///
1367 /// By default, performs semantic analysis to build the new statement.
1368 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001369 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001370 Stmt *Body) {
1371 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001373
James Dennett2a4d13c2012-06-15 07:13:21 +00001374 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001375 ///
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001378 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001379 Expr *Operand) {
1380 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001381 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001382
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001383 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001384 ///
1385 /// By default, performs semantic analysis to build the new statement.
1386 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001387 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001388 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001389 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001390 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001391 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001392 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001393 return getSema().ActOnOpenMPExecutableDirective(
1394 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001395 }
1396
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001397 /// \brief Build a new OpenMP 'if' clause.
1398 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001399 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001400 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001401 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1402 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001403 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001404 SourceLocation NameModifierLoc,
1405 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001406 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001407 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1408 LParenLoc, NameModifierLoc, ColonLoc,
1409 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001410 }
1411
Alexey Bataev3778b602014-07-17 07:32:53 +00001412 /// \brief Build a new OpenMP 'final' clause.
1413 ///
1414 /// By default, performs semantic analysis to build the new OpenMP clause.
1415 /// Subclasses may override this routine to provide different behavior.
1416 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1417 SourceLocation LParenLoc,
1418 SourceLocation EndLoc) {
1419 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1420 EndLoc);
1421 }
1422
Alexey Bataev568a8332014-03-06 06:15:19 +00001423 /// \brief Build a new OpenMP 'num_threads' clause.
1424 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001425 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001426 /// Subclasses may override this routine to provide different behavior.
1427 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1428 SourceLocation StartLoc,
1429 SourceLocation LParenLoc,
1430 SourceLocation EndLoc) {
1431 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1432 LParenLoc, EndLoc);
1433 }
1434
Alexey Bataev62c87d22014-03-21 04:51:18 +00001435 /// \brief Build a new OpenMP 'safelen' clause.
1436 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001437 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001438 /// Subclasses may override this routine to provide different behavior.
1439 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1440 SourceLocation LParenLoc,
1441 SourceLocation EndLoc) {
1442 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1443 }
1444
Alexey Bataev66b15b52015-08-21 11:14:16 +00001445 /// \brief Build a new OpenMP 'simdlen' clause.
1446 ///
1447 /// By default, performs semantic analysis to build the new OpenMP clause.
1448 /// Subclasses may override this routine to provide different behavior.
1449 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1450 SourceLocation LParenLoc,
1451 SourceLocation EndLoc) {
1452 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1453 }
1454
Alexander Musman8bd31e62014-05-27 15:12:19 +00001455 /// \brief Build a new OpenMP 'collapse' clause.
1456 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001457 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001458 /// Subclasses may override this routine to provide different behavior.
1459 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation EndLoc) {
1462 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1463 EndLoc);
1464 }
1465
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001466 /// \brief Build a new OpenMP 'default' clause.
1467 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001468 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001469 /// Subclasses may override this routine to provide different behavior.
1470 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1471 SourceLocation KindKwLoc,
1472 SourceLocation StartLoc,
1473 SourceLocation LParenLoc,
1474 SourceLocation EndLoc) {
1475 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1476 StartLoc, LParenLoc, EndLoc);
1477 }
1478
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001479 /// \brief Build a new OpenMP 'proc_bind' clause.
1480 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001481 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001482 /// Subclasses may override this routine to provide different behavior.
1483 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1484 SourceLocation KindKwLoc,
1485 SourceLocation StartLoc,
1486 SourceLocation LParenLoc,
1487 SourceLocation EndLoc) {
1488 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1489 StartLoc, LParenLoc, EndLoc);
1490 }
1491
Alexey Bataev56dafe82014-06-20 07:16:17 +00001492 /// \brief Build a new OpenMP 'schedule' clause.
1493 ///
1494 /// By default, performs semantic analysis to build the new OpenMP clause.
1495 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001496 OMPClause *RebuildOMPScheduleClause(
1497 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1498 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1499 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1500 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001501 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001502 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1503 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001504 }
1505
Alexey Bataev10e775f2015-07-30 11:36:16 +00001506 /// \brief Build a new OpenMP 'ordered' clause.
1507 ///
1508 /// By default, performs semantic analysis to build the new OpenMP clause.
1509 /// Subclasses may override this routine to provide different behavior.
1510 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1511 SourceLocation EndLoc,
1512 SourceLocation LParenLoc, Expr *Num) {
1513 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1514 }
1515
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001516 /// \brief Build a new OpenMP 'private' clause.
1517 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001518 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001519 /// Subclasses may override this routine to provide different behavior.
1520 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1521 SourceLocation StartLoc,
1522 SourceLocation LParenLoc,
1523 SourceLocation EndLoc) {
1524 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1525 EndLoc);
1526 }
1527
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001528 /// \brief Build a new OpenMP 'firstprivate' clause.
1529 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001530 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1533 SourceLocation StartLoc,
1534 SourceLocation LParenLoc,
1535 SourceLocation EndLoc) {
1536 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1537 EndLoc);
1538 }
1539
Alexander Musman1bb328c2014-06-04 13:06:39 +00001540 /// \brief Build a new OpenMP 'lastprivate' clause.
1541 ///
1542 /// By default, performs semantic analysis to build the new OpenMP clause.
1543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1549 EndLoc);
1550 }
1551
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001552 /// \brief Build a new OpenMP 'shared' clause.
1553 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001554 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001555 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001556 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1557 SourceLocation StartLoc,
1558 SourceLocation LParenLoc,
1559 SourceLocation EndLoc) {
1560 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1561 EndLoc);
1562 }
1563
Alexey Bataevc5e02582014-06-16 07:08:35 +00001564 /// \brief Build a new OpenMP 'reduction' clause.
1565 ///
1566 /// By default, performs semantic analysis to build the new statement.
1567 /// Subclasses may override this routine to provide different behavior.
1568 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1569 SourceLocation StartLoc,
1570 SourceLocation LParenLoc,
1571 SourceLocation ColonLoc,
1572 SourceLocation EndLoc,
1573 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001574 const DeclarationNameInfo &ReductionId,
1575 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001576 return getSema().ActOnOpenMPReductionClause(
1577 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001578 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001579 }
1580
Alexander Musman8dba6642014-04-22 13:09:42 +00001581 /// \brief Build a new OpenMP 'linear' clause.
1582 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001583 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001584 /// Subclasses may override this routine to provide different behavior.
1585 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1586 SourceLocation StartLoc,
1587 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001588 OpenMPLinearClauseKind Modifier,
1589 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001590 SourceLocation ColonLoc,
1591 SourceLocation EndLoc) {
1592 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001593 Modifier, ModifierLoc, ColonLoc,
1594 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001595 }
1596
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001597 /// \brief Build a new OpenMP 'aligned' clause.
1598 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001599 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001600 /// Subclasses may override this routine to provide different behavior.
1601 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1602 SourceLocation StartLoc,
1603 SourceLocation LParenLoc,
1604 SourceLocation ColonLoc,
1605 SourceLocation EndLoc) {
1606 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1607 LParenLoc, ColonLoc, EndLoc);
1608 }
1609
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001610 /// \brief Build a new OpenMP 'copyin' clause.
1611 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001612 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001613 /// Subclasses may override this routine to provide different behavior.
1614 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1615 SourceLocation StartLoc,
1616 SourceLocation LParenLoc,
1617 SourceLocation EndLoc) {
1618 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1619 EndLoc);
1620 }
1621
Alexey Bataevbae9a792014-06-27 10:37:06 +00001622 /// \brief Build a new OpenMP 'copyprivate' clause.
1623 ///
1624 /// By default, performs semantic analysis to build the new OpenMP clause.
1625 /// Subclasses may override this routine to provide different behavior.
1626 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1627 SourceLocation StartLoc,
1628 SourceLocation LParenLoc,
1629 SourceLocation EndLoc) {
1630 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1631 EndLoc);
1632 }
1633
Alexey Bataev6125da92014-07-21 11:26:11 +00001634 /// \brief Build a new OpenMP 'flush' pseudo clause.
1635 ///
1636 /// By default, performs semantic analysis to build the new OpenMP clause.
1637 /// Subclasses may override this routine to provide different behavior.
1638 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1639 SourceLocation StartLoc,
1640 SourceLocation LParenLoc,
1641 SourceLocation EndLoc) {
1642 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1643 EndLoc);
1644 }
1645
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001646 /// \brief Build a new OpenMP 'depend' pseudo clause.
1647 ///
1648 /// By default, performs semantic analysis to build the new OpenMP clause.
1649 /// Subclasses may override this routine to provide different behavior.
1650 OMPClause *
1651 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1652 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1653 SourceLocation StartLoc, SourceLocation LParenLoc,
1654 SourceLocation EndLoc) {
1655 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1656 StartLoc, LParenLoc, EndLoc);
1657 }
1658
Michael Wonge710d542015-08-07 16:16:36 +00001659 /// \brief Build a new OpenMP 'device' clause.
1660 ///
1661 /// By default, performs semantic analysis to build the new statement.
1662 /// Subclasses may override this routine to provide different behavior.
1663 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1664 SourceLocation LParenLoc,
1665 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001666 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001667 EndLoc);
1668 }
1669
Kelvin Li0bff7af2015-11-23 05:32:03 +00001670 /// \brief Build a new OpenMP 'map' clause.
1671 ///
1672 /// By default, performs semantic analysis to build the new OpenMP clause.
1673 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001674 OMPClause *
1675 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1676 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1677 SourceLocation MapLoc, SourceLocation ColonLoc,
1678 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1679 SourceLocation LParenLoc, SourceLocation EndLoc) {
1680 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1681 IsMapTypeImplicit, MapLoc, ColonLoc,
1682 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001683 }
1684
Kelvin Li099bb8c2015-11-24 20:50:12 +00001685 /// \brief Build a new OpenMP 'num_teams' clause.
1686 ///
1687 /// By default, performs semantic analysis to build the new statement.
1688 /// Subclasses may override this routine to provide different behavior.
1689 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1690 SourceLocation LParenLoc,
1691 SourceLocation EndLoc) {
1692 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1693 EndLoc);
1694 }
1695
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001696 /// \brief Build a new OpenMP 'thread_limit' clause.
1697 ///
1698 /// By default, performs semantic analysis to build the new statement.
1699 /// Subclasses may override this routine to provide different behavior.
1700 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1701 SourceLocation StartLoc,
1702 SourceLocation LParenLoc,
1703 SourceLocation EndLoc) {
1704 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1705 LParenLoc, EndLoc);
1706 }
1707
Alexey Bataeva0569352015-12-01 10:17:31 +00001708 /// \brief Build a new OpenMP 'priority' clause.
1709 ///
1710 /// By default, performs semantic analysis to build the new statement.
1711 /// Subclasses may override this routine to provide different behavior.
1712 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1713 SourceLocation LParenLoc,
1714 SourceLocation EndLoc) {
1715 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1716 EndLoc);
1717 }
1718
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001719 /// \brief Build a new OpenMP 'grainsize' clause.
1720 ///
1721 /// By default, performs semantic analysis to build the new statement.
1722 /// Subclasses may override this routine to provide different behavior.
1723 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1724 SourceLocation LParenLoc,
1725 SourceLocation EndLoc) {
1726 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1727 EndLoc);
1728 }
1729
Alexey Bataev382967a2015-12-08 12:06:20 +00001730 /// \brief Build a new OpenMP 'num_tasks' clause.
1731 ///
1732 /// By default, performs semantic analysis to build the new statement.
1733 /// Subclasses may override this routine to provide different behavior.
1734 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1735 SourceLocation LParenLoc,
1736 SourceLocation EndLoc) {
1737 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1738 EndLoc);
1739 }
1740
Alexey Bataev28c75412015-12-15 08:19:24 +00001741 /// \brief Build a new OpenMP 'hint' clause.
1742 ///
1743 /// By default, performs semantic analysis to build the new statement.
1744 /// Subclasses may override this routine to provide different behavior.
1745 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1746 SourceLocation LParenLoc,
1747 SourceLocation EndLoc) {
1748 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1749 }
1750
Carlo Bertollib4adf552016-01-15 18:50:31 +00001751 /// \brief Build a new OpenMP 'dist_schedule' clause.
1752 ///
1753 /// By default, performs semantic analysis to build the new OpenMP clause.
1754 /// Subclasses may override this routine to provide different behavior.
1755 OMPClause *
1756 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1757 Expr *ChunkSize, SourceLocation StartLoc,
1758 SourceLocation LParenLoc, SourceLocation KindLoc,
1759 SourceLocation CommaLoc, SourceLocation EndLoc) {
1760 return getSema().ActOnOpenMPDistScheduleClause(
1761 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1762 }
1763
Samuel Antao661c0902016-05-26 17:39:58 +00001764 /// \brief Build a new OpenMP 'to' clause.
1765 ///
1766 /// By default, performs semantic analysis to build the new statement.
1767 /// Subclasses may override this routine to provide different behavior.
1768 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1769 SourceLocation StartLoc,
1770 SourceLocation LParenLoc,
1771 SourceLocation EndLoc) {
1772 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1773 }
1774
Samuel Antaoec172c62016-05-26 17:49:04 +00001775 /// \brief Build a new OpenMP 'from' clause.
1776 ///
1777 /// By default, performs semantic analysis to build the new statement.
1778 /// Subclasses may override this routine to provide different behavior.
1779 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1780 SourceLocation StartLoc,
1781 SourceLocation LParenLoc,
1782 SourceLocation EndLoc) {
1783 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1784 EndLoc);
1785 }
1786
Carlo Bertolli2404b172016-07-13 15:37:16 +00001787 /// Build a new OpenMP 'use_device_ptr' clause.
1788 ///
1789 /// By default, performs semantic analysis to build the new OpenMP clause.
1790 /// Subclasses may override this routine to provide different behavior.
1791 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1792 SourceLocation StartLoc,
1793 SourceLocation LParenLoc,
1794 SourceLocation EndLoc) {
1795 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1796 EndLoc);
1797 }
1798
Carlo Bertolli70594e92016-07-13 17:16:49 +00001799 /// Build a new OpenMP 'is_device_ptr' clause.
1800 ///
1801 /// By default, performs semantic analysis to build the new OpenMP clause.
1802 /// Subclasses may override this routine to provide different behavior.
1803 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1804 SourceLocation StartLoc,
1805 SourceLocation LParenLoc,
1806 SourceLocation EndLoc) {
1807 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1808 EndLoc);
1809 }
1810
James Dennett2a4d13c2012-06-15 07:13:21 +00001811 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001812 ///
1813 /// By default, performs semantic analysis to build the new statement.
1814 /// Subclasses may override this routine to provide different behavior.
1815 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1816 Expr *object) {
1817 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1818 }
1819
James Dennett2a4d13c2012-06-15 07:13:21 +00001820 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001821 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001822 /// By default, performs semantic analysis to build the new statement.
1823 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001824 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001825 Expr *Object, Stmt *Body) {
1826 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001827 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001828
James Dennett2a4d13c2012-06-15 07:13:21 +00001829 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001830 ///
1831 /// By default, performs semantic analysis to build the new statement.
1832 /// Subclasses may override this routine to provide different behavior.
1833 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1834 Stmt *Body) {
1835 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1836 }
John McCall53848232011-07-27 01:07:15 +00001837
Douglas Gregorf68a5082010-04-22 23:10:45 +00001838 /// \brief Build a new Objective-C fast enumeration statement.
1839 ///
1840 /// By default, performs semantic analysis to build the new statement.
1841 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001842 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001843 Stmt *Element,
1844 Expr *Collection,
1845 SourceLocation RParenLoc,
1846 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001847 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001848 Element,
John McCallb268a282010-08-23 23:25:46 +00001849 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001850 RParenLoc);
1851 if (ForEachStmt.isInvalid())
1852 return StmtError();
1853
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001854 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001856
Douglas Gregorebe10102009-08-20 07:17:43 +00001857 /// \brief Build a new C++ exception declaration.
1858 ///
1859 /// By default, performs semantic analysis to build the new decaration.
1860 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001861 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001862 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001863 SourceLocation StartLoc,
1864 SourceLocation IdLoc,
1865 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001866 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001867 StartLoc, IdLoc, Id);
1868 if (Var)
1869 getSema().CurContext->addDecl(Var);
1870 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001871 }
1872
1873 /// \brief Build a new C++ catch statement.
1874 ///
1875 /// By default, performs semantic analysis to build the new statement.
1876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001877 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001878 VarDecl *ExceptionDecl,
1879 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001880 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1881 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001882 }
Mike Stump11289f42009-09-09 15:08:12 +00001883
Douglas Gregorebe10102009-08-20 07:17:43 +00001884 /// \brief Build a new C++ try statement.
1885 ///
1886 /// By default, performs semantic analysis to build the new statement.
1887 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001888 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1889 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001890 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001891 }
Mike Stump11289f42009-09-09 15:08:12 +00001892
Richard Smith02e85f32011-04-14 22:09:26 +00001893 /// \brief Build a new C++0x range-based for statement.
1894 ///
1895 /// By default, performs semantic analysis to build the new statement.
1896 /// Subclasses may override this routine to provide different behavior.
1897 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001898 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001899 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001900 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001901 Expr *Cond, Expr *Inc,
1902 Stmt *LoopVar,
1903 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001904 // If we've just learned that the range is actually an Objective-C
1905 // collection, treat this as an Objective-C fast enumeration loop.
1906 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1907 if (RangeStmt->isSingleDecl()) {
1908 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001909 if (RangeVar->isInvalidDecl())
1910 return StmtError();
1911
Douglas Gregorf7106af2013-04-08 18:40:13 +00001912 Expr *RangeExpr = RangeVar->getInit();
1913 if (!RangeExpr->isTypeDependent() &&
1914 RangeExpr->getType()->isObjCObjectPointerType())
1915 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1916 RParenLoc);
1917 }
1918 }
1919 }
1920
Richard Smithcfd53b42015-10-22 06:13:50 +00001921 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001922 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001923 Cond, Inc, LoopVar, RParenLoc,
1924 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001925 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001926
1927 /// \brief Build a new C++0x range-based for statement.
1928 ///
1929 /// By default, performs semantic analysis to build the new statement.
1930 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001931 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001932 bool IsIfExists,
1933 NestedNameSpecifierLoc QualifierLoc,
1934 DeclarationNameInfo NameInfo,
1935 Stmt *Nested) {
1936 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1937 QualifierLoc, NameInfo, Nested);
1938 }
1939
Richard Smith02e85f32011-04-14 22:09:26 +00001940 /// \brief Attach body to a C++0x range-based for statement.
1941 ///
1942 /// By default, performs semantic analysis to finish the new statement.
1943 /// Subclasses may override this routine to provide different behavior.
1944 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1945 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1946 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001947
David Majnemerfad8f482013-10-15 09:33:02 +00001948 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001949 Stmt *TryBlock, Stmt *Handler) {
1950 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001951 }
1952
David Majnemerfad8f482013-10-15 09:33:02 +00001953 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001954 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001955 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001956 }
1957
David Majnemerfad8f482013-10-15 09:33:02 +00001958 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001959 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001960 }
1961
Alexey Bataevec474782014-10-09 08:45:04 +00001962 /// \brief Build a new predefined expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
1966 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1967 PredefinedExpr::IdentType IT) {
1968 return getSema().BuildPredefinedExpr(Loc, IT);
1969 }
1970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new expression that references a declaration.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001976 LookupResult &R,
1977 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001978 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1979 }
1980
1981
1982 /// \brief Build a new expression that references a declaration.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001986 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001987 ValueDecl *VD,
1988 const DeclarationNameInfo &NameInfo,
1989 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001990 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001991 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001992
1993 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001994
1995 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 }
Mike Stump11289f42009-09-09 15:08:12 +00001997
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001999 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// By default, performs semantic analysis to build the new expression.
2001 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002002 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002004 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 }
2006
Douglas Gregorad8a3362009-09-04 17:36:40 +00002007 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002008 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002011 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002012 SourceLocation OperatorLoc,
2013 bool isArrow,
2014 CXXScopeSpec &SS,
2015 TypeSourceInfo *ScopeType,
2016 SourceLocation CCLoc,
2017 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002018 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002021 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002024 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002025 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002026 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002027 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 }
Mike Stump11289f42009-09-09 15:08:12 +00002029
Douglas Gregor882211c2010-04-28 22:16:22 +00002030 /// \brief Build a new builtin offsetof expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002035 TypeSourceInfo *Type,
2036 ArrayRef<Sema::OffsetOfComponent> Components,
2037 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002038 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002039 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002040 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002041
2042 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002043 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002044 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002047 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2048 SourceLocation OpLoc,
2049 UnaryExprOrTypeTrait ExprKind,
2050 SourceRange R) {
2051 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 }
2053
Peter Collingbournee190dee2011-03-11 19:24:49 +00002054 /// \brief Build a new sizeof, alignof or vec step expression with an
2055 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002056 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002059 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2060 UnaryExprOrTypeTrait ExprKind,
2061 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002062 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002063 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002066
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002067 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 }
Mike Stump11289f42009-09-09 15:08:12 +00002069
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002071 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002076 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002078 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002079 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 RBracketLoc);
2081 }
2082
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002083 /// \brief Build a new array section expression.
2084 ///
2085 /// By default, performs semantic analysis to build the new expression.
2086 /// Subclasses may override this routine to provide different behavior.
2087 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2088 Expr *LowerBound,
2089 SourceLocation ColonLoc, Expr *Length,
2090 SourceLocation RBracketLoc) {
2091 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2092 ColonLoc, Length, RBracketLoc);
2093 }
2094
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002096 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002101 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002102 Expr *ExecConfig = nullptr) {
2103 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002104 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 }
2106
2107 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002108 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002112 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002113 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002114 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002115 const DeclarationNameInfo &MemberNameInfo,
2116 ValueDecl *Member,
2117 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002118 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002119 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002120 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2121 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002122 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002123 // We have a reference to an unnamed field. This is always the
2124 // base of an anonymous struct/union member access, i.e. the
2125 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002126 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002127 assert(Member->getType()->isRecordType() &&
2128 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002129
Richard Smithcab9a7d2011-10-26 19:06:56 +00002130 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002131 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002132 QualifierLoc.getNestedNameSpecifier(),
2133 FoundDecl, Member);
2134 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002135 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002136 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002137 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002138 MemberExpr *ME = new (getSema().Context)
2139 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2140 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002141 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002142 }
Mike Stump11289f42009-09-09 15:08:12 +00002143
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002144 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002145 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002146
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002147 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002148 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002149
John McCall16df1e52010-03-30 21:47:33 +00002150 // FIXME: this involves duplicating earlier analysis in a lot of
2151 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002152 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002153 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002154 R.resolveKind();
2155
John McCallb268a282010-08-23 23:25:46 +00002156 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002157 SS, TemplateKWLoc,
2158 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002159 R, ExplicitTemplateArgs,
2160 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 }
Mike Stump11289f42009-09-09 15:08:12 +00002162
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002164 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002167 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002168 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002169 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002170 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 }
2172
2173 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002174 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002178 SourceLocation QuestionLoc,
2179 Expr *LHS,
2180 SourceLocation ColonLoc,
2181 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002182 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2183 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 }
2185
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002187 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002190 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002191 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002193 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002194 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002195 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 }
Mike Stump11289f42009-09-09 15:08:12 +00002197
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002199 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002202 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002203 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002205 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002206 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002207 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 }
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002211 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 /// By default, performs semantic analysis to build the new expression.
2213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002214 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 SourceLocation OpLoc,
2216 SourceLocation AccessorLoc,
2217 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002218
John McCall10eae182009-11-30 22:42:35 +00002219 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002220 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002221 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002222 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002223 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002224 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002225 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002226 /* TemplateArgs */ nullptr,
2227 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 }
Mike Stump11289f42009-09-09 15:08:12 +00002229
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002231 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 /// By default, performs semantic analysis to build the new expression.
2233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002234 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002235 MultiExprArg Inits,
2236 SourceLocation RBraceLoc,
2237 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002238 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002239 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002240 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002241 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002242
Douglas Gregord3d93062009-11-09 17:16:50 +00002243 // Patch in the result type we were given, which may have been computed
2244 // when the initial InitListExpr was built.
2245 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2246 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002247 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 }
Mike Stump11289f42009-09-09 15:08:12 +00002249
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002251 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// By default, performs semantic analysis to build the new expression.
2253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002255 MultiExprArg ArrayExprs,
2256 SourceLocation EqualOrColonLoc,
2257 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002258 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002259 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002261 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002264
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002265 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 }
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002269 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002270 /// By default, builds the implicit value initialization without performing
2271 /// any semantic analysis. Subclasses may override this routine to provide
2272 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002273 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002274 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 }
Mike Stump11289f42009-09-09 15:08:12 +00002276
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002278 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002281 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002282 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002283 SourceLocation RParenLoc) {
2284 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002285 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002286 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 }
2288
2289 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002290 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 /// By default, performs semantic analysis to build the new expression.
2292 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002293 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002294 MultiExprArg SubExprs,
2295 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002296 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 }
Mike Stump11289f42009-09-09 15:08:12 +00002298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002300 ///
2301 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002302 /// rather than attempting to map the label statement itself.
2303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002304 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002305 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002306 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 }
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002310 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 /// By default, performs semantic analysis to build the new expression.
2312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002313 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002314 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002316 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 }
Mike Stump11289f42009-09-09 15:08:12 +00002318
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 /// \brief Build a new __builtin_choose_expr expression.
2320 ///
2321 /// By default, performs semantic analysis to build the new expression.
2322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002323 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002324 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 SourceLocation RParenLoc) {
2326 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002327 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 RParenLoc);
2329 }
Mike Stump11289f42009-09-09 15:08:12 +00002330
Peter Collingbourne91147592011-04-15 00:35:48 +00002331 /// \brief Build a new generic selection expression.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
2335 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2336 SourceLocation DefaultLoc,
2337 SourceLocation RParenLoc,
2338 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002339 ArrayRef<TypeSourceInfo *> Types,
2340 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002341 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002342 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002343 }
2344
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 /// \brief Build a new overloaded operator call expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// The semantic analysis provides the behavior of template instantiation,
2349 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002350 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 /// argument-dependent lookup, etc. Subclasses may override this routine to
2352 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002353 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002355 Expr *Callee,
2356 Expr *First,
2357 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002358
2359 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 /// reinterpret_cast.
2361 ///
2362 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002363 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002365 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 Stmt::StmtClass Class,
2367 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002368 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 SourceLocation RAngleLoc,
2370 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002371 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 SourceLocation RParenLoc) {
2373 switch (Class) {
2374 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002375 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002376 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002377 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002378
2379 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002380 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002381 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002382 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002383
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002385 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002386 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002387 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002389
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002391 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002392 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002393 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002394
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002396 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 }
Mike Stump11289f42009-09-09 15:08:12 +00002399
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 /// \brief Build a new C++ static_cast expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002404 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002406 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 SourceLocation RAngleLoc,
2408 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002409 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002410 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002411 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002412 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002413 SourceRange(LAngleLoc, RAngleLoc),
2414 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 }
2416
2417 /// \brief Build a new C++ dynamic_cast expression.
2418 ///
2419 /// By default, performs semantic analysis to build the new expression.
2420 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002421 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002423 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 SourceLocation RAngleLoc,
2425 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002426 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002428 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002429 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002430 SourceRange(LAngleLoc, RAngleLoc),
2431 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 }
2433
2434 /// \brief Build a new C++ reinterpret_cast expression.
2435 ///
2436 /// By default, performs semantic analysis to build the new expression.
2437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002438 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002440 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 SourceLocation RAngleLoc,
2442 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002443 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002445 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002446 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002447 SourceRange(LAngleLoc, RAngleLoc),
2448 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002449 }
2450
2451 /// \brief Build a new C++ const_cast expression.
2452 ///
2453 /// By default, performs semantic analysis to build the new expression.
2454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002455 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002456 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002457 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002458 SourceLocation RAngleLoc,
2459 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002460 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002462 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002463 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002464 SourceRange(LAngleLoc, RAngleLoc),
2465 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 }
Mike Stump11289f42009-09-09 15:08:12 +00002467
Douglas Gregora16548e2009-08-11 05:31:07 +00002468 /// \brief Build a new C++ functional-style cast expression.
2469 ///
2470 /// By default, performs semantic analysis to build the new expression.
2471 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002472 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2473 SourceLocation LParenLoc,
2474 Expr *Sub,
2475 SourceLocation RParenLoc) {
2476 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002477 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 RParenLoc);
2479 }
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregora16548e2009-08-11 05:31:07 +00002481 /// \brief Build a new C++ typeid(type) expression.
2482 ///
2483 /// By default, performs semantic analysis to build the new expression.
2484 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002485 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002486 SourceLocation TypeidLoc,
2487 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002489 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002490 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002491 }
Mike Stump11289f42009-09-09 15:08:12 +00002492
Francois Pichet9f4f2072010-09-08 12:20:18 +00002493
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 /// \brief Build a new C++ typeid(expr) expression.
2495 ///
2496 /// By default, performs semantic analysis to build the new expression.
2497 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002498 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002499 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002500 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002501 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002502 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002503 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002504 }
2505
Francois Pichet9f4f2072010-09-08 12:20:18 +00002506 /// \brief Build a new C++ __uuidof(type) expression.
2507 ///
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
2510 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2511 SourceLocation TypeidLoc,
2512 TypeSourceInfo *Operand,
2513 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002514 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002515 RParenLoc);
2516 }
2517
2518 /// \brief Build a new C++ __uuidof(expr) expression.
2519 ///
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// Subclasses may override this routine to provide different behavior.
2522 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2523 SourceLocation TypeidLoc,
2524 Expr *Operand,
2525 SourceLocation RParenLoc) {
2526 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2527 RParenLoc);
2528 }
2529
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 /// \brief Build a new C++ "this" expression.
2531 ///
2532 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002533 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002534 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002535 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002536 QualType ThisType,
2537 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002538 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002539 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002540 }
2541
2542 /// \brief Build a new C++ throw expression.
2543 ///
2544 /// By default, performs semantic analysis to build the new expression.
2545 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002546 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2547 bool IsThrownVariableInScope) {
2548 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002549 }
2550
2551 /// \brief Build a new C++ default-argument expression.
2552 ///
2553 /// By default, builds a new default-argument expression, which does not
2554 /// require any semantic analysis. Subclasses may override this routine to
2555 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002556 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002557 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002558 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002559 }
2560
Richard Smith852c9db2013-04-20 22:23:05 +00002561 /// \brief Build a new C++11 default-initialization expression.
2562 ///
2563 /// By default, builds a new default field initialization expression, which
2564 /// does not require any semantic analysis. Subclasses may override this
2565 /// routine to provide different behavior.
2566 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2567 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002568 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002569 }
2570
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 /// \brief Build a new C++ zero-initialization expression.
2572 ///
2573 /// By default, performs semantic analysis to build the new expression.
2574 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002575 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2576 SourceLocation LParenLoc,
2577 SourceLocation RParenLoc) {
2578 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002579 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 }
Mike Stump11289f42009-09-09 15:08:12 +00002581
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 /// \brief Build a new C++ "new" expression.
2583 ///
2584 /// By default, performs semantic analysis to build the new expression.
2585 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002586 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002587 bool UseGlobal,
2588 SourceLocation PlacementLParen,
2589 MultiExprArg PlacementArgs,
2590 SourceLocation PlacementRParen,
2591 SourceRange TypeIdParens,
2592 QualType AllocatedType,
2593 TypeSourceInfo *AllocatedTypeInfo,
2594 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002595 SourceRange DirectInitRange,
2596 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002597 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002599 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002601 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002602 AllocatedType,
2603 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002604 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002605 DirectInitRange,
2606 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002607 }
Mike Stump11289f42009-09-09 15:08:12 +00002608
Douglas Gregora16548e2009-08-11 05:31:07 +00002609 /// \brief Build a new C++ "delete" expression.
2610 ///
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002613 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 bool IsGlobalDelete,
2615 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002616 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002618 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002619 }
Mike Stump11289f42009-09-09 15:08:12 +00002620
Douglas Gregor29c42f22012-02-24 07:38:34 +00002621 /// \brief Build a new type trait expression.
2622 ///
2623 /// By default, performs semantic analysis to build the new expression.
2624 /// Subclasses may override this routine to provide different behavior.
2625 ExprResult RebuildTypeTrait(TypeTrait Trait,
2626 SourceLocation StartLoc,
2627 ArrayRef<TypeSourceInfo *> Args,
2628 SourceLocation RParenLoc) {
2629 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002631
John Wiegley6242b6a2011-04-28 00:16:57 +00002632 /// \brief Build a new array type trait expression.
2633 ///
2634 /// By default, performs semantic analysis to build the new expression.
2635 /// Subclasses may override this routine to provide different behavior.
2636 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2637 SourceLocation StartLoc,
2638 TypeSourceInfo *TSInfo,
2639 Expr *DimExpr,
2640 SourceLocation RParenLoc) {
2641 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2642 }
2643
John Wiegleyf9f65842011-04-25 06:54:41 +00002644 /// \brief Build a new expression trait expression.
2645 ///
2646 /// By default, performs semantic analysis to build the new expression.
2647 /// Subclasses may override this routine to provide different behavior.
2648 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2649 SourceLocation StartLoc,
2650 Expr *Queried,
2651 SourceLocation RParenLoc) {
2652 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2653 }
2654
Mike Stump11289f42009-09-09 15:08:12 +00002655 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002656 /// expression.
2657 ///
2658 /// By default, performs semantic analysis to build the new expression.
2659 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002660 ExprResult RebuildDependentScopeDeclRefExpr(
2661 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002662 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002663 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002664 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002665 bool IsAddressOfOperand,
2666 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002667 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002668 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002669
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002670 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002671 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2672 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002673
Reid Kleckner32506ed2014-06-12 23:03:48 +00002674 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002675 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002676 }
2677
2678 /// \brief Build a new template-id expression.
2679 ///
2680 /// By default, performs semantic analysis to build the new expression.
2681 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002682 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002683 SourceLocation TemplateKWLoc,
2684 LookupResult &R,
2685 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002686 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002687 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2688 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002689 }
2690
2691 /// \brief Build a new object-construction expression.
2692 ///
2693 /// By default, performs semantic analysis to build the new expression.
2694 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002695 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002696 SourceLocation Loc,
2697 CXXConstructorDecl *Constructor,
2698 bool IsElidable,
2699 MultiExprArg Args,
2700 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002701 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002702 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002703 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002704 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002705 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002706 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002707 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002708 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002709 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002710
Richard Smithc83bf822016-06-10 00:58:19 +00002711 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002712 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002713 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002714 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002715 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002716 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002717 RequiresZeroInit, ConstructKind,
2718 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 }
2720
Richard Smith5179eb72016-06-28 19:03:57 +00002721 /// \brief Build a new implicit construction via inherited constructor
2722 /// expression.
2723 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2724 CXXConstructorDecl *Constructor,
2725 bool ConstructsVBase,
2726 bool InheritedFromVBase) {
2727 return new (getSema().Context) CXXInheritedCtorInitExpr(
2728 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2729 }
2730
Douglas Gregora16548e2009-08-11 05:31:07 +00002731 /// \brief Build a new object-construction expression.
2732 ///
2733 /// By default, performs semantic analysis to build the new expression.
2734 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002735 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2736 SourceLocation LParenLoc,
2737 MultiExprArg Args,
2738 SourceLocation RParenLoc) {
2739 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002740 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002741 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 RParenLoc);
2743 }
2744
2745 /// \brief Build a new object-construction expression.
2746 ///
2747 /// By default, performs semantic analysis to build the new expression.
2748 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002749 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2750 SourceLocation LParenLoc,
2751 MultiExprArg Args,
2752 SourceLocation RParenLoc) {
2753 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002754 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002755 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 RParenLoc);
2757 }
Mike Stump11289f42009-09-09 15:08:12 +00002758
Douglas Gregora16548e2009-08-11 05:31:07 +00002759 /// \brief Build a new member reference expression.
2760 ///
2761 /// By default, performs semantic analysis to build the new expression.
2762 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002763 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002764 QualType BaseType,
2765 bool IsArrow,
2766 SourceLocation OperatorLoc,
2767 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002768 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002769 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002770 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002771 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002772 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002773 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002774
John McCallb268a282010-08-23 23:25:46 +00002775 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002776 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002777 SS, TemplateKWLoc,
2778 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002779 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002780 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002781 }
2782
John McCall10eae182009-11-30 22:42:35 +00002783 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002784 ///
2785 /// By default, performs semantic analysis to build the new expression.
2786 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002787 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2788 SourceLocation OperatorLoc,
2789 bool IsArrow,
2790 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002791 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002792 NamedDecl *FirstQualifierInScope,
2793 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002794 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002795 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002796 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002797
John McCallb268a282010-08-23 23:25:46 +00002798 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002799 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002800 SS, TemplateKWLoc,
2801 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002802 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002803 }
Mike Stump11289f42009-09-09 15:08:12 +00002804
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002805 /// \brief Build a new noexcept expression.
2806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2809 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2810 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2811 }
2812
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002813 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002814 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2815 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002816 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002817 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002818 Optional<unsigned> Length,
2819 ArrayRef<TemplateArgument> PartialArgs) {
2820 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2821 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002822 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002823
Patrick Beard0caa3942012-04-19 00:25:12 +00002824 /// \brief Build a new Objective-C boxed expression.
2825 ///
2826 /// By default, performs semantic analysis to build the new expression.
2827 /// Subclasses may override this routine to provide different behavior.
2828 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2829 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002831
Ted Kremeneke65b0862012-03-06 20:05:56 +00002832 /// \brief Build a new Objective-C array literal.
2833 ///
2834 /// By default, performs semantic analysis to build the new expression.
2835 /// Subclasses may override this routine to provide different behavior.
2836 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2837 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002838 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002839 MultiExprArg(Elements, NumElements));
2840 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002841
2842 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002843 Expr *Base, Expr *Key,
2844 ObjCMethodDecl *getterMethod,
2845 ObjCMethodDecl *setterMethod) {
2846 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2847 getterMethod, setterMethod);
2848 }
2849
2850 /// \brief Build a new Objective-C dictionary literal.
2851 ///
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
2854 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002855 MutableArrayRef<ObjCDictionaryElement> Elements) {
2856 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002857 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002858
James Dennett2a4d13c2012-06-15 07:13:21 +00002859 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002860 ///
2861 /// By default, performs semantic analysis to build the new expression.
2862 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002863 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002864 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002865 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002866 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002867 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002868
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002869 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002870 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002871 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002872 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002873 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002874 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002875 MultiExprArg Args,
2876 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002877 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2878 ReceiverTypeInfo->getType(),
2879 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002880 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002881 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002882 }
2883
2884 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002885 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002886 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002887 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002888 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002889 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002890 MultiExprArg Args,
2891 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002892 return SemaRef.BuildInstanceMessage(Receiver,
2893 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002894 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002895 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002896 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002897 }
2898
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002899 /// \brief Build a new Objective-C instance/class message to 'super'.
2900 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2901 Selector Sel,
2902 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002903 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002904 ObjCMethodDecl *Method,
2905 SourceLocation LBracLoc,
2906 MultiExprArg Args,
2907 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002908 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002909 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002910 SuperLoc,
2911 Sel, Method, LBracLoc, SelectorLocs,
2912 RBracLoc, Args)
2913 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002914 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002915 SuperLoc,
2916 Sel, Method, LBracLoc, SelectorLocs,
2917 RBracLoc, Args);
2918
2919
2920 }
2921
Douglas Gregord51d90d2010-04-26 20:11:03 +00002922 /// \brief Build a new Objective-C ivar reference expression.
2923 ///
2924 /// By default, performs semantic analysis to build the new expression.
2925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002926 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002927 SourceLocation IvarLoc,
2928 bool IsArrow, bool IsFreeIvar) {
2929 // FIXME: We lose track of the IsFreeIvar bit.
2930 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002931 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2932 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002933 /*FIXME:*/IvarLoc, IsArrow,
2934 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002935 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002936 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002937 /*TemplateArgs=*/nullptr,
2938 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002939 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002940
2941 /// \brief Build a new Objective-C property reference expression.
2942 ///
2943 /// By default, performs semantic analysis to build the new expression.
2944 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002945 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002946 ObjCPropertyDecl *Property,
2947 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002948 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002949 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2950 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2951 /*FIXME:*/PropertyLoc,
2952 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002953 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002954 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002955 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002956 /*TemplateArgs=*/nullptr,
2957 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002959
John McCallb7bd14f2010-12-02 01:19:52 +00002960 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002961 ///
2962 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002963 /// Subclasses may override this routine to provide different behavior.
2964 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2965 ObjCMethodDecl *Getter,
2966 ObjCMethodDecl *Setter,
2967 SourceLocation PropertyLoc) {
2968 // Since these expressions can only be value-dependent, we do not
2969 // need to perform semantic analysis again.
2970 return Owned(
2971 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2972 VK_LValue, OK_ObjCProperty,
2973 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002974 }
2975
Douglas Gregord51d90d2010-04-26 20:11:03 +00002976 /// \brief Build a new Objective-C "isa" expression.
2977 ///
2978 /// By default, performs semantic analysis to build the new expression.
2979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002980 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002981 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002982 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002983 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2984 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002985 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002986 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002987 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002988 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002989 /*TemplateArgs=*/nullptr,
2990 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002992
Douglas Gregora16548e2009-08-11 05:31:07 +00002993 /// \brief Build a new shuffle vector expression.
2994 ///
2995 /// By default, performs semantic analysis to build the new expression.
2996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002997 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002998 MultiExprArg SubExprs,
2999 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003000 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003001 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003002 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3003 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3004 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003005 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003006
Douglas Gregora16548e2009-08-11 05:31:07 +00003007 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003008 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003009 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3010 SemaRef.Context.BuiltinFnTy,
3011 VK_RValue, BuiltinLoc);
3012 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3013 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003014 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003015
3016 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003017 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003018 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003019 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003020
Douglas Gregora16548e2009-08-11 05:31:07 +00003021 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003022 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003023 }
John McCall31f82722010-11-12 08:19:04 +00003024
Hal Finkelc4d7c822013-09-18 03:29:45 +00003025 /// \brief Build a new convert vector expression.
3026 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3027 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3028 SourceLocation RParenLoc) {
3029 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3030 BuiltinLoc, RParenLoc);
3031 }
3032
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003033 /// \brief Build a new template argument pack expansion.
3034 ///
3035 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003036 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003037 /// different behavior.
3038 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003039 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003040 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003041 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003042 case TemplateArgument::Expression: {
3043 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003044 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3045 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003046 if (Result.isInvalid())
3047 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003048
Douglas Gregor98318c22011-01-03 21:37:45 +00003049 return TemplateArgumentLoc(Result.get(), Result.get());
3050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003051
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003052 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003053 return TemplateArgumentLoc(TemplateArgument(
3054 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003055 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003056 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003057 Pattern.getTemplateNameLoc(),
3058 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003060 case TemplateArgument::Null:
3061 case TemplateArgument::Integral:
3062 case TemplateArgument::Declaration:
3063 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003064 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003065 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003066 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003067
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003068 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003069 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003070 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003071 EllipsisLoc,
3072 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003073 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3074 Expansion);
3075 break;
3076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003078 return TemplateArgumentLoc();
3079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003080
Douglas Gregor968f23a2011-01-03 19:31:53 +00003081 /// \brief Build a new expression pack expansion.
3082 ///
3083 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003084 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003085 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003086 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003087 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003088 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003089 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003090
Richard Smith0f0af192014-11-08 05:07:16 +00003091 /// \brief Build a new C++1z fold-expression.
3092 ///
3093 /// By default, performs semantic analysis in order to build a new fold
3094 /// expression.
3095 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3096 BinaryOperatorKind Operator,
3097 SourceLocation EllipsisLoc, Expr *RHS,
3098 SourceLocation RParenLoc) {
3099 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3100 RHS, RParenLoc);
3101 }
3102
3103 /// \brief Build an empty C++1z fold-expression with the given operator.
3104 ///
3105 /// By default, produces the fallback value for the fold-expression, or
3106 /// produce an error if there is no fallback value.
3107 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3108 BinaryOperatorKind Operator) {
3109 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3110 }
3111
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003112 /// \brief Build a new atomic operation expression.
3113 ///
3114 /// By default, performs semantic analysis to build the new expression.
3115 /// Subclasses may override this routine to provide different behavior.
3116 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3117 MultiExprArg SubExprs,
3118 QualType RetTy,
3119 AtomicExpr::AtomicOp Op,
3120 SourceLocation RParenLoc) {
3121 // Just create the expression; there is not any interesting semantic
3122 // analysis here because we can't actually build an AtomicExpr until
3123 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003124 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003125 RParenLoc);
3126 }
3127
John McCall31f82722010-11-12 08:19:04 +00003128private:
Douglas Gregor14454802011-02-25 02:25:35 +00003129 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3130 QualType ObjectType,
3131 NamedDecl *FirstQualifierInScope,
3132 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003133
3134 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3135 QualType ObjectType,
3136 NamedDecl *FirstQualifierInScope,
3137 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003138
3139 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3140 NamedDecl *FirstQualifierInScope,
3141 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142};
Douglas Gregora16548e2009-08-11 05:31:07 +00003143
Douglas Gregorebe10102009-08-20 07:17:43 +00003144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003145StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003146 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003147 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregorebe10102009-08-20 07:17:43 +00003149 switch (S->getStmtClass()) {
3150 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003151
Douglas Gregorebe10102009-08-20 07:17:43 +00003152 // Transform individual statement nodes
3153#define STMT(Node, Parent) \
3154 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003155#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003156#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003157#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregorebe10102009-08-20 07:17:43 +00003159 // Transform expressions by calling TransformExpr.
3160#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003161#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003162#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003163#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003164 {
John McCalldadc5752010-08-24 06:29:42 +00003165 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003166 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003167 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003168
Richard Smith945f8d32013-01-14 22:39:08 +00003169 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003170 }
Mike Stump11289f42009-09-09 15:08:12 +00003171 }
3172
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003173 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003174}
Mike Stump11289f42009-09-09 15:08:12 +00003175
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003176template<typename Derived>
3177OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3178 if (!S)
3179 return S;
3180
3181 switch (S->getClauseKind()) {
3182 default: break;
3183 // Transform individual clause nodes
3184#define OPENMP_CLAUSE(Name, Class) \
3185 case OMPC_ ## Name : \
3186 return getDerived().Transform ## Class(cast<Class>(S));
3187#include "clang/Basic/OpenMPKinds.def"
3188 }
3189
3190 return S;
3191}
3192
Mike Stump11289f42009-09-09 15:08:12 +00003193
Douglas Gregore922c772009-08-04 22:27:00 +00003194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003195ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003196 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003197 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003198
3199 switch (E->getStmtClass()) {
3200 case Stmt::NoStmtClass: break;
3201#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003202#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003203#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003204 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003205#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003206 }
3207
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003208 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003209}
3210
3211template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003212ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003213 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003214 // Initializers are instantiated like expressions, except that various outer
3215 // layers are stripped.
3216 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003217 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003218
3219 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3220 Init = ExprTemp->getSubExpr();
3221
Richard Smithe6ca4752013-05-30 22:40:16 +00003222 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3223 Init = MTE->GetTemporaryExpr();
3224
Richard Smithd59b8322012-12-19 01:39:02 +00003225 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3226 Init = Binder->getSubExpr();
3227
3228 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3229 Init = ICE->getSubExprAsWritten();
3230
Richard Smithcc1b96d2013-06-12 22:31:48 +00003231 if (CXXStdInitializerListExpr *ILE =
3232 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003233 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003234
Richard Smithc6abd962014-07-25 01:12:44 +00003235 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003236 // InitListExprs. Other forms of copy-initialization will be a no-op if
3237 // the initializer is already the right type.
3238 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003239 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003240 return getDerived().TransformExpr(Init);
3241
3242 // Revert value-initialization back to empty parens.
3243 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3244 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003245 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003246 Parens.getEnd());
3247 }
3248
3249 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3250 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003251 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003252 SourceLocation());
3253
3254 // Revert initialization by constructor back to a parenthesized or braced list
3255 // of expressions. Any other form of initializer can just be reused directly.
3256 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003257 return getDerived().TransformExpr(Init);
3258
Richard Smithf8adcdc2014-07-17 05:12:35 +00003259 // If the initialization implicitly converted an initializer list to a
3260 // std::initializer_list object, unwrap the std::initializer_list too.
3261 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003262 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003263
Richard Smithd59b8322012-12-19 01:39:02 +00003264 SmallVector<Expr*, 8> NewArgs;
3265 bool ArgChanged = false;
3266 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003267 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003268 return ExprError();
3269
3270 // If this was list initialization, revert to list form.
3271 if (Construct->isListInitialization())
3272 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3273 Construct->getLocEnd(),
3274 Construct->getType());
3275
Richard Smithd59b8322012-12-19 01:39:02 +00003276 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003277 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003278 if (Parens.isInvalid()) {
3279 // This was a variable declaration's initialization for which no initializer
3280 // was specified.
3281 assert(NewArgs.empty() &&
3282 "no parens or braces but have direct init with arguments?");
3283 return ExprEmpty();
3284 }
Richard Smithd59b8322012-12-19 01:39:02 +00003285 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3286 Parens.getEnd());
3287}
3288
3289template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003290bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003291 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003292 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003293 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003294 bool *ArgChanged) {
3295 for (unsigned I = 0; I != NumInputs; ++I) {
3296 // If requested, drop call arguments that need to be dropped.
3297 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3298 if (ArgChanged)
3299 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregora3efea12011-01-03 19:04:46 +00003301 break;
3302 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003303
Douglas Gregor968f23a2011-01-03 19:31:53 +00003304 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3305 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003306
Chris Lattner01cf8db2011-07-20 06:58:45 +00003307 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003308 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3309 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor968f23a2011-01-03 19:31:53 +00003311 // Determine whether the set of unexpanded parameter packs can and should
3312 // be expanded.
3313 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003314 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003315 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3316 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003317 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3318 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003319 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003320 Expand, RetainExpansion,
3321 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003322 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003323
Douglas Gregor968f23a2011-01-03 19:31:53 +00003324 if (!Expand) {
3325 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003326 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003327 // expansion.
3328 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3329 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3330 if (OutPattern.isInvalid())
3331 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003332
3333 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003334 Expansion->getEllipsisLoc(),
3335 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003336 if (Out.isInvalid())
3337 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregor968f23a2011-01-03 19:31:53 +00003339 if (ArgChanged)
3340 *ArgChanged = true;
3341 Outputs.push_back(Out.get());
3342 continue;
3343 }
John McCall542e7c62011-07-06 07:30:07 +00003344
3345 // Record right away that the argument was changed. This needs
3346 // to happen even if the array expands to nothing.
3347 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003348
Douglas Gregor968f23a2011-01-03 19:31:53 +00003349 // The transform has determined that we should perform an elementwise
3350 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003351 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003352 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3353 ExprResult Out = getDerived().TransformExpr(Pattern);
3354 if (Out.isInvalid())
3355 return true;
3356
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003357 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003358 Out = getDerived().RebuildPackExpansion(
3359 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003360 if (Out.isInvalid())
3361 return true;
3362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Douglas Gregor968f23a2011-01-03 19:31:53 +00003364 Outputs.push_back(Out.get());
3365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003366
Richard Smith9467be42014-06-06 17:33:35 +00003367 // If we're supposed to retain a pack expansion, do so by temporarily
3368 // forgetting the partially-substituted parameter pack.
3369 if (RetainExpansion) {
3370 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3371
3372 ExprResult Out = getDerived().TransformExpr(Pattern);
3373 if (Out.isInvalid())
3374 return true;
3375
3376 Out = getDerived().RebuildPackExpansion(
3377 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3378 if (Out.isInvalid())
3379 return true;
3380
3381 Outputs.push_back(Out.get());
3382 }
3383
Douglas Gregor968f23a2011-01-03 19:31:53 +00003384 continue;
3385 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003386
Richard Smithd59b8322012-12-19 01:39:02 +00003387 ExprResult Result =
3388 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3389 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003390 if (Result.isInvalid())
3391 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregora3efea12011-01-03 19:04:46 +00003393 if (Result.get() != Inputs[I] && ArgChanged)
3394 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003395
3396 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003398
Douglas Gregora3efea12011-01-03 19:04:46 +00003399 return false;
3400}
3401
Richard Smith03a4aa32016-06-23 19:02:52 +00003402template <typename Derived>
3403Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3404 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3405 if (Var) {
3406 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3407 getDerived().TransformDefinition(Var->getLocation(), Var));
3408
3409 if (!ConditionVar)
3410 return Sema::ConditionError();
3411
3412 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3413 }
3414
3415 if (Expr) {
3416 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3417
3418 if (CondExpr.isInvalid())
3419 return Sema::ConditionError();
3420
3421 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3422 }
3423
3424 return Sema::ConditionResult();
3425}
3426
Douglas Gregora3efea12011-01-03 19:04:46 +00003427template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003428NestedNameSpecifierLoc
3429TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3430 NestedNameSpecifierLoc NNS,
3431 QualType ObjectType,
3432 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003433 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003434 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003435 Qualifier = Qualifier.getPrefix())
3436 Qualifiers.push_back(Qualifier);
3437
3438 CXXScopeSpec SS;
3439 while (!Qualifiers.empty()) {
3440 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3441 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003442
Douglas Gregor14454802011-02-25 02:25:35 +00003443 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003444 case NestedNameSpecifier::Identifier: {
3445 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3446 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3447 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3448 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003449 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003450 }
Douglas Gregor14454802011-02-25 02:25:35 +00003451 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003452
Douglas Gregor14454802011-02-25 02:25:35 +00003453 case NestedNameSpecifier::Namespace: {
3454 NamespaceDecl *NS
3455 = cast_or_null<NamespaceDecl>(
3456 getDerived().TransformDecl(
3457 Q.getLocalBeginLoc(),
3458 QNNS->getAsNamespace()));
3459 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3460 break;
3461 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
Douglas Gregor14454802011-02-25 02:25:35 +00003463 case NestedNameSpecifier::NamespaceAlias: {
3464 NamespaceAliasDecl *Alias
3465 = cast_or_null<NamespaceAliasDecl>(
3466 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3467 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003468 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003469 Q.getLocalEndLoc());
3470 break;
3471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregor14454802011-02-25 02:25:35 +00003473 case NestedNameSpecifier::Global:
3474 // There is no meaningful transformation that one could perform on the
3475 // global scope.
3476 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3477 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003478
Nikola Smiljanic67860242014-09-26 00:28:20 +00003479 case NestedNameSpecifier::Super: {
3480 CXXRecordDecl *RD =
3481 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3482 SourceLocation(), QNNS->getAsRecordDecl()));
3483 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3484 break;
3485 }
3486
Douglas Gregor14454802011-02-25 02:25:35 +00003487 case NestedNameSpecifier::TypeSpecWithTemplate:
3488 case NestedNameSpecifier::TypeSpec: {
3489 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3490 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003491
Douglas Gregor14454802011-02-25 02:25:35 +00003492 if (!TL)
3493 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
Douglas Gregor14454802011-02-25 02:25:35 +00003495 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003496 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003497 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003498 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003499 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003500 if (TL.getType()->isEnumeralType())
3501 SemaRef.Diag(TL.getBeginLoc(),
3502 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003503 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3504 Q.getLocalEndLoc());
3505 break;
3506 }
Richard Trieude756fb2011-05-07 01:36:37 +00003507 // If the nested-name-specifier is an invalid type def, don't emit an
3508 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003509 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3510 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003511 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003512 << TL.getType() << SS.getRange();
3513 }
Douglas Gregor14454802011-02-25 02:25:35 +00003514 return NestedNameSpecifierLoc();
3515 }
Douglas Gregore16af532011-02-28 18:50:33 +00003516 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Douglas Gregore16af532011-02-28 18:50:33 +00003518 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003519 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003520 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003522
Douglas Gregor14454802011-02-25 02:25:35 +00003523 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003524 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003525 !getDerived().AlwaysRebuild())
3526 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003527
3528 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003529 // nested-name-specifier, do so.
3530 if (SS.location_size() == NNS.getDataLength() &&
3531 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3532 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3533
3534 // Allocate new nested-name-specifier location information.
3535 return SS.getWithLocInContext(SemaRef.Context);
3536}
3537
3538template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003539DeclarationNameInfo
3540TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003541::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003542 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003543 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003544 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003545
3546 switch (Name.getNameKind()) {
3547 case DeclarationName::Identifier:
3548 case DeclarationName::ObjCZeroArgSelector:
3549 case DeclarationName::ObjCOneArgSelector:
3550 case DeclarationName::ObjCMultiArgSelector:
3551 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003552 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003553 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003554 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003555
Douglas Gregorf816bd72009-09-03 22:13:48 +00003556 case DeclarationName::CXXConstructorName:
3557 case DeclarationName::CXXDestructorName:
3558 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003559 TypeSourceInfo *NewTInfo;
3560 CanQualType NewCanTy;
3561 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003562 NewTInfo = getDerived().TransformType(OldTInfo);
3563 if (!NewTInfo)
3564 return DeclarationNameInfo();
3565 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003566 }
3567 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003568 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003569 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003570 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003571 if (NewT.isNull())
3572 return DeclarationNameInfo();
3573 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3574 }
Mike Stump11289f42009-09-09 15:08:12 +00003575
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003576 DeclarationName NewName
3577 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3578 NewCanTy);
3579 DeclarationNameInfo NewNameInfo(NameInfo);
3580 NewNameInfo.setName(NewName);
3581 NewNameInfo.setNamedTypeInfo(NewTInfo);
3582 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003583 }
Mike Stump11289f42009-09-09 15:08:12 +00003584 }
3585
David Blaikie83d382b2011-09-23 05:06:16 +00003586 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003587}
3588
3589template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003590TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003591TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3592 TemplateName Name,
3593 SourceLocation NameLoc,
3594 QualType ObjectType,
3595 NamedDecl *FirstQualifierInScope) {
3596 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3597 TemplateDecl *Template = QTN->getTemplateDecl();
3598 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
Douglas Gregor9db53502011-03-02 18:07:45 +00003600 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003601 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003602 Template));
3603 if (!TransTemplate)
3604 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Douglas Gregor9db53502011-03-02 18:07:45 +00003606 if (!getDerived().AlwaysRebuild() &&
3607 SS.getScopeRep() == QTN->getQualifier() &&
3608 TransTemplate == Template)
3609 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003610
Douglas Gregor9db53502011-03-02 18:07:45 +00003611 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3612 TransTemplate);
3613 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003614
Douglas Gregor9db53502011-03-02 18:07:45 +00003615 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3616 if (SS.getScopeRep()) {
3617 // These apply to the scope specifier, not the template.
3618 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003619 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003620 }
3621
Douglas Gregor9db53502011-03-02 18:07:45 +00003622 if (!getDerived().AlwaysRebuild() &&
3623 SS.getScopeRep() == DTN->getQualifier() &&
3624 ObjectType.isNull())
3625 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregor9db53502011-03-02 18:07:45 +00003627 if (DTN->isIdentifier()) {
3628 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003629 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003630 NameLoc,
3631 ObjectType,
3632 FirstQualifierInScope);
3633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003634
Douglas Gregor9db53502011-03-02 18:07:45 +00003635 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3636 ObjectType);
3637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003638
Douglas Gregor9db53502011-03-02 18:07:45 +00003639 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3640 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003641 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003642 Template));
3643 if (!TransTemplate)
3644 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor9db53502011-03-02 18:07:45 +00003646 if (!getDerived().AlwaysRebuild() &&
3647 TransTemplate == Template)
3648 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003649
Douglas Gregor9db53502011-03-02 18:07:45 +00003650 return TemplateName(TransTemplate);
3651 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003652
Douglas Gregor9db53502011-03-02 18:07:45 +00003653 if (SubstTemplateTemplateParmPackStorage *SubstPack
3654 = Name.getAsSubstTemplateTemplateParmPack()) {
3655 TemplateTemplateParmDecl *TransParam
3656 = cast_or_null<TemplateTemplateParmDecl>(
3657 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3658 if (!TransParam)
3659 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003660
Douglas Gregor9db53502011-03-02 18:07:45 +00003661 if (!getDerived().AlwaysRebuild() &&
3662 TransParam == SubstPack->getParameterPack())
3663 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003664
3665 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003666 SubstPack->getArgumentPack());
3667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003668
Douglas Gregor9db53502011-03-02 18:07:45 +00003669 // These should be getting filtered out before they reach the AST.
3670 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003671}
3672
3673template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003674void TreeTransform<Derived>::InventTemplateArgumentLoc(
3675 const TemplateArgument &Arg,
3676 TemplateArgumentLoc &Output) {
3677 SourceLocation Loc = getDerived().getBaseLocation();
3678 switch (Arg.getKind()) {
3679 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003680 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003681 break;
3682
3683 case TemplateArgument::Type:
3684 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003685 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003686
John McCall0ad16662009-10-29 08:12:44 +00003687 break;
3688
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003689 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003690 case TemplateArgument::TemplateExpansion: {
3691 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003692 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003693 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3694 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3695 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3696 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003697
Douglas Gregor9d802122011-03-02 17:09:35 +00003698 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003699 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003700 Builder.getWithLocInContext(SemaRef.Context),
3701 Loc);
3702 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003703 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003704 Builder.getWithLocInContext(SemaRef.Context),
3705 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003706
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003707 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003708 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003709
John McCall0ad16662009-10-29 08:12:44 +00003710 case TemplateArgument::Expression:
3711 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3712 break;
3713
3714 case TemplateArgument::Declaration:
3715 case TemplateArgument::Integral:
3716 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003717 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003718 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003719 break;
3720 }
3721}
3722
3723template<typename Derived>
3724bool TreeTransform<Derived>::TransformTemplateArgument(
3725 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003726 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003727 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003728 switch (Arg.getKind()) {
3729 case TemplateArgument::Null:
3730 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003731 case TemplateArgument::Pack:
3732 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003733 case TemplateArgument::NullPtr:
3734 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003735
Douglas Gregore922c772009-08-04 22:27:00 +00003736 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003737 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003738 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003739 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003740
3741 DI = getDerived().TransformType(DI);
3742 if (!DI) return true;
3743
3744 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3745 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003746 }
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003748 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003749 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3750 if (QualifierLoc) {
3751 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3752 if (!QualifierLoc)
3753 return true;
3754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
Douglas Gregordf846d12011-03-02 18:46:51 +00003756 CXXScopeSpec SS;
3757 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003758 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003759 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3760 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003761 if (Template.isNull())
3762 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003763
Douglas Gregor9d802122011-03-02 17:09:35 +00003764 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003765 Input.getTemplateNameLoc());
3766 return false;
3767 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003768
3769 case TemplateArgument::TemplateExpansion:
3770 llvm_unreachable("Caller should expand pack expansions");
3771
Douglas Gregore922c772009-08-04 22:27:00 +00003772 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003773 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003774 EnterExpressionEvaluationContext Unevaluated(
3775 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003776
John McCall0ad16662009-10-29 08:12:44 +00003777 Expr *InputExpr = Input.getSourceExpression();
3778 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3779
Chris Lattnercdb591a2011-04-25 20:37:58 +00003780 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003781 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003782 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003783 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003784 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003785 }
Douglas Gregore922c772009-08-04 22:27:00 +00003786 }
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregore922c772009-08-04 22:27:00 +00003788 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003789 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003790}
3791
Douglas Gregorfe921a72010-12-20 23:36:19 +00003792/// \brief Iterator adaptor that invents template argument location information
3793/// for each of the template arguments in its underlying iterator.
3794template<typename Derived, typename InputIterator>
3795class TemplateArgumentLocInventIterator {
3796 TreeTransform<Derived> &Self;
3797 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
Douglas Gregorfe921a72010-12-20 23:36:19 +00003799public:
3800 typedef TemplateArgumentLoc value_type;
3801 typedef TemplateArgumentLoc reference;
3802 typedef typename std::iterator_traits<InputIterator>::difference_type
3803 difference_type;
3804 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003805
Douglas Gregorfe921a72010-12-20 23:36:19 +00003806 class pointer {
3807 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003808
Douglas Gregorfe921a72010-12-20 23:36:19 +00003809 public:
3810 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003811
Douglas Gregorfe921a72010-12-20 23:36:19 +00003812 const TemplateArgumentLoc *operator->() const { return &Arg; }
3813 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003814
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003815 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregorfe921a72010-12-20 23:36:19 +00003817 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3818 InputIterator Iter)
3819 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
Douglas Gregorfe921a72010-12-20 23:36:19 +00003821 TemplateArgumentLocInventIterator &operator++() {
3822 ++Iter;
3823 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregorfe921a72010-12-20 23:36:19 +00003826 TemplateArgumentLocInventIterator operator++(int) {
3827 TemplateArgumentLocInventIterator Old(*this);
3828 ++(*this);
3829 return Old;
3830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003831
Douglas Gregorfe921a72010-12-20 23:36:19 +00003832 reference operator*() const {
3833 TemplateArgumentLoc Result;
3834 Self.InventTemplateArgumentLoc(*Iter, Result);
3835 return Result;
3836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003837
Douglas Gregorfe921a72010-12-20 23:36:19 +00003838 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003839
Douglas Gregorfe921a72010-12-20 23:36:19 +00003840 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3841 const TemplateArgumentLocInventIterator &Y) {
3842 return X.Iter == Y.Iter;
3843 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003844
Douglas Gregorfe921a72010-12-20 23:36:19 +00003845 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3846 const TemplateArgumentLocInventIterator &Y) {
3847 return X.Iter != Y.Iter;
3848 }
3849};
Chad Rosier1dcde962012-08-08 18:46:20 +00003850
Douglas Gregor42cafa82010-12-20 17:42:22 +00003851template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003852template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003853bool TreeTransform<Derived>::TransformTemplateArguments(
3854 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3855 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003856 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003857 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003858 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003860 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3861 // Unpack argument packs, which we translate them into separate
3862 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003863 // FIXME: We could do much better if we could guarantee that the
3864 // TemplateArgumentLocInfo for the pack expansion would be usable for
3865 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003866 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003867 TemplateArgument::pack_iterator>
3868 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003869 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003870 In.getArgument().pack_begin()),
3871 PackLocIterator(*this,
3872 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003873 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003874 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003875
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003876 continue;
3877 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003878
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003879 if (In.getArgument().isPackExpansion()) {
3880 // We have a pack expansion, for which we will be substituting into
3881 // the pattern.
3882 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003883 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003884 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003885 = getSema().getTemplateArgumentPackExpansionPattern(
3886 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003887
Chris Lattner01cf8db2011-07-20 06:58:45 +00003888 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003889 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3890 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003891
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003892 // Determine whether the set of unexpanded parameter packs can and should
3893 // be expanded.
3894 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003895 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003896 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003897 if (getDerived().TryExpandParameterPacks(Ellipsis,
3898 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003899 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003900 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003901 RetainExpansion,
3902 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003903 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003904
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003905 if (!Expand) {
3906 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003907 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003908 // expansion.
3909 TemplateArgumentLoc OutPattern;
3910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003911 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003912 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003913
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003914 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3915 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003916 if (Out.getArgument().isNull())
3917 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003918
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003919 Outputs.addArgument(Out);
3920 continue;
3921 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003922
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003923 // The transform has determined that we should perform an elementwise
3924 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003925 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003926 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3927
Richard Smithd784e682015-09-23 21:41:42 +00003928 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003929 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003930
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003931 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003932 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3933 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003934 if (Out.getArgument().isNull())
3935 return true;
3936 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003937
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003938 Outputs.addArgument(Out);
3939 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003940
Douglas Gregor48d24112011-01-10 20:53:55 +00003941 // If we're supposed to retain a pack expansion, do so by temporarily
3942 // forgetting the partially-substituted parameter pack.
3943 if (RetainExpansion) {
3944 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003945
Richard Smithd784e682015-09-23 21:41:42 +00003946 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003947 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003948
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003949 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3950 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003951 if (Out.getArgument().isNull())
3952 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003953
Douglas Gregor48d24112011-01-10 20:53:55 +00003954 Outputs.addArgument(Out);
3955 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003956
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003957 continue;
3958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003959
3960 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003961 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003962 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003963
Douglas Gregor42cafa82010-12-20 17:42:22 +00003964 Outputs.addArgument(Out);
3965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003966
Douglas Gregor42cafa82010-12-20 17:42:22 +00003967 return false;
3968
3969}
3970
Douglas Gregord6ff3322009-08-04 16:50:30 +00003971//===----------------------------------------------------------------------===//
3972// Type transformation
3973//===----------------------------------------------------------------------===//
3974
3975template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003976QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003977 if (getDerived().AlreadyTransformed(T))
3978 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003979
John McCall550e0c22009-10-21 00:40:46 +00003980 // Temporary workaround. All of these transformations should
3981 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003982 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3983 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003984
John McCall31f82722010-11-12 08:19:04 +00003985 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003986
John McCall550e0c22009-10-21 00:40:46 +00003987 if (!NewDI)
3988 return QualType();
3989
3990 return NewDI->getType();
3991}
3992
3993template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003994TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003995 // Refine the base location to the type's location.
3996 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3997 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003998 if (getDerived().AlreadyTransformed(DI->getType()))
3999 return DI;
4000
4001 TypeLocBuilder TLB;
4002
4003 TypeLoc TL = DI->getTypeLoc();
4004 TLB.reserve(TL.getFullDataSize());
4005
John McCall31f82722010-11-12 08:19:04 +00004006 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004007 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004008 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004009
John McCallbcd03502009-12-07 02:54:59 +00004010 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004011}
4012
4013template<typename Derived>
4014QualType
John McCall31f82722010-11-12 08:19:04 +00004015TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004016 switch (T.getTypeLocClass()) {
4017#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004018#define TYPELOC(CLASS, PARENT) \
4019 case TypeLoc::CLASS: \
4020 return getDerived().Transform##CLASS##Type(TLB, \
4021 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004022#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004023 }
Mike Stump11289f42009-09-09 15:08:12 +00004024
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004025 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004026}
4027
4028/// FIXME: By default, this routine adds type qualifiers only to types
4029/// that can have qualifiers, and silently suppresses those qualifiers
4030/// that are not permitted (e.g., qualifiers on reference or function
4031/// types). This is the right thing for template instantiation, but
4032/// probably not for other clients.
4033template<typename Derived>
4034QualType
4035TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004036 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004037 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004038
John McCall31f82722010-11-12 08:19:04 +00004039 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004040 if (Result.isNull())
4041 return QualType();
4042
4043 // Silently suppress qualifiers if the result type can't be qualified.
4044 // FIXME: this is the right thing for template instantiation, but
4045 // probably not for other clients.
4046 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004047 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004048
John McCall31168b02011-06-15 23:02:42 +00004049 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004050 // resulting type.
4051 if (Quals.hasObjCLifetime()) {
4052 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4053 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004054 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004055 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004056 // A lifetime qualifier applied to a substituted template parameter
4057 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004058 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004059 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004060 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4061 QualType Replacement = SubstTypeParam->getReplacementType();
4062 Qualifiers Qs = Replacement.getQualifiers();
4063 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004064 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004065 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4066 Qs);
4067 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004068 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004069 Replacement);
4070 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004071 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4072 // 'auto' types behave the same way as template parameters.
4073 QualType Deduced = AutoTy->getDeducedType();
4074 Qualifiers Qs = Deduced.getQualifiers();
4075 Qs.removeObjCLifetime();
4076 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4077 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004078 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004079 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004080 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004081 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004082 // Otherwise, complain about the addition of a qualifier to an
4083 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004084 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004085 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004086 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004087
Douglas Gregore46db902011-06-17 22:11:49 +00004088 Quals.removeObjCLifetime();
4089 }
4090 }
4091 }
John McCallcb0f89a2010-06-05 06:41:15 +00004092 if (!Quals.empty()) {
4093 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004094 // BuildQualifiedType might not add qualifiers if they are invalid.
4095 if (Result.hasLocalQualifiers())
4096 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004097 // No location information to preserve.
4098 }
John McCall550e0c22009-10-21 00:40:46 +00004099
4100 return Result;
4101}
4102
Douglas Gregor14454802011-02-25 02:25:35 +00004103template<typename Derived>
4104TypeLoc
4105TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4106 QualType ObjectType,
4107 NamedDecl *UnqualLookup,
4108 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004109 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004110 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004112 TypeSourceInfo *TSI =
4113 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4114 if (TSI)
4115 return TSI->getTypeLoc();
4116 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004117}
4118
Douglas Gregor579c15f2011-03-02 18:32:08 +00004119template<typename Derived>
4120TypeSourceInfo *
4121TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4122 QualType ObjectType,
4123 NamedDecl *UnqualLookup,
4124 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004125 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004126 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004127
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004128 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4129 UnqualLookup, SS);
4130}
4131
4132template <typename Derived>
4133TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4134 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4135 CXXScopeSpec &SS) {
4136 QualType T = TL.getType();
4137 assert(!getDerived().AlreadyTransformed(T));
4138
Douglas Gregor579c15f2011-03-02 18:32:08 +00004139 TypeLocBuilder TLB;
4140 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004141
Douglas Gregor579c15f2011-03-02 18:32:08 +00004142 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004143 TemplateSpecializationTypeLoc SpecTL =
4144 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004145
Douglas Gregor579c15f2011-03-02 18:32:08 +00004146 TemplateName Template
4147 = getDerived().TransformTemplateName(SS,
4148 SpecTL.getTypePtr()->getTemplateName(),
4149 SpecTL.getTemplateNameLoc(),
4150 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004151 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004152 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004153
4154 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004155 Template);
4156 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004157 DependentTemplateSpecializationTypeLoc SpecTL =
4158 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004159
Douglas Gregor579c15f2011-03-02 18:32:08 +00004160 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004161 = getDerived().RebuildTemplateName(SS,
4162 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004163 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004164 ObjectType, UnqualLookup);
4165 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004166 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004167
4168 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004169 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004170 Template,
4171 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004172 } else {
4173 // Nothing special needs to be done for these.
4174 Result = getDerived().TransformType(TLB, TL);
4175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004176
4177 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004178 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004179
Douglas Gregor579c15f2011-03-02 18:32:08 +00004180 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4181}
4182
John McCall550e0c22009-10-21 00:40:46 +00004183template <class TyLoc> static inline
4184QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4185 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4186 NewT.setNameLoc(T.getNameLoc());
4187 return T.getType();
4188}
4189
John McCall550e0c22009-10-21 00:40:46 +00004190template<typename Derived>
4191QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004192 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004193 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4194 NewT.setBuiltinLoc(T.getBuiltinLoc());
4195 if (T.needsExtraLocalData())
4196 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4197 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198}
Mike Stump11289f42009-09-09 15:08:12 +00004199
Douglas Gregord6ff3322009-08-04 16:50:30 +00004200template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004201QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004202 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004203 // FIXME: recurse?
4204 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004205}
Mike Stump11289f42009-09-09 15:08:12 +00004206
Reid Kleckner0503a872013-12-05 01:23:43 +00004207template <typename Derived>
4208QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4209 AdjustedTypeLoc TL) {
4210 // Adjustments applied during transformation are handled elsewhere.
4211 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4212}
4213
Douglas Gregord6ff3322009-08-04 16:50:30 +00004214template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004215QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4216 DecayedTypeLoc TL) {
4217 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4218 if (OriginalType.isNull())
4219 return QualType();
4220
4221 QualType Result = TL.getType();
4222 if (getDerived().AlwaysRebuild() ||
4223 OriginalType != TL.getOriginalLoc().getType())
4224 Result = SemaRef.Context.getDecayedType(OriginalType);
4225 TLB.push<DecayedTypeLoc>(Result);
4226 // Nothing to set for DecayedTypeLoc.
4227 return Result;
4228}
4229
4230template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004231QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004232 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004233 QualType PointeeType
4234 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004235 if (PointeeType.isNull())
4236 return QualType();
4237
4238 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004239 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004240 // A dependent pointer type 'T *' has is being transformed such
4241 // that an Objective-C class type is being replaced for 'T'. The
4242 // resulting pointer type is an ObjCObjectPointerType, not a
4243 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004244 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004245
John McCall8b07ec22010-05-15 11:32:37 +00004246 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4247 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004248 return Result;
4249 }
John McCall31f82722010-11-12 08:19:04 +00004250
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004251 if (getDerived().AlwaysRebuild() ||
4252 PointeeType != TL.getPointeeLoc().getType()) {
4253 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4254 if (Result.isNull())
4255 return QualType();
4256 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004257
John McCall31168b02011-06-15 23:02:42 +00004258 // Objective-C ARC can add lifetime qualifiers to the type that we're
4259 // pointing to.
4260 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004261
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004262 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4263 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004264 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265}
Mike Stump11289f42009-09-09 15:08:12 +00004266
4267template<typename Derived>
4268QualType
John McCall550e0c22009-10-21 00:40:46 +00004269TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004270 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004271 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004272 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4273 if (PointeeType.isNull())
4274 return QualType();
4275
4276 QualType Result = TL.getType();
4277 if (getDerived().AlwaysRebuild() ||
4278 PointeeType != TL.getPointeeLoc().getType()) {
4279 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004280 TL.getSigilLoc());
4281 if (Result.isNull())
4282 return QualType();
4283 }
4284
Douglas Gregor049211a2010-04-22 16:50:51 +00004285 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004286 NewT.setSigilLoc(TL.getSigilLoc());
4287 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004288}
4289
John McCall70dd5f62009-10-30 00:06:24 +00004290/// Transforms a reference type. Note that somewhat paradoxically we
4291/// don't care whether the type itself is an l-value type or an r-value
4292/// type; we only care if the type was *written* as an l-value type
4293/// or an r-value type.
4294template<typename Derived>
4295QualType
4296TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004297 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004298 const ReferenceType *T = TL.getTypePtr();
4299
4300 // Note that this works with the pointee-as-written.
4301 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4302 if (PointeeType.isNull())
4303 return QualType();
4304
4305 QualType Result = TL.getType();
4306 if (getDerived().AlwaysRebuild() ||
4307 PointeeType != T->getPointeeTypeAsWritten()) {
4308 Result = getDerived().RebuildReferenceType(PointeeType,
4309 T->isSpelledAsLValue(),
4310 TL.getSigilLoc());
4311 if (Result.isNull())
4312 return QualType();
4313 }
4314
John McCall31168b02011-06-15 23:02:42 +00004315 // Objective-C ARC can add lifetime qualifiers to the type that we're
4316 // referring to.
4317 TLB.TypeWasModifiedSafely(
4318 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4319
John McCall70dd5f62009-10-30 00:06:24 +00004320 // r-value references can be rebuilt as l-value references.
4321 ReferenceTypeLoc NewTL;
4322 if (isa<LValueReferenceType>(Result))
4323 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4324 else
4325 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4326 NewTL.setSigilLoc(TL.getSigilLoc());
4327
4328 return Result;
4329}
4330
Mike Stump11289f42009-09-09 15:08:12 +00004331template<typename Derived>
4332QualType
John McCall550e0c22009-10-21 00:40:46 +00004333TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004334 LValueReferenceTypeLoc TL) {
4335 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004336}
4337
Mike Stump11289f42009-09-09 15:08:12 +00004338template<typename Derived>
4339QualType
John McCall550e0c22009-10-21 00:40:46 +00004340TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004341 RValueReferenceTypeLoc TL) {
4342 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004343}
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregord6ff3322009-08-04 16:50:30 +00004345template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004346QualType
John McCall550e0c22009-10-21 00:40:46 +00004347TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004348 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004349 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004350 if (PointeeType.isNull())
4351 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004352
Abramo Bagnara509357842011-03-05 14:42:21 +00004353 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004354 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004355 if (OldClsTInfo) {
4356 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4357 if (!NewClsTInfo)
4358 return QualType();
4359 }
4360
4361 const MemberPointerType *T = TL.getTypePtr();
4362 QualType OldClsType = QualType(T->getClass(), 0);
4363 QualType NewClsType;
4364 if (NewClsTInfo)
4365 NewClsType = NewClsTInfo->getType();
4366 else {
4367 NewClsType = getDerived().TransformType(OldClsType);
4368 if (NewClsType.isNull())
4369 return QualType();
4370 }
Mike Stump11289f42009-09-09 15:08:12 +00004371
John McCall550e0c22009-10-21 00:40:46 +00004372 QualType Result = TL.getType();
4373 if (getDerived().AlwaysRebuild() ||
4374 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004375 NewClsType != OldClsType) {
4376 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004377 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004378 if (Result.isNull())
4379 return QualType();
4380 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004381
Reid Kleckner0503a872013-12-05 01:23:43 +00004382 // If we had to adjust the pointee type when building a member pointer, make
4383 // sure to push TypeLoc info for it.
4384 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4385 if (MPT && PointeeType != MPT->getPointeeType()) {
4386 assert(isa<AdjustedType>(MPT->getPointeeType()));
4387 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4388 }
4389
John McCall550e0c22009-10-21 00:40:46 +00004390 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4391 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004392 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004393
4394 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004395}
4396
Mike Stump11289f42009-09-09 15:08:12 +00004397template<typename Derived>
4398QualType
John McCall550e0c22009-10-21 00:40:46 +00004399TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004400 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004401 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004402 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004403 if (ElementType.isNull())
4404 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004405
John McCall550e0c22009-10-21 00:40:46 +00004406 QualType Result = TL.getType();
4407 if (getDerived().AlwaysRebuild() ||
4408 ElementType != T->getElementType()) {
4409 Result = getDerived().RebuildConstantArrayType(ElementType,
4410 T->getSizeModifier(),
4411 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004412 T->getIndexTypeCVRQualifiers(),
4413 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004414 if (Result.isNull())
4415 return QualType();
4416 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004417
4418 // We might have either a ConstantArrayType or a VariableArrayType now:
4419 // a ConstantArrayType is allowed to have an element type which is a
4420 // VariableArrayType if the type is dependent. Fortunately, all array
4421 // types have the same location layout.
4422 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004423 NewTL.setLBracketLoc(TL.getLBracketLoc());
4424 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004425
John McCall550e0c22009-10-21 00:40:46 +00004426 Expr *Size = TL.getSizeExpr();
4427 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004428 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4429 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004430 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4431 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004432 }
4433 NewTL.setSizeExpr(Size);
4434
4435 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004436}
Mike Stump11289f42009-09-09 15:08:12 +00004437
Douglas Gregord6ff3322009-08-04 16:50:30 +00004438template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004439QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004440 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004441 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004442 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004443 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004444 if (ElementType.isNull())
4445 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004446
John McCall550e0c22009-10-21 00:40:46 +00004447 QualType Result = TL.getType();
4448 if (getDerived().AlwaysRebuild() ||
4449 ElementType != T->getElementType()) {
4450 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004451 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004452 T->getIndexTypeCVRQualifiers(),
4453 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004454 if (Result.isNull())
4455 return QualType();
4456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004457
John McCall550e0c22009-10-21 00:40:46 +00004458 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4459 NewTL.setLBracketLoc(TL.getLBracketLoc());
4460 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004461 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004462
4463 return Result;
4464}
4465
4466template<typename Derived>
4467QualType
4468TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004469 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004470 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004471 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4472 if (ElementType.isNull())
4473 return QualType();
4474
John McCalldadc5752010-08-24 06:29:42 +00004475 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004476 = getDerived().TransformExpr(T->getSizeExpr());
4477 if (SizeResult.isInvalid())
4478 return QualType();
4479
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004480 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004481
4482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() ||
4484 ElementType != T->getElementType() ||
4485 Size != T->getSizeExpr()) {
4486 Result = getDerived().RebuildVariableArrayType(ElementType,
4487 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004488 Size,
John McCall550e0c22009-10-21 00:40:46 +00004489 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004490 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004491 if (Result.isNull())
4492 return QualType();
4493 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004494
Serge Pavlov774c6d02014-02-06 03:49:11 +00004495 // We might have constant size array now, but fortunately it has the same
4496 // location layout.
4497 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004498 NewTL.setLBracketLoc(TL.getLBracketLoc());
4499 NewTL.setRBracketLoc(TL.getRBracketLoc());
4500 NewTL.setSizeExpr(Size);
4501
4502 return Result;
4503}
4504
4505template<typename Derived>
4506QualType
4507TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004508 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004509 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004510 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4511 if (ElementType.isNull())
4512 return QualType();
4513
Richard Smith764d2fe2011-12-20 02:08:33 +00004514 // Array bounds are constant expressions.
4515 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4516 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004517
John McCall33ddac02011-01-19 10:06:00 +00004518 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4519 Expr *origSize = TL.getSizeExpr();
4520 if (!origSize) origSize = T->getSizeExpr();
4521
4522 ExprResult sizeResult
4523 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004524 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004525 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004526 return QualType();
4527
John McCall33ddac02011-01-19 10:06:00 +00004528 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004529
4530 QualType Result = TL.getType();
4531 if (getDerived().AlwaysRebuild() ||
4532 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004533 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004534 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4535 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004536 size,
John McCall550e0c22009-10-21 00:40:46 +00004537 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004538 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004539 if (Result.isNull())
4540 return QualType();
4541 }
John McCall550e0c22009-10-21 00:40:46 +00004542
4543 // We might have any sort of array type now, but fortunately they
4544 // all have the same location layout.
4545 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4546 NewTL.setLBracketLoc(TL.getLBracketLoc());
4547 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004548 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004549
4550 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004551}
Mike Stump11289f42009-09-09 15:08:12 +00004552
4553template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004554QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004555 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004556 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004557 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004558
4559 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004560 QualType ElementType = getDerived().TransformType(T->getElementType());
4561 if (ElementType.isNull())
4562 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004563
Richard Smith764d2fe2011-12-20 02:08:33 +00004564 // Vector sizes are constant expressions.
4565 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4566 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004567
John McCalldadc5752010-08-24 06:29:42 +00004568 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004569 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004570 if (Size.isInvalid())
4571 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004572
John McCall550e0c22009-10-21 00:40:46 +00004573 QualType Result = TL.getType();
4574 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004575 ElementType != T->getElementType() ||
4576 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004577 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004578 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004579 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004580 if (Result.isNull())
4581 return QualType();
4582 }
John McCall550e0c22009-10-21 00:40:46 +00004583
4584 // Result might be dependent or not.
4585 if (isa<DependentSizedExtVectorType>(Result)) {
4586 DependentSizedExtVectorTypeLoc NewTL
4587 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4588 NewTL.setNameLoc(TL.getNameLoc());
4589 } else {
4590 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4591 NewTL.setNameLoc(TL.getNameLoc());
4592 }
4593
4594 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004595}
Mike Stump11289f42009-09-09 15:08:12 +00004596
4597template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004598QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004599 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004600 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004601 QualType ElementType = getDerived().TransformType(T->getElementType());
4602 if (ElementType.isNull())
4603 return QualType();
4604
John McCall550e0c22009-10-21 00:40:46 +00004605 QualType Result = TL.getType();
4606 if (getDerived().AlwaysRebuild() ||
4607 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004608 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004609 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004610 if (Result.isNull())
4611 return QualType();
4612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004613
John McCall550e0c22009-10-21 00:40:46 +00004614 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4615 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004616
John McCall550e0c22009-10-21 00:40:46 +00004617 return Result;
4618}
4619
4620template<typename Derived>
4621QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004622 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004623 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004624 QualType ElementType = getDerived().TransformType(T->getElementType());
4625 if (ElementType.isNull())
4626 return QualType();
4627
4628 QualType Result = TL.getType();
4629 if (getDerived().AlwaysRebuild() ||
4630 ElementType != T->getElementType()) {
4631 Result = getDerived().RebuildExtVectorType(ElementType,
4632 T->getNumElements(),
4633 /*FIXME*/ SourceLocation());
4634 if (Result.isNull())
4635 return QualType();
4636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004637
John McCall550e0c22009-10-21 00:40:46 +00004638 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4639 NewTL.setNameLoc(TL.getNameLoc());
4640
4641 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004642}
Mike Stump11289f42009-09-09 15:08:12 +00004643
David Blaikie05785d12013-02-20 22:23:23 +00004644template <typename Derived>
4645ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4646 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4647 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004648 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004649 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004650
Douglas Gregor715e4612011-01-14 22:40:04 +00004651 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004652 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004653 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004654 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004655 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004656
Douglas Gregor715e4612011-01-14 22:40:04 +00004657 TypeLocBuilder TLB;
4658 TypeLoc NewTL = OldDI->getTypeLoc();
4659 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004660
4661 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004662 OldExpansionTL.getPatternLoc());
4663 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004664 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004665
4666 Result = RebuildPackExpansionType(Result,
4667 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004668 OldExpansionTL.getEllipsisLoc(),
4669 NumExpansions);
4670 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004671 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004672
Douglas Gregor715e4612011-01-14 22:40:04 +00004673 PackExpansionTypeLoc NewExpansionTL
4674 = TLB.push<PackExpansionTypeLoc>(Result);
4675 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4676 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4677 } else
4678 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004679 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004680 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004681
John McCall8fb0d9d2011-05-01 22:35:37 +00004682 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004683 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004684
4685 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4686 OldParm->getDeclContext(),
4687 OldParm->getInnerLocStart(),
4688 OldParm->getLocation(),
4689 OldParm->getIdentifier(),
4690 NewDI->getType(),
4691 NewDI,
4692 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004693 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004694 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4695 OldParm->getFunctionScopeIndex() + indexAdjustment);
4696 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004697}
4698
David Majnemer59f77922016-06-24 04:05:48 +00004699template <typename Derived>
4700bool TreeTransform<Derived>::TransformFunctionTypeParams(
4701 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4702 const QualType *ParamTypes,
4703 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4704 SmallVectorImpl<QualType> &OutParamTypes,
4705 SmallVectorImpl<ParmVarDecl *> *PVars,
4706 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004707 int indexAdjustment = 0;
4708
David Majnemer59f77922016-06-24 04:05:48 +00004709 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004710 for (unsigned i = 0; i != NumParams; ++i) {
4711 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004712 assert(OldParm->getFunctionScopeIndex() == i);
4713
David Blaikie05785d12013-02-20 22:23:23 +00004714 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004715 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004716 if (OldParm->isParameterPack()) {
4717 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004718 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004719
Douglas Gregor5499af42011-01-05 23:12:31 +00004720 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004721 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004722 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004723 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4724 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004725 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4726
Douglas Gregor5499af42011-01-05 23:12:31 +00004727 // Determine whether we should expand the parameter packs.
4728 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004729 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004730 Optional<unsigned> OrigNumExpansions =
4731 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004732 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004733 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4734 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004735 Unexpanded,
4736 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004737 RetainExpansion,
4738 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004739 return true;
4740 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004741
Douglas Gregor5499af42011-01-05 23:12:31 +00004742 if (ShouldExpand) {
4743 // Expand the function parameter pack into multiple, separate
4744 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004745 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004746 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004747 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004748 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004749 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004750 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004751 OrigNumExpansions,
4752 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004753 if (!NewParm)
4754 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004755
John McCallc8e321d2016-03-01 02:09:25 +00004756 if (ParamInfos)
4757 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004758 OutParamTypes.push_back(NewParm->getType());
4759 if (PVars)
4760 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004761 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004762
4763 // If we're supposed to retain a pack expansion, do so by temporarily
4764 // forgetting the partially-substituted parameter pack.
4765 if (RetainExpansion) {
4766 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004767 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004768 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004769 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004770 OrigNumExpansions,
4771 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004772 if (!NewParm)
4773 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004774
John McCallc8e321d2016-03-01 02:09:25 +00004775 if (ParamInfos)
4776 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004777 OutParamTypes.push_back(NewParm->getType());
4778 if (PVars)
4779 PVars->push_back(NewParm);
4780 }
4781
John McCall8fb0d9d2011-05-01 22:35:37 +00004782 // The next parameter should have the same adjustment as the
4783 // last thing we pushed, but we post-incremented indexAdjustment
4784 // on every push. Also, if we push nothing, the adjustment should
4785 // go down by one.
4786 indexAdjustment--;
4787
Douglas Gregor5499af42011-01-05 23:12:31 +00004788 // We're done with the pack expansion.
4789 continue;
4790 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004791
4792 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004793 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004794 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4795 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004796 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004797 NumExpansions,
4798 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004799 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004800 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004801 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004802 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004803
John McCall58f10c32010-03-11 09:03:00 +00004804 if (!NewParm)
4805 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004806
John McCallc8e321d2016-03-01 02:09:25 +00004807 if (ParamInfos)
4808 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004809 OutParamTypes.push_back(NewParm->getType());
4810 if (PVars)
4811 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004812 continue;
4813 }
John McCall58f10c32010-03-11 09:03:00 +00004814
4815 // Deal with the possibility that we don't have a parameter
4816 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004817 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004818 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004819 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004820 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004821 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004822 = dyn_cast<PackExpansionType>(OldType)) {
4823 // We have a function parameter pack that may need to be expanded.
4824 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004825 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004826 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004827
Douglas Gregor5499af42011-01-05 23:12:31 +00004828 // Determine whether we should expand the parameter packs.
4829 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004830 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004831 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004832 Unexpanded,
4833 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004834 RetainExpansion,
4835 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004836 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004837 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004838
Douglas Gregor5499af42011-01-05 23:12:31 +00004839 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004840 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004841 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004842 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004843 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4844 QualType NewType = getDerived().TransformType(Pattern);
4845 if (NewType.isNull())
4846 return true;
John McCall58f10c32010-03-11 09:03:00 +00004847
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00004848 if (NewType->containsUnexpandedParameterPack()) {
4849 NewType =
4850 getSema().getASTContext().getPackExpansionType(NewType, None);
4851
4852 if (NewType.isNull())
4853 return true;
4854 }
4855
John McCallc8e321d2016-03-01 02:09:25 +00004856 if (ParamInfos)
4857 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004858 OutParamTypes.push_back(NewType);
4859 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004860 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004862
Douglas Gregor5499af42011-01-05 23:12:31 +00004863 // We're done with the pack expansion.
4864 continue;
4865 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004866
Douglas Gregor48d24112011-01-10 20:53:55 +00004867 // If we're supposed to retain a pack expansion, do so by temporarily
4868 // forgetting the partially-substituted parameter pack.
4869 if (RetainExpansion) {
4870 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4871 QualType NewType = getDerived().TransformType(Pattern);
4872 if (NewType.isNull())
4873 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004874
John McCallc8e321d2016-03-01 02:09:25 +00004875 if (ParamInfos)
4876 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004877 OutParamTypes.push_back(NewType);
4878 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004879 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004880 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004881
Chad Rosier1dcde962012-08-08 18:46:20 +00004882 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004883 // expansion.
4884 OldType = Expansion->getPattern();
4885 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004886 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4887 NewType = getDerived().TransformType(OldType);
4888 } else {
4889 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004891
Douglas Gregor5499af42011-01-05 23:12:31 +00004892 if (NewType.isNull())
4893 return true;
4894
4895 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004896 NewType = getSema().Context.getPackExpansionType(NewType,
4897 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004898
John McCallc8e321d2016-03-01 02:09:25 +00004899 if (ParamInfos)
4900 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004901 OutParamTypes.push_back(NewType);
4902 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004903 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004904 }
4905
John McCall8fb0d9d2011-05-01 22:35:37 +00004906#ifndef NDEBUG
4907 if (PVars) {
4908 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4909 if (ParmVarDecl *parm = (*PVars)[i])
4910 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004911 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004912#endif
4913
4914 return false;
4915}
John McCall58f10c32010-03-11 09:03:00 +00004916
4917template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004918QualType
John McCall550e0c22009-10-21 00:40:46 +00004919TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004920 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004921 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004922 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004923 return getDerived().TransformFunctionProtoType(
4924 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004925 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4926 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4927 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004928 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004929}
4930
Richard Smith2e321552014-11-12 02:00:47 +00004931template<typename Derived> template<typename Fn>
4932QualType TreeTransform<Derived>::TransformFunctionProtoType(
4933 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4934 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004935
Douglas Gregor4afc2362010-08-31 00:26:14 +00004936 // Transform the parameters and return type.
4937 //
Richard Smithf623c962012-04-17 00:58:00 +00004938 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004939 // When the function has a trailing return type, we instantiate the
4940 // parameters before the return type, since the return type can then refer
4941 // to the parameters themselves (via decltype, sizeof, etc.).
4942 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004943 SmallVector<QualType, 4> ParamTypes;
4944 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004945 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004946 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004947
Douglas Gregor7fb25412010-10-01 18:44:50 +00004948 QualType ResultType;
4949
Richard Smith1226c602012-08-14 22:51:13 +00004950 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004951 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004952 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004953 TL.getTypePtr()->param_type_begin(),
4954 T->getExtParameterInfosOrNull(),
4955 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004956 return QualType();
4957
Douglas Gregor3024f072012-04-16 07:05:22 +00004958 {
4959 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004960 // If a declaration declares a member function or member function
4961 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004962 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004963 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004964 // declarator.
4965 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004966
Alp Toker42a16a62014-01-25 23:51:36 +00004967 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004968 if (ResultType.isNull())
4969 return QualType();
4970 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004971 }
4972 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004973 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004974 if (ResultType.isNull())
4975 return QualType();
4976
Alp Toker9cacbab2014-01-20 20:26:09 +00004977 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004978 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004979 TL.getTypePtr()->param_type_begin(),
4980 T->getExtParameterInfosOrNull(),
4981 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004982 return QualType();
4983 }
4984
Richard Smith2e321552014-11-12 02:00:47 +00004985 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4986
4987 bool EPIChanged = false;
4988 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4989 return QualType();
4990
John McCallc8e321d2016-03-01 02:09:25 +00004991 // Handle extended parameter information.
4992 if (auto NewExtParamInfos =
4993 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4994 if (!EPI.ExtParameterInfos ||
4995 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4996 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4997 EPIChanged = true;
4998 }
4999 EPI.ExtParameterInfos = NewExtParamInfos;
5000 } else if (EPI.ExtParameterInfos) {
5001 EPIChanged = true;
5002 EPI.ExtParameterInfos = nullptr;
5003 }
Richard Smithf623c962012-04-17 00:58:00 +00005004
John McCall550e0c22009-10-21 00:40:46 +00005005 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005006 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005007 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005008 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005009 if (Result.isNull())
5010 return QualType();
5011 }
Mike Stump11289f42009-09-09 15:08:12 +00005012
John McCall550e0c22009-10-21 00:40:46 +00005013 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005014 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005015 NewTL.setLParenLoc(TL.getLParenLoc());
5016 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005017 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005018 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5019 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005020
5021 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022}
Mike Stump11289f42009-09-09 15:08:12 +00005023
Douglas Gregord6ff3322009-08-04 16:50:30 +00005024template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005025bool TreeTransform<Derived>::TransformExceptionSpec(
5026 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5027 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5028 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5029
5030 // Instantiate a dynamic noexcept expression, if any.
5031 if (ESI.Type == EST_ComputedNoexcept) {
5032 EnterExpressionEvaluationContext Unevaluated(getSema(),
5033 Sema::ConstantEvaluated);
5034 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5035 if (NoexceptExpr.isInvalid())
5036 return true;
5037
Richard Smith03a4aa32016-06-23 19:02:52 +00005038 // FIXME: This is bogus, a noexcept expression is not a condition.
5039 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005040 if (NoexceptExpr.isInvalid())
5041 return true;
5042
5043 if (!NoexceptExpr.get()->isValueDependent()) {
5044 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5045 NoexceptExpr.get(), nullptr,
5046 diag::err_noexcept_needs_constant_expression,
5047 /*AllowFold*/false);
5048 if (NoexceptExpr.isInvalid())
5049 return true;
5050 }
5051
5052 if (ESI.NoexceptExpr != NoexceptExpr.get())
5053 Changed = true;
5054 ESI.NoexceptExpr = NoexceptExpr.get();
5055 }
5056
5057 if (ESI.Type != EST_Dynamic)
5058 return false;
5059
5060 // Instantiate a dynamic exception specification's type.
5061 for (QualType T : ESI.Exceptions) {
5062 if (const PackExpansionType *PackExpansion =
5063 T->getAs<PackExpansionType>()) {
5064 Changed = true;
5065
5066 // We have a pack expansion. Instantiate it.
5067 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5068 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5069 Unexpanded);
5070 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5071
5072 // Determine whether the set of unexpanded parameter packs can and
5073 // should
5074 // be expanded.
5075 bool Expand = false;
5076 bool RetainExpansion = false;
5077 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5078 // FIXME: Track the location of the ellipsis (and track source location
5079 // information for the types in the exception specification in general).
5080 if (getDerived().TryExpandParameterPacks(
5081 Loc, SourceRange(), Unexpanded, Expand,
5082 RetainExpansion, NumExpansions))
5083 return true;
5084
5085 if (!Expand) {
5086 // We can't expand this pack expansion into separate arguments yet;
5087 // just substitute into the pattern and create a new pack expansion
5088 // type.
5089 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5090 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5091 if (U.isNull())
5092 return true;
5093
5094 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5095 Exceptions.push_back(U);
5096 continue;
5097 }
5098
5099 // Substitute into the pack expansion pattern for each slice of the
5100 // pack.
5101 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5102 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5103
5104 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5105 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5106 return true;
5107
5108 Exceptions.push_back(U);
5109 }
5110 } else {
5111 QualType U = getDerived().TransformType(T);
5112 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5113 return true;
5114 if (T != U)
5115 Changed = true;
5116
5117 Exceptions.push_back(U);
5118 }
5119 }
5120
5121 ESI.Exceptions = Exceptions;
5122 return false;
5123}
5124
5125template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005126QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005127 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005128 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005129 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005130 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005131 if (ResultType.isNull())
5132 return QualType();
5133
5134 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005135 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005136 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5137
5138 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005139 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005140 NewTL.setLParenLoc(TL.getLParenLoc());
5141 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005142 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005143
5144 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005145}
Mike Stump11289f42009-09-09 15:08:12 +00005146
John McCallb96ec562009-12-04 22:46:56 +00005147template<typename Derived> QualType
5148TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005149 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005150 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005151 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005152 if (!D)
5153 return QualType();
5154
5155 QualType Result = TL.getType();
5156 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5157 Result = getDerived().RebuildUnresolvedUsingType(D);
5158 if (Result.isNull())
5159 return QualType();
5160 }
5161
5162 // We might get an arbitrary type spec type back. We should at
5163 // least always get a type spec type, though.
5164 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5165 NewTL.setNameLoc(TL.getNameLoc());
5166
5167 return Result;
5168}
5169
Douglas Gregord6ff3322009-08-04 16:50:30 +00005170template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005171QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005172 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005173 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005174 TypedefNameDecl *Typedef
5175 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5176 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005177 if (!Typedef)
5178 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005179
John McCall550e0c22009-10-21 00:40:46 +00005180 QualType Result = TL.getType();
5181 if (getDerived().AlwaysRebuild() ||
5182 Typedef != T->getDecl()) {
5183 Result = getDerived().RebuildTypedefType(Typedef);
5184 if (Result.isNull())
5185 return QualType();
5186 }
Mike Stump11289f42009-09-09 15:08:12 +00005187
John McCall550e0c22009-10-21 00:40:46 +00005188 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5189 NewTL.setNameLoc(TL.getNameLoc());
5190
5191 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005192}
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregord6ff3322009-08-04 16:50:30 +00005194template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005195QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005196 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005197 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005198 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5199 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005200
John McCalldadc5752010-08-24 06:29:42 +00005201 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005202 if (E.isInvalid())
5203 return QualType();
5204
Eli Friedmane4f22df2012-02-29 04:03:55 +00005205 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5206 if (E.isInvalid())
5207 return QualType();
5208
John McCall550e0c22009-10-21 00:40:46 +00005209 QualType Result = TL.getType();
5210 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005211 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005212 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005213 if (Result.isNull())
5214 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005215 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005216 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005217
John McCall550e0c22009-10-21 00:40:46 +00005218 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005219 NewTL.setTypeofLoc(TL.getTypeofLoc());
5220 NewTL.setLParenLoc(TL.getLParenLoc());
5221 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005222
5223 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005224}
Mike Stump11289f42009-09-09 15:08:12 +00005225
5226template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005227QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005228 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005229 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5230 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5231 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005232 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005233
John McCall550e0c22009-10-21 00:40:46 +00005234 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005235 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5236 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005237 if (Result.isNull())
5238 return QualType();
5239 }
Mike Stump11289f42009-09-09 15:08:12 +00005240
John McCall550e0c22009-10-21 00:40:46 +00005241 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005242 NewTL.setTypeofLoc(TL.getTypeofLoc());
5243 NewTL.setLParenLoc(TL.getLParenLoc());
5244 NewTL.setRParenLoc(TL.getRParenLoc());
5245 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005246
5247 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005248}
Mike Stump11289f42009-09-09 15:08:12 +00005249
5250template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005251QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005252 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005253 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005254
Douglas Gregore922c772009-08-04 22:27:00 +00005255 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005256 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5257 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005258
John McCalldadc5752010-08-24 06:29:42 +00005259 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005260 if (E.isInvalid())
5261 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005262
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005263 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005264 if (E.isInvalid())
5265 return QualType();
5266
John McCall550e0c22009-10-21 00:40:46 +00005267 QualType Result = TL.getType();
5268 if (getDerived().AlwaysRebuild() ||
5269 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005270 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005271 if (Result.isNull())
5272 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005273 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005274 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005275
John McCall550e0c22009-10-21 00:40:46 +00005276 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5277 NewTL.setNameLoc(TL.getNameLoc());
5278
5279 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280}
5281
5282template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005283QualType TreeTransform<Derived>::TransformUnaryTransformType(
5284 TypeLocBuilder &TLB,
5285 UnaryTransformTypeLoc TL) {
5286 QualType Result = TL.getType();
5287 if (Result->isDependentType()) {
5288 const UnaryTransformType *T = TL.getTypePtr();
5289 QualType NewBase =
5290 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5291 Result = getDerived().RebuildUnaryTransformType(NewBase,
5292 T->getUTTKind(),
5293 TL.getKWLoc());
5294 if (Result.isNull())
5295 return QualType();
5296 }
5297
5298 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5299 NewTL.setKWLoc(TL.getKWLoc());
5300 NewTL.setParensRange(TL.getParensRange());
5301 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5302 return Result;
5303}
5304
5305template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005306QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5307 AutoTypeLoc TL) {
5308 const AutoType *T = TL.getTypePtr();
5309 QualType OldDeduced = T->getDeducedType();
5310 QualType NewDeduced;
5311 if (!OldDeduced.isNull()) {
5312 NewDeduced = getDerived().TransformType(OldDeduced);
5313 if (NewDeduced.isNull())
5314 return QualType();
5315 }
5316
5317 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005318 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5319 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005320 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005321 if (Result.isNull())
5322 return QualType();
5323 }
5324
5325 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5326 NewTL.setNameLoc(TL.getNameLoc());
5327
5328 return Result;
5329}
5330
5331template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005332QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005333 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005334 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005335 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005336 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5337 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005338 if (!Record)
5339 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005340
John McCall550e0c22009-10-21 00:40:46 +00005341 QualType Result = TL.getType();
5342 if (getDerived().AlwaysRebuild() ||
5343 Record != T->getDecl()) {
5344 Result = getDerived().RebuildRecordType(Record);
5345 if (Result.isNull())
5346 return QualType();
5347 }
Mike Stump11289f42009-09-09 15:08:12 +00005348
John McCall550e0c22009-10-21 00:40:46 +00005349 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5350 NewTL.setNameLoc(TL.getNameLoc());
5351
5352 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005353}
Mike Stump11289f42009-09-09 15:08:12 +00005354
5355template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005356QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005357 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005358 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005359 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005360 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5361 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005362 if (!Enum)
5363 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005364
John McCall550e0c22009-10-21 00:40:46 +00005365 QualType Result = TL.getType();
5366 if (getDerived().AlwaysRebuild() ||
5367 Enum != T->getDecl()) {
5368 Result = getDerived().RebuildEnumType(Enum);
5369 if (Result.isNull())
5370 return QualType();
5371 }
Mike Stump11289f42009-09-09 15:08:12 +00005372
John McCall550e0c22009-10-21 00:40:46 +00005373 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5374 NewTL.setNameLoc(TL.getNameLoc());
5375
5376 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005377}
John McCallfcc33b02009-09-05 00:15:47 +00005378
John McCalle78aac42010-03-10 03:28:59 +00005379template<typename Derived>
5380QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5381 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005382 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005383 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5384 TL.getTypePtr()->getDecl());
5385 if (!D) return QualType();
5386
5387 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5388 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5389 return T;
5390}
5391
Douglas Gregord6ff3322009-08-04 16:50:30 +00005392template<typename Derived>
5393QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005394 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005395 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005396 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005397}
5398
Mike Stump11289f42009-09-09 15:08:12 +00005399template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005400QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005401 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005402 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005403 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005404
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005405 // Substitute into the replacement type, which itself might involve something
5406 // that needs to be transformed. This only tends to occur with default
5407 // template arguments of template template parameters.
5408 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5409 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5410 if (Replacement.isNull())
5411 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005412
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005413 // Always canonicalize the replacement type.
5414 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5415 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005416 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005417 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005418
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005419 // Propagate type-source information.
5420 SubstTemplateTypeParmTypeLoc NewTL
5421 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5422 NewTL.setNameLoc(TL.getNameLoc());
5423 return Result;
5424
John McCallcebee162009-10-18 09:09:24 +00005425}
5426
5427template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005428QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5429 TypeLocBuilder &TLB,
5430 SubstTemplateTypeParmPackTypeLoc TL) {
5431 return TransformTypeSpecType(TLB, TL);
5432}
5433
5434template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005435QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005436 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005437 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005438 const TemplateSpecializationType *T = TL.getTypePtr();
5439
Douglas Gregordf846d12011-03-02 18:46:51 +00005440 // The nested-name-specifier never matters in a TemplateSpecializationType,
5441 // because we can't have a dependent nested-name-specifier anyway.
5442 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005443 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005444 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5445 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005446 if (Template.isNull())
5447 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005448
John McCall31f82722010-11-12 08:19:04 +00005449 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5450}
5451
Eli Friedman0dfb8892011-10-06 23:00:33 +00005452template<typename Derived>
5453QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5454 AtomicTypeLoc TL) {
5455 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5456 if (ValueType.isNull())
5457 return QualType();
5458
5459 QualType Result = TL.getType();
5460 if (getDerived().AlwaysRebuild() ||
5461 ValueType != TL.getValueLoc().getType()) {
5462 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5463 if (Result.isNull())
5464 return QualType();
5465 }
5466
5467 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5468 NewTL.setKWLoc(TL.getKWLoc());
5469 NewTL.setLParenLoc(TL.getLParenLoc());
5470 NewTL.setRParenLoc(TL.getRParenLoc());
5471
5472 return Result;
5473}
5474
Xiuli Pan9c14e282016-01-09 12:53:17 +00005475template <typename Derived>
5476QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5477 PipeTypeLoc TL) {
5478 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5479 if (ValueType.isNull())
5480 return QualType();
5481
5482 QualType Result = TL.getType();
5483 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5484 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5485 if (Result.isNull())
5486 return QualType();
5487 }
5488
5489 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5490 NewTL.setKWLoc(TL.getKWLoc());
5491
5492 return Result;
5493}
5494
Chad Rosier1dcde962012-08-08 18:46:20 +00005495 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005496 /// container that provides a \c getArgLoc() member function.
5497 ///
5498 /// This iterator is intended to be used with the iterator form of
5499 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5500 template<typename ArgLocContainer>
5501 class TemplateArgumentLocContainerIterator {
5502 ArgLocContainer *Container;
5503 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005504
Douglas Gregorfe921a72010-12-20 23:36:19 +00005505 public:
5506 typedef TemplateArgumentLoc value_type;
5507 typedef TemplateArgumentLoc reference;
5508 typedef int difference_type;
5509 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005510
Douglas Gregorfe921a72010-12-20 23:36:19 +00005511 class pointer {
5512 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005513
Douglas Gregorfe921a72010-12-20 23:36:19 +00005514 public:
5515 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005516
Douglas Gregorfe921a72010-12-20 23:36:19 +00005517 const TemplateArgumentLoc *operator->() const {
5518 return &Arg;
5519 }
5520 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005521
5522
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005523 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005524
Douglas Gregorfe921a72010-12-20 23:36:19 +00005525 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5526 unsigned Index)
5527 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005528
Douglas Gregorfe921a72010-12-20 23:36:19 +00005529 TemplateArgumentLocContainerIterator &operator++() {
5530 ++Index;
5531 return *this;
5532 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005533
Douglas Gregorfe921a72010-12-20 23:36:19 +00005534 TemplateArgumentLocContainerIterator operator++(int) {
5535 TemplateArgumentLocContainerIterator Old(*this);
5536 ++(*this);
5537 return Old;
5538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005539
Douglas Gregorfe921a72010-12-20 23:36:19 +00005540 TemplateArgumentLoc operator*() const {
5541 return Container->getArgLoc(Index);
5542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005543
Douglas Gregorfe921a72010-12-20 23:36:19 +00005544 pointer operator->() const {
5545 return pointer(Container->getArgLoc(Index));
5546 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005547
Douglas Gregorfe921a72010-12-20 23:36:19 +00005548 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005549 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005550 return X.Container == Y.Container && X.Index == Y.Index;
5551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregorfe921a72010-12-20 23:36:19 +00005553 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005554 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005555 return !(X == Y);
5556 }
5557 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005558
5559
John McCall31f82722010-11-12 08:19:04 +00005560template <typename Derived>
5561QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5562 TypeLocBuilder &TLB,
5563 TemplateSpecializationTypeLoc TL,
5564 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005565 TemplateArgumentListInfo NewTemplateArgs;
5566 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5567 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005568 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5569 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005570 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005571 ArgIterator(TL, TL.getNumArgs()),
5572 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005573 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005574
John McCall0ad16662009-10-29 08:12:44 +00005575 // FIXME: maybe don't rebuild if all the template arguments are the same.
5576
5577 QualType Result =
5578 getDerived().RebuildTemplateSpecializationType(Template,
5579 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005580 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005581
5582 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005583 // Specializations of template template parameters are represented as
5584 // TemplateSpecializationTypes, and substitution of type alias templates
5585 // within a dependent context can transform them into
5586 // DependentTemplateSpecializationTypes.
5587 if (isa<DependentTemplateSpecializationType>(Result)) {
5588 DependentTemplateSpecializationTypeLoc NewTL
5589 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005590 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005591 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005592 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005593 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005594 NewTL.setLAngleLoc(TL.getLAngleLoc());
5595 NewTL.setRAngleLoc(TL.getRAngleLoc());
5596 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5597 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5598 return Result;
5599 }
5600
John McCall0ad16662009-10-29 08:12:44 +00005601 TemplateSpecializationTypeLoc NewTL
5602 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005603 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005604 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5605 NewTL.setLAngleLoc(TL.getLAngleLoc());
5606 NewTL.setRAngleLoc(TL.getRAngleLoc());
5607 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5608 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005609 }
Mike Stump11289f42009-09-09 15:08:12 +00005610
John McCall0ad16662009-10-29 08:12:44 +00005611 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005612}
Mike Stump11289f42009-09-09 15:08:12 +00005613
Douglas Gregor5a064722011-02-28 17:23:35 +00005614template <typename Derived>
5615QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5616 TypeLocBuilder &TLB,
5617 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005618 TemplateName Template,
5619 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005620 TemplateArgumentListInfo NewTemplateArgs;
5621 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5622 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5623 typedef TemplateArgumentLocContainerIterator<
5624 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005625 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005626 ArgIterator(TL, TL.getNumArgs()),
5627 NewTemplateArgs))
5628 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005629
Douglas Gregor5a064722011-02-28 17:23:35 +00005630 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005631
Douglas Gregor5a064722011-02-28 17:23:35 +00005632 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5633 QualType Result
5634 = getSema().Context.getDependentTemplateSpecializationType(
5635 TL.getTypePtr()->getKeyword(),
5636 DTN->getQualifier(),
5637 DTN->getIdentifier(),
5638 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005639
Douglas Gregor5a064722011-02-28 17:23:35 +00005640 DependentTemplateSpecializationTypeLoc NewTL
5641 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005642 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005643 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005644 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005645 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005646 NewTL.setLAngleLoc(TL.getLAngleLoc());
5647 NewTL.setRAngleLoc(TL.getRAngleLoc());
5648 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5649 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5650 return Result;
5651 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005652
5653 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005654 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005655 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005656 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005657
Douglas Gregor5a064722011-02-28 17:23:35 +00005658 if (!Result.isNull()) {
5659 /// FIXME: Wrap this in an elaborated-type-specifier?
5660 TemplateSpecializationTypeLoc NewTL
5661 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005662 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005663 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005664 NewTL.setLAngleLoc(TL.getLAngleLoc());
5665 NewTL.setRAngleLoc(TL.getRAngleLoc());
5666 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5667 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005669
Douglas Gregor5a064722011-02-28 17:23:35 +00005670 return Result;
5671}
5672
Mike Stump11289f42009-09-09 15:08:12 +00005673template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005674QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005675TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005676 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005677 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005678
Douglas Gregor844cb502011-03-01 18:12:44 +00005679 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005680 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005681 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005682 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005683 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5684 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005685 return QualType();
5686 }
Mike Stump11289f42009-09-09 15:08:12 +00005687
John McCall31f82722010-11-12 08:19:04 +00005688 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5689 if (NamedT.isNull())
5690 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005691
Richard Smith3f1b5d02011-05-05 21:57:07 +00005692 // C++0x [dcl.type.elab]p2:
5693 // If the identifier resolves to a typedef-name or the simple-template-id
5694 // resolves to an alias template specialization, the
5695 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005696 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5697 if (const TemplateSpecializationType *TST =
5698 NamedT->getAs<TemplateSpecializationType>()) {
5699 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005700 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5701 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005702 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005703 diag::err_tag_reference_non_tag)
5704 << Sema::NTK_TypeAliasTemplate;
Richard Smith0c4a34b2011-05-14 15:04:18 +00005705 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5706 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005707 }
5708 }
5709
John McCall550e0c22009-10-21 00:40:46 +00005710 QualType Result = TL.getType();
5711 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005712 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005713 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005714 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005715 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005716 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005717 if (Result.isNull())
5718 return QualType();
5719 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005720
Abramo Bagnara6150c882010-05-11 21:36:43 +00005721 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005722 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005723 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005724 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005725}
Mike Stump11289f42009-09-09 15:08:12 +00005726
5727template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005728QualType TreeTransform<Derived>::TransformAttributedType(
5729 TypeLocBuilder &TLB,
5730 AttributedTypeLoc TL) {
5731 const AttributedType *oldType = TL.getTypePtr();
5732 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5733 if (modifiedType.isNull())
5734 return QualType();
5735
5736 QualType result = TL.getType();
5737
5738 // FIXME: dependent operand expressions?
5739 if (getDerived().AlwaysRebuild() ||
5740 modifiedType != oldType->getModifiedType()) {
5741 // TODO: this is really lame; we should really be rebuilding the
5742 // equivalent type from first principles.
5743 QualType equivalentType
5744 = getDerived().TransformType(oldType->getEquivalentType());
5745 if (equivalentType.isNull())
5746 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005747
5748 // Check whether we can add nullability; it is only represented as
5749 // type sugar, and therefore cannot be diagnosed in any other way.
5750 if (auto nullability = oldType->getImmediateNullability()) {
5751 if (!modifiedType->canHaveNullability()) {
5752 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005753 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005754 return QualType();
5755 }
5756 }
5757
John McCall81904512011-01-06 01:58:22 +00005758 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5759 modifiedType,
5760 equivalentType);
5761 }
5762
5763 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5764 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5765 if (TL.hasAttrOperand())
5766 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5767 if (TL.hasAttrExprOperand())
5768 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5769 else if (TL.hasAttrEnumOperand())
5770 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5771
5772 return result;
5773}
5774
5775template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005776QualType
5777TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5778 ParenTypeLoc TL) {
5779 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5780 if (Inner.isNull())
5781 return QualType();
5782
5783 QualType Result = TL.getType();
5784 if (getDerived().AlwaysRebuild() ||
5785 Inner != TL.getInnerLoc().getType()) {
5786 Result = getDerived().RebuildParenType(Inner);
5787 if (Result.isNull())
5788 return QualType();
5789 }
5790
5791 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5792 NewTL.setLParenLoc(TL.getLParenLoc());
5793 NewTL.setRParenLoc(TL.getRParenLoc());
5794 return Result;
5795}
5796
5797template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005798QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005799 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005800 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005801
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005802 NestedNameSpecifierLoc QualifierLoc
5803 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5804 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005805 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005806
John McCallc392f372010-06-11 00:33:02 +00005807 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005808 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005809 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005810 QualifierLoc,
5811 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005812 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005813 if (Result.isNull())
5814 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005815
Abramo Bagnarad7548482010-05-19 21:37:53 +00005816 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5817 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005818 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5819
Abramo Bagnarad7548482010-05-19 21:37:53 +00005820 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005821 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005822 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005823 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005824 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005825 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005826 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005827 NewTL.setNameLoc(TL.getNameLoc());
5828 }
John McCall550e0c22009-10-21 00:40:46 +00005829 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005830}
Mike Stump11289f42009-09-09 15:08:12 +00005831
Douglas Gregord6ff3322009-08-04 16:50:30 +00005832template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005833QualType TreeTransform<Derived>::
5834 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005835 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005836 NestedNameSpecifierLoc QualifierLoc;
5837 if (TL.getQualifierLoc()) {
5838 QualifierLoc
5839 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5840 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005841 return QualType();
5842 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005843
John McCall31f82722010-11-12 08:19:04 +00005844 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005845 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005846}
5847
5848template<typename Derived>
5849QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005850TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5851 DependentTemplateSpecializationTypeLoc TL,
5852 NestedNameSpecifierLoc QualifierLoc) {
5853 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005854
Douglas Gregora7a795b2011-03-01 20:11:18 +00005855 TemplateArgumentListInfo NewTemplateArgs;
5856 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5857 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Douglas Gregora7a795b2011-03-01 20:11:18 +00005859 typedef TemplateArgumentLocContainerIterator<
5860 DependentTemplateSpecializationTypeLoc> ArgIterator;
5861 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5862 ArgIterator(TL, TL.getNumArgs()),
5863 NewTemplateArgs))
5864 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005865
Douglas Gregora7a795b2011-03-01 20:11:18 +00005866 QualType Result
5867 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5868 QualifierLoc,
5869 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005870 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005871 NewTemplateArgs);
5872 if (Result.isNull())
5873 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005874
Douglas Gregora7a795b2011-03-01 20:11:18 +00005875 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5876 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005877
Douglas Gregora7a795b2011-03-01 20:11:18 +00005878 // Copy information relevant to the template specialization.
5879 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005880 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005881 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005882 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005883 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5884 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005885 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005886 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005887
Douglas Gregora7a795b2011-03-01 20:11:18 +00005888 // Copy information relevant to the elaborated type.
5889 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005890 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005891 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005892 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5893 DependentTemplateSpecializationTypeLoc SpecTL
5894 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005895 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005896 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005897 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005898 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005899 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5900 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005901 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005902 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005903 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005904 TemplateSpecializationTypeLoc SpecTL
5905 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005906 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005907 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005908 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5909 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005910 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005911 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005912 }
5913 return Result;
5914}
5915
5916template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005917QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5918 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005919 QualType Pattern
5920 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005921 if (Pattern.isNull())
5922 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005923
5924 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005925 if (getDerived().AlwaysRebuild() ||
5926 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005927 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005928 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005929 TL.getEllipsisLoc(),
5930 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005931 if (Result.isNull())
5932 return QualType();
5933 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005934
Douglas Gregor822d0302011-01-12 17:07:58 +00005935 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5936 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5937 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005938}
5939
5940template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005941QualType
5942TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005943 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005944 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005945 TLB.pushFullCopy(TL);
5946 return TL.getType();
5947}
5948
5949template<typename Derived>
5950QualType
Manman Rene6be26c2016-09-13 17:25:08 +00005951TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
5952 ObjCTypeParamTypeLoc TL) {
5953 const ObjCTypeParamType *T = TL.getTypePtr();
5954 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
5955 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
5956 if (!OTP)
5957 return QualType();
5958
5959 QualType Result = TL.getType();
5960 if (getDerived().AlwaysRebuild() ||
5961 OTP != T->getDecl()) {
5962 Result = getDerived().RebuildObjCTypeParamType(OTP,
5963 TL.getProtocolLAngleLoc(),
5964 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5965 TL.getNumProtocols()),
5966 TL.getProtocolLocs(),
5967 TL.getProtocolRAngleLoc());
5968 if (Result.isNull())
5969 return QualType();
5970 }
5971
5972 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
5973 if (TL.getNumProtocols()) {
5974 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5975 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5976 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
5977 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5978 }
5979 return Result;
5980}
5981
5982template<typename Derived>
5983QualType
John McCall8b07ec22010-05-15 11:32:37 +00005984TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005985 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005986 // Transform base type.
5987 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5988 if (BaseType.isNull())
5989 return QualType();
5990
5991 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5992
5993 // Transform type arguments.
5994 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5995 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5996 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5997 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5998 QualType TypeArg = TypeArgInfo->getType();
5999 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6000 AnyChanged = true;
6001
6002 // We have a pack expansion. Instantiate it.
6003 const auto *PackExpansion = PackExpansionLoc.getType()
6004 ->castAs<PackExpansionType>();
6005 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6006 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6007 Unexpanded);
6008 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6009
6010 // Determine whether the set of unexpanded parameter packs can
6011 // and should be expanded.
6012 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6013 bool Expand = false;
6014 bool RetainExpansion = false;
6015 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6016 if (getDerived().TryExpandParameterPacks(
6017 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6018 Unexpanded, Expand, RetainExpansion, NumExpansions))
6019 return QualType();
6020
6021 if (!Expand) {
6022 // We can't expand this pack expansion into separate arguments yet;
6023 // just substitute into the pattern and create a new pack expansion
6024 // type.
6025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6026
6027 TypeLocBuilder TypeArgBuilder;
6028 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6029 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6030 PatternLoc);
6031 if (NewPatternType.isNull())
6032 return QualType();
6033
6034 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6035 NewPatternType, NumExpansions);
6036 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6037 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6038 NewTypeArgInfos.push_back(
6039 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6040 continue;
6041 }
6042
6043 // Substitute into the pack expansion pattern for each slice of the
6044 // pack.
6045 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6046 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6047
6048 TypeLocBuilder TypeArgBuilder;
6049 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6050
6051 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6052 PatternLoc);
6053 if (NewTypeArg.isNull())
6054 return QualType();
6055
6056 NewTypeArgInfos.push_back(
6057 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6058 }
6059
6060 continue;
6061 }
6062
6063 TypeLocBuilder TypeArgBuilder;
6064 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6065 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6066 if (NewTypeArg.isNull())
6067 return QualType();
6068
6069 // If nothing changed, just keep the old TypeSourceInfo.
6070 if (NewTypeArg == TypeArg) {
6071 NewTypeArgInfos.push_back(TypeArgInfo);
6072 continue;
6073 }
6074
6075 NewTypeArgInfos.push_back(
6076 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6077 AnyChanged = true;
6078 }
6079
6080 QualType Result = TL.getType();
6081 if (getDerived().AlwaysRebuild() || AnyChanged) {
6082 // Rebuild the type.
6083 Result = getDerived().RebuildObjCObjectType(
6084 BaseType,
6085 TL.getLocStart(),
6086 TL.getTypeArgsLAngleLoc(),
6087 NewTypeArgInfos,
6088 TL.getTypeArgsRAngleLoc(),
6089 TL.getProtocolLAngleLoc(),
6090 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6091 TL.getNumProtocols()),
6092 TL.getProtocolLocs(),
6093 TL.getProtocolRAngleLoc());
6094
6095 if (Result.isNull())
6096 return QualType();
6097 }
6098
6099 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006100 NewT.setHasBaseTypeAsWritten(true);
6101 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6102 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6103 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6104 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6105 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6106 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6107 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6108 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6109 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006110}
Mike Stump11289f42009-09-09 15:08:12 +00006111
6112template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006113QualType
6114TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006115 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006116 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6117 if (PointeeType.isNull())
6118 return QualType();
6119
6120 QualType Result = TL.getType();
6121 if (getDerived().AlwaysRebuild() ||
6122 PointeeType != TL.getPointeeLoc().getType()) {
6123 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6124 TL.getStarLoc());
6125 if (Result.isNull())
6126 return QualType();
6127 }
6128
6129 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6130 NewT.setStarLoc(TL.getStarLoc());
6131 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006132}
6133
Douglas Gregord6ff3322009-08-04 16:50:30 +00006134//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006135// Statement transformation
6136//===----------------------------------------------------------------------===//
6137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006138StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006139TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006140 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006141}
6142
6143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006144StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006145TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6146 return getDerived().TransformCompoundStmt(S, false);
6147}
6148
6149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006150StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006151TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006152 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006153 Sema::CompoundScopeRAII CompoundScope(getSema());
6154
John McCall1ababa62010-08-27 19:56:05 +00006155 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006156 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006157 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006158 for (auto *B : S->body()) {
6159 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006160 if (Result.isInvalid()) {
6161 // Immediately fail if this was a DeclStmt, since it's very
6162 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006163 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006164 return StmtError();
6165
6166 // Otherwise, just keep processing substatements and fail later.
6167 SubStmtInvalid = true;
6168 continue;
6169 }
Mike Stump11289f42009-09-09 15:08:12 +00006170
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006171 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006172 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006173 }
Mike Stump11289f42009-09-09 15:08:12 +00006174
John McCall1ababa62010-08-27 19:56:05 +00006175 if (SubStmtInvalid)
6176 return StmtError();
6177
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 if (!getDerived().AlwaysRebuild() &&
6179 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006180 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006181
6182 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006183 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006184 S->getRBracLoc(),
6185 IsStmtExpr);
6186}
Mike Stump11289f42009-09-09 15:08:12 +00006187
Douglas Gregorebe10102009-08-20 07:17:43 +00006188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006189StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006190TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006191 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006192 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006193 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6194 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006195
Eli Friedman06577382009-11-19 03:14:00 +00006196 // Transform the left-hand case value.
6197 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006198 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006199 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006200 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006201
Eli Friedman06577382009-11-19 03:14:00 +00006202 // Transform the right-hand case value (for the GNU case-range extension).
6203 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006204 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006205 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006207 }
Mike Stump11289f42009-09-09 15:08:12 +00006208
Douglas Gregorebe10102009-08-20 07:17:43 +00006209 // Build the case statement.
6210 // Case statements are always rebuilt so that they will attached to their
6211 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006212 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006213 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006214 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006215 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006216 S->getColonLoc());
6217 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006218 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006219
Douglas Gregorebe10102009-08-20 07:17:43 +00006220 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006221 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006222 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006224
Douglas Gregorebe10102009-08-20 07:17:43 +00006225 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006226 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006227}
6228
6229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006230StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006231TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006232 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006233 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006234 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006235 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregorebe10102009-08-20 07:17:43 +00006237 // Default statements are always rebuilt
6238 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006239 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006240}
Mike Stump11289f42009-09-09 15:08:12 +00006241
Douglas Gregorebe10102009-08-20 07:17:43 +00006242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006243StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006244TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006245 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006246 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006247 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006248
Chris Lattnercab02a62011-02-17 20:34:02 +00006249 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6250 S->getDecl());
6251 if (!LD)
6252 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006253
6254
Douglas Gregorebe10102009-08-20 07:17:43 +00006255 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006256 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006257 cast<LabelDecl>(LD), SourceLocation(),
6258 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006259}
Mike Stump11289f42009-09-09 15:08:12 +00006260
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006261template <typename Derived>
6262const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6263 if (!R)
6264 return R;
6265
6266 switch (R->getKind()) {
6267// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6268#define ATTR(X)
6269#define PRAGMA_SPELLING_ATTR(X) \
6270 case attr::X: \
6271 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6272#include "clang/Basic/AttrList.inc"
6273 default:
6274 return R;
6275 }
6276}
6277
6278template <typename Derived>
6279StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6280 bool AttrsChanged = false;
6281 SmallVector<const Attr *, 1> Attrs;
6282
6283 // Visit attributes and keep track if any are transformed.
6284 for (const auto *I : S->getAttrs()) {
6285 const Attr *R = getDerived().TransformAttr(I);
6286 AttrsChanged |= (I != R);
6287 Attrs.push_back(R);
6288 }
6289
Richard Smithc202b282012-04-14 00:33:13 +00006290 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6291 if (SubStmt.isInvalid())
6292 return StmtError();
6293
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006294 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006295 return S;
6296
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006297 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006298 SubStmt.get());
6299}
6300
6301template<typename Derived>
6302StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006303TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006304 // Transform the initialization statement
6305 StmtResult Init = getDerived().TransformStmt(S->getInit());
6306 if (Init.isInvalid())
6307 return StmtError();
6308
Douglas Gregorebe10102009-08-20 07:17:43 +00006309 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006310 Sema::ConditionResult Cond = getDerived().TransformCondition(
6311 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006312 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6313 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006314 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006315 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006316
Richard Smithb130fe72016-06-23 19:16:49 +00006317 // If this is a constexpr if, determine which arm we should instantiate.
6318 llvm::Optional<bool> ConstexprConditionValue;
6319 if (S->isConstexpr())
6320 ConstexprConditionValue = Cond.getKnownValue();
6321
Douglas Gregorebe10102009-08-20 07:17:43 +00006322 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006323 StmtResult Then;
6324 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6325 Then = getDerived().TransformStmt(S->getThen());
6326 if (Then.isInvalid())
6327 return StmtError();
6328 } else {
6329 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6330 }
Mike Stump11289f42009-09-09 15:08:12 +00006331
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006333 StmtResult Else;
6334 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6335 Else = getDerived().TransformStmt(S->getElse());
6336 if (Else.isInvalid())
6337 return StmtError();
6338 }
Mike Stump11289f42009-09-09 15:08:12 +00006339
Douglas Gregorebe10102009-08-20 07:17:43 +00006340 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006341 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006342 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006343 Then.get() == S->getThen() &&
6344 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006345 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006346
Richard Smithb130fe72016-06-23 19:16:49 +00006347 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006348 Init.get(), Then.get(), S->getElseLoc(),
6349 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006350}
6351
6352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006353StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006354TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006355 // Transform the initialization statement
6356 StmtResult Init = getDerived().TransformStmt(S->getInit());
6357 if (Init.isInvalid())
6358 return StmtError();
6359
Douglas Gregorebe10102009-08-20 07:17:43 +00006360 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006361 Sema::ConditionResult Cond = getDerived().TransformCondition(
6362 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6363 Sema::ConditionKind::Switch);
6364 if (Cond.isInvalid())
6365 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregorebe10102009-08-20 07:17:43 +00006367 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006368 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006369 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6370 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006371 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006372 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregorebe10102009-08-20 07:17:43 +00006374 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006375 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006376 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006378
Douglas Gregorebe10102009-08-20 07:17:43 +00006379 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006380 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6381 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006382}
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregorebe10102009-08-20 07:17:43 +00006384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006385StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006386TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006387 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006388 Sema::ConditionResult Cond = getDerived().TransformCondition(
6389 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6390 Sema::ConditionKind::Boolean);
6391 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006392 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006393
Douglas Gregorebe10102009-08-20 07:17:43 +00006394 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006395 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006396 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006397 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006398
Douglas Gregorebe10102009-08-20 07:17:43 +00006399 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006400 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006401 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006402 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006403
Richard Smith03a4aa32016-06-23 19:02:52 +00006404 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006405}
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregorebe10102009-08-20 07:17:43 +00006407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006408StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006409TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006410 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006411 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006412 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006413 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006414
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006415 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006416 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006417 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006418 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006419
Douglas Gregorebe10102009-08-20 07:17:43 +00006420 if (!getDerived().AlwaysRebuild() &&
6421 Cond.get() == S->getCond() &&
6422 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006423 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006424
John McCallb268a282010-08-23 23:25:46 +00006425 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6426 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006427 S->getRParenLoc());
6428}
Mike Stump11289f42009-09-09 15:08:12 +00006429
Douglas Gregorebe10102009-08-20 07:17:43 +00006430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006431StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006432TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006433 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006434 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006435 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006436 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006437
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006438 // In OpenMP loop region loop control variable must be captured and be
6439 // private. Perform analysis of first part (if any).
6440 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6441 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6442
Douglas Gregorebe10102009-08-20 07:17:43 +00006443 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006444 Sema::ConditionResult Cond = getDerived().TransformCondition(
6445 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6446 Sema::ConditionKind::Boolean);
6447 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006448 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006449
Douglas Gregorebe10102009-08-20 07:17:43 +00006450 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006451 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006452 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006453 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006454
Richard Smith945f8d32013-01-14 22:39:08 +00006455 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006456 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006457 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006458
Douglas Gregorebe10102009-08-20 07:17:43 +00006459 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006460 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006461 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006462 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006463
Douglas Gregorebe10102009-08-20 07:17:43 +00006464 if (!getDerived().AlwaysRebuild() &&
6465 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006466 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006467 Inc.get() == S->getInc() &&
6468 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006469 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006470
Douglas Gregorebe10102009-08-20 07:17:43 +00006471 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006472 Init.get(), Cond, FullInc,
6473 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006474}
6475
6476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006477StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006478TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006479 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6480 S->getLabel());
6481 if (!LD)
6482 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006483
Douglas Gregorebe10102009-08-20 07:17:43 +00006484 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006485 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006486 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006487}
6488
6489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006490StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006491TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006492 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006493 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006494 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006495 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006496
Douglas Gregorebe10102009-08-20 07:17:43 +00006497 if (!getDerived().AlwaysRebuild() &&
6498 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006499 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006500
6501 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006502 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006503}
6504
6505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006506StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006507TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006508 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006509}
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregorebe10102009-08-20 07:17:43 +00006511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006512StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006513TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006514 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregorebe10102009-08-20 07:17:43 +00006517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006518StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006519TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006520 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6521 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006522 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006523 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006524
Mike Stump11289f42009-09-09 15:08:12 +00006525 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006526 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006527 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006528}
Mike Stump11289f42009-09-09 15:08:12 +00006529
Douglas Gregorebe10102009-08-20 07:17:43 +00006530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006531StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006532TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006533 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006534 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006535 for (auto *D : S->decls()) {
6536 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006537 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006538 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006539
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006540 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006541 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006542
Douglas Gregorebe10102009-08-20 07:17:43 +00006543 Decls.push_back(Transformed);
6544 }
Mike Stump11289f42009-09-09 15:08:12 +00006545
Douglas Gregorebe10102009-08-20 07:17:43 +00006546 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006547 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006548
Rafael Espindolaab417692013-07-09 12:05:01 +00006549 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006550}
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregorebe10102009-08-20 07:17:43 +00006552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006553StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006554TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006555
Benjamin Kramerf0623432012-08-23 22:51:59 +00006556 SmallVector<Expr*, 8> Constraints;
6557 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006558 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006559
John McCalldadc5752010-08-24 06:29:42 +00006560 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006561 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006562
6563 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006564
Anders Carlssonaaeef072010-01-24 05:50:09 +00006565 // Go through the outputs.
6566 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006567 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006568
Anders Carlssonaaeef072010-01-24 05:50:09 +00006569 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006570 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006571
Anders Carlssonaaeef072010-01-24 05:50:09 +00006572 // Transform the output expr.
6573 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006574 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006575 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006577
Anders Carlssonaaeef072010-01-24 05:50:09 +00006578 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006579
John McCallb268a282010-08-23 23:25:46 +00006580 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Anders Carlssonaaeef072010-01-24 05:50:09 +00006583 // Go through the inputs.
6584 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006585 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006586
Anders Carlssonaaeef072010-01-24 05:50:09 +00006587 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006588 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006589
Anders Carlssonaaeef072010-01-24 05:50:09 +00006590 // Transform the input expr.
6591 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006592 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006593 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006594 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006595
Anders Carlssonaaeef072010-01-24 05:50:09 +00006596 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006597
John McCallb268a282010-08-23 23:25:46 +00006598 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006599 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006600
Anders Carlssonaaeef072010-01-24 05:50:09 +00006601 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006602 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006603
6604 // Go through the clobbers.
6605 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006606 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006607
6608 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006609 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006610 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6611 S->isVolatile(), S->getNumOutputs(),
6612 S->getNumInputs(), Names.data(),
6613 Constraints, Exprs, AsmString.get(),
6614 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006615}
6616
Chad Rosier32503022012-06-11 20:47:18 +00006617template<typename Derived>
6618StmtResult
6619TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006620 ArrayRef<Token> AsmToks =
6621 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006622
John McCallf413f5e2013-05-03 00:10:13 +00006623 bool HadError = false, HadChange = false;
6624
6625 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6626 SmallVector<Expr*, 8> TransformedExprs;
6627 TransformedExprs.reserve(SrcExprs.size());
6628 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6629 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6630 if (!Result.isUsable()) {
6631 HadError = true;
6632 } else {
6633 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006634 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006635 }
6636 }
6637
6638 if (HadError) return StmtError();
6639 if (!HadChange && !getDerived().AlwaysRebuild())
6640 return Owned(S);
6641
Chad Rosierb6f46c12012-08-15 16:53:30 +00006642 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006643 AsmToks, S->getAsmString(),
6644 S->getNumOutputs(), S->getNumInputs(),
6645 S->getAllConstraints(), S->getClobbers(),
6646 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006647}
Douglas Gregorebe10102009-08-20 07:17:43 +00006648
Richard Smith9f690bd2015-10-27 06:02:45 +00006649// C++ Coroutines TS
6650
6651template<typename Derived>
6652StmtResult
6653TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6654 // The coroutine body should be re-formed by the caller if necessary.
6655 return getDerived().TransformStmt(S->getBody());
6656}
6657
6658template<typename Derived>
6659StmtResult
6660TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6661 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6662 /*NotCopyInit*/false);
6663 if (Result.isInvalid())
6664 return StmtError();
6665
6666 // Always rebuild; we don't know if this needs to be injected into a new
6667 // context or if the promise type has changed.
6668 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6669}
6670
6671template<typename Derived>
6672ExprResult
6673TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6674 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6675 /*NotCopyInit*/false);
6676 if (Result.isInvalid())
6677 return ExprError();
6678
6679 // Always rebuild; we don't know if this needs to be injected into a new
6680 // context or if the promise type has changed.
6681 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6682}
6683
6684template<typename Derived>
6685ExprResult
6686TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6687 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6688 /*NotCopyInit*/false);
6689 if (Result.isInvalid())
6690 return ExprError();
6691
6692 // Always rebuild; we don't know if this needs to be injected into a new
6693 // context or if the promise type has changed.
6694 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6695}
6696
6697// Objective-C Statements.
6698
Douglas Gregorebe10102009-08-20 07:17:43 +00006699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006700StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006701TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006702 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006703 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006704 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006706
Douglas Gregor96c79492010-04-23 22:50:49 +00006707 // Transform the @catch statements (if present).
6708 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006709 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006710 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006711 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006712 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006713 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006714 if (Catch.get() != S->getCatchStmt(I))
6715 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006716 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006718
Douglas Gregor306de2f2010-04-22 23:59:56 +00006719 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006720 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006721 if (S->getFinallyStmt()) {
6722 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6723 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006724 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006725 }
6726
6727 // If nothing changed, just retain this statement.
6728 if (!getDerived().AlwaysRebuild() &&
6729 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006730 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006731 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006732 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006733
Douglas Gregor306de2f2010-04-22 23:59:56 +00006734 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006735 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006736 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006737}
Mike Stump11289f42009-09-09 15:08:12 +00006738
Douglas Gregorebe10102009-08-20 07:17:43 +00006739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006740StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006741TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006742 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006743 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006744 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006745 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006746 if (FromVar->getTypeSourceInfo()) {
6747 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6748 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006749 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006750 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006751
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006752 QualType T;
6753 if (TSInfo)
6754 T = TSInfo->getType();
6755 else {
6756 T = getDerived().TransformType(FromVar->getType());
6757 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006758 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006760
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006761 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6762 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006763 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006765
John McCalldadc5752010-08-24 06:29:42 +00006766 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006767 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006768 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
6770 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006771 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006772 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006773}
Mike Stump11289f42009-09-09 15:08:12 +00006774
Douglas Gregorebe10102009-08-20 07:17:43 +00006775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006776StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006777TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006778 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006779 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006780 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006781 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006782
Douglas Gregor306de2f2010-04-22 23:59:56 +00006783 // If nothing changed, just retain this statement.
6784 if (!getDerived().AlwaysRebuild() &&
6785 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006786 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006787
6788 // Build a new statement.
6789 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006790 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006791}
Mike Stump11289f42009-09-09 15:08:12 +00006792
Douglas Gregorebe10102009-08-20 07:17:43 +00006793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006794StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006795TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006796 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006797 if (S->getThrowExpr()) {
6798 Operand = getDerived().TransformExpr(S->getThrowExpr());
6799 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006800 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006801 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006802
Douglas Gregor2900c162010-04-22 21:44:01 +00006803 if (!getDerived().AlwaysRebuild() &&
6804 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006805 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006806
John McCallb268a282010-08-23 23:25:46 +00006807 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006808}
Mike Stump11289f42009-09-09 15:08:12 +00006809
Douglas Gregorebe10102009-08-20 07:17:43 +00006810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006811StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006812TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006813 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006814 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006815 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006816 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006817 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006818 Object =
6819 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6820 Object.get());
6821 if (Object.isInvalid())
6822 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006823
Douglas Gregor6148de72010-04-22 22:01:21 +00006824 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006825 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006826 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006827 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006828
Douglas Gregor6148de72010-04-22 22:01:21 +00006829 // If nothing change, just retain the current statement.
6830 if (!getDerived().AlwaysRebuild() &&
6831 Object.get() == S->getSynchExpr() &&
6832 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006833 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006834
6835 // Build a new statement.
6836 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006837 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006838}
6839
6840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006841StmtResult
John McCall31168b02011-06-15 23:02:42 +00006842TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6843 ObjCAutoreleasePoolStmt *S) {
6844 // Transform the body.
6845 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6846 if (Body.isInvalid())
6847 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006848
John McCall31168b02011-06-15 23:02:42 +00006849 // If nothing changed, just retain this statement.
6850 if (!getDerived().AlwaysRebuild() &&
6851 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006852 return S;
John McCall31168b02011-06-15 23:02:42 +00006853
6854 // Build a new statement.
6855 return getDerived().RebuildObjCAutoreleasePoolStmt(
6856 S->getAtLoc(), Body.get());
6857}
6858
6859template<typename Derived>
6860StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006861TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006862 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006863 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006864 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006865 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006866 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006867
Douglas Gregorf68a5082010-04-22 23:10:45 +00006868 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006869 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006870 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006872
Douglas Gregorf68a5082010-04-22 23:10:45 +00006873 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006874 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006875 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006876 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006877
Douglas Gregorf68a5082010-04-22 23:10:45 +00006878 // If nothing changed, just retain this statement.
6879 if (!getDerived().AlwaysRebuild() &&
6880 Element.get() == S->getElement() &&
6881 Collection.get() == S->getCollection() &&
6882 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006883 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006884
Douglas Gregorf68a5082010-04-22 23:10:45 +00006885 // Build a new statement.
6886 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006887 Element.get(),
6888 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006889 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006890 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006891}
6892
David Majnemer5f7efef2013-10-15 09:50:08 +00006893template <typename Derived>
6894StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006895 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006896 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006897 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6898 TypeSourceInfo *T =
6899 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006900 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006901 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006902
David Majnemer5f7efef2013-10-15 09:50:08 +00006903 Var = getDerived().RebuildExceptionDecl(
6904 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6905 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006906 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006907 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006908 }
Mike Stump11289f42009-09-09 15:08:12 +00006909
Douglas Gregorebe10102009-08-20 07:17:43 +00006910 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006911 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006912 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006913 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006914
David Majnemer5f7efef2013-10-15 09:50:08 +00006915 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006916 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006917 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006918
David Majnemer5f7efef2013-10-15 09:50:08 +00006919 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006920}
Mike Stump11289f42009-09-09 15:08:12 +00006921
David Majnemer5f7efef2013-10-15 09:50:08 +00006922template <typename Derived>
6923StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006924 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006925 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006926 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006927 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006928
Douglas Gregorebe10102009-08-20 07:17:43 +00006929 // Transform the handlers.
6930 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006931 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006932 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006933 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006934 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006935 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006936
Douglas Gregorebe10102009-08-20 07:17:43 +00006937 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006938 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006939 }
Mike Stump11289f42009-09-09 15:08:12 +00006940
David Majnemer5f7efef2013-10-15 09:50:08 +00006941 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006942 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006943 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006944
John McCallb268a282010-08-23 23:25:46 +00006945 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006946 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006947}
Mike Stump11289f42009-09-09 15:08:12 +00006948
Richard Smith02e85f32011-04-14 22:09:26 +00006949template<typename Derived>
6950StmtResult
6951TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6952 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6953 if (Range.isInvalid())
6954 return StmtError();
6955
Richard Smith01694c32016-03-20 10:33:40 +00006956 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6957 if (Begin.isInvalid())
6958 return StmtError();
6959 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6960 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006961 return StmtError();
6962
6963 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6964 if (Cond.isInvalid())
6965 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006966 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006967 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006968 if (Cond.isInvalid())
6969 return StmtError();
6970 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006971 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006972
6973 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6974 if (Inc.isInvalid())
6975 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006976 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006977 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006978
6979 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6980 if (LoopVar.isInvalid())
6981 return StmtError();
6982
6983 StmtResult NewStmt = S;
6984 if (getDerived().AlwaysRebuild() ||
6985 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006986 Begin.get() != S->getBeginStmt() ||
6987 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006988 Cond.get() != S->getCond() ||
6989 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006990 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006991 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006992 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006993 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006994 Begin.get(), End.get(),
6995 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006996 Inc.get(), LoopVar.get(),
6997 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006998 if (NewStmt.isInvalid())
6999 return StmtError();
7000 }
Richard Smith02e85f32011-04-14 22:09:26 +00007001
7002 StmtResult Body = getDerived().TransformStmt(S->getBody());
7003 if (Body.isInvalid())
7004 return StmtError();
7005
7006 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7007 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007008 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007009 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007010 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007011 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007012 Begin.get(), End.get(),
7013 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007014 Inc.get(), LoopVar.get(),
7015 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007016 if (NewStmt.isInvalid())
7017 return StmtError();
7018 }
Richard Smith02e85f32011-04-14 22:09:26 +00007019
7020 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007021 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007022
7023 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7024}
7025
John Wiegley1c0675e2011-04-28 01:08:34 +00007026template<typename Derived>
7027StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007028TreeTransform<Derived>::TransformMSDependentExistsStmt(
7029 MSDependentExistsStmt *S) {
7030 // Transform the nested-name-specifier, if any.
7031 NestedNameSpecifierLoc QualifierLoc;
7032 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007033 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007034 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7035 if (!QualifierLoc)
7036 return StmtError();
7037 }
7038
7039 // Transform the declaration name.
7040 DeclarationNameInfo NameInfo = S->getNameInfo();
7041 if (NameInfo.getName()) {
7042 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7043 if (!NameInfo.getName())
7044 return StmtError();
7045 }
7046
7047 // Check whether anything changed.
7048 if (!getDerived().AlwaysRebuild() &&
7049 QualifierLoc == S->getQualifierLoc() &&
7050 NameInfo.getName() == S->getNameInfo().getName())
7051 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007052
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007053 // Determine whether this name exists, if we can.
7054 CXXScopeSpec SS;
7055 SS.Adopt(QualifierLoc);
7056 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007057 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007058 case Sema::IER_Exists:
7059 if (S->isIfExists())
7060 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007061
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007062 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7063
7064 case Sema::IER_DoesNotExist:
7065 if (S->isIfNotExists())
7066 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007067
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007068 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007069
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007070 case Sema::IER_Dependent:
7071 Dependent = true;
7072 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007073
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007074 case Sema::IER_Error:
7075 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007077
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007078 // We need to continue with the instantiation, so do so now.
7079 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7080 if (SubStmt.isInvalid())
7081 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007082
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007083 // If we have resolved the name, just transform to the substatement.
7084 if (!Dependent)
7085 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007086
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007087 // The name is still dependent, so build a dependent expression again.
7088 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7089 S->isIfExists(),
7090 QualifierLoc,
7091 NameInfo,
7092 SubStmt.get());
7093}
7094
7095template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007096ExprResult
7097TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7098 NestedNameSpecifierLoc QualifierLoc;
7099 if (E->getQualifierLoc()) {
7100 QualifierLoc
7101 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7102 if (!QualifierLoc)
7103 return ExprError();
7104 }
7105
7106 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7107 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7108 if (!PD)
7109 return ExprError();
7110
7111 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7112 if (Base.isInvalid())
7113 return ExprError();
7114
7115 return new (SemaRef.getASTContext())
7116 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7117 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7118 QualifierLoc, E->getMemberLoc());
7119}
7120
David Majnemerfad8f482013-10-15 09:33:02 +00007121template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007122ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7123 MSPropertySubscriptExpr *E) {
7124 auto BaseRes = getDerived().TransformExpr(E->getBase());
7125 if (BaseRes.isInvalid())
7126 return ExprError();
7127 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7128 if (IdxRes.isInvalid())
7129 return ExprError();
7130
7131 if (!getDerived().AlwaysRebuild() &&
7132 BaseRes.get() == E->getBase() &&
7133 IdxRes.get() == E->getIdx())
7134 return E;
7135
7136 return getDerived().RebuildArraySubscriptExpr(
7137 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7138}
7139
7140template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007141StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007142 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007143 if (TryBlock.isInvalid())
7144 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007145
7146 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007147 if (Handler.isInvalid())
7148 return StmtError();
7149
David Majnemerfad8f482013-10-15 09:33:02 +00007150 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7151 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007152 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007153
Warren Huntf6be4cb2014-07-25 20:52:51 +00007154 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7155 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007156}
7157
David Majnemerfad8f482013-10-15 09:33:02 +00007158template <typename Derived>
7159StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007160 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007161 if (Block.isInvalid())
7162 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007163
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007164 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007165}
7166
David Majnemerfad8f482013-10-15 09:33:02 +00007167template <typename Derived>
7168StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007169 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007170 if (FilterExpr.isInvalid())
7171 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007172
David Majnemer7e755502013-10-15 09:30:14 +00007173 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007174 if (Block.isInvalid())
7175 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007176
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007177 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7178 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007179}
7180
David Majnemerfad8f482013-10-15 09:33:02 +00007181template <typename Derived>
7182StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7183 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007184 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7185 else
7186 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7187}
7188
Nico Weber9b982072014-07-07 00:12:30 +00007189template<typename Derived>
7190StmtResult
7191TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7192 return S;
7193}
7194
Alexander Musman64d33f12014-06-04 07:53:32 +00007195//===----------------------------------------------------------------------===//
7196// OpenMP directive transformation
7197//===----------------------------------------------------------------------===//
7198template <typename Derived>
7199StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7200 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007201
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007202 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007203 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007204 ArrayRef<OMPClause *> Clauses = D->clauses();
7205 TClauses.reserve(Clauses.size());
7206 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7207 I != E; ++I) {
7208 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007209 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007210 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007211 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007212 if (Clause)
7213 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007214 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007215 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007216 }
7217 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007218 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007219 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007220 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7221 /*CurScope=*/nullptr);
7222 StmtResult Body;
7223 {
7224 Sema::CompoundScopeRAII CompoundScope(getSema());
7225 Body = getDerived().TransformStmt(
7226 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7227 }
7228 AssociatedStmt =
7229 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007230 if (AssociatedStmt.isInvalid()) {
7231 return StmtError();
7232 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007233 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007234 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007235 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007236 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007237
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007238 // Transform directive name for 'omp critical' directive.
7239 DeclarationNameInfo DirName;
7240 if (D->getDirectiveKind() == OMPD_critical) {
7241 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7242 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7243 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007244 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7245 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7246 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007247 } else if (D->getDirectiveKind() == OMPD_cancel) {
7248 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007249 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007250
Alexander Musman64d33f12014-06-04 07:53:32 +00007251 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007252 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7253 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007254}
7255
Alexander Musman64d33f12014-06-04 07:53:32 +00007256template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007257StmtResult
7258TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7259 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007260 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7261 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007262 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7263 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7264 return Res;
7265}
7266
Alexander Musman64d33f12014-06-04 07:53:32 +00007267template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007268StmtResult
7269TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7270 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007271 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7272 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007273 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7274 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007275 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007276}
7277
Alexey Bataevf29276e2014-06-18 04:14:57 +00007278template <typename Derived>
7279StmtResult
7280TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7281 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007282 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7283 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007284 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7285 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7286 return Res;
7287}
7288
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007289template <typename Derived>
7290StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007291TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7292 DeclarationNameInfo DirName;
7293 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7294 D->getLocStart());
7295 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7296 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7297 return Res;
7298}
7299
7300template <typename Derived>
7301StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007302TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7303 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007304 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7305 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007306 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7307 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7308 return Res;
7309}
7310
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007311template <typename Derived>
7312StmtResult
7313TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7314 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007315 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7316 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007317 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7318 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7319 return Res;
7320}
7321
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007322template <typename Derived>
7323StmtResult
7324TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7325 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007326 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7327 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007328 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7329 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7330 return Res;
7331}
7332
Alexey Bataev4acb8592014-07-07 13:01:15 +00007333template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007334StmtResult
7335TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7336 DeclarationNameInfo DirName;
7337 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7338 D->getLocStart());
7339 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7340 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7341 return Res;
7342}
7343
7344template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007345StmtResult
7346TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7347 getDerived().getSema().StartOpenMPDSABlock(
7348 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7349 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7350 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7351 return Res;
7352}
7353
7354template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007355StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7356 OMPParallelForDirective *D) {
7357 DeclarationNameInfo DirName;
7358 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7359 nullptr, D->getLocStart());
7360 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7361 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7362 return Res;
7363}
7364
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007365template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007366StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7367 OMPParallelForSimdDirective *D) {
7368 DeclarationNameInfo DirName;
7369 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7370 nullptr, D->getLocStart());
7371 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7372 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7373 return Res;
7374}
7375
7376template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007377StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7378 OMPParallelSectionsDirective *D) {
7379 DeclarationNameInfo DirName;
7380 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7381 nullptr, D->getLocStart());
7382 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7383 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7384 return Res;
7385}
7386
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007387template <typename Derived>
7388StmtResult
7389TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7390 DeclarationNameInfo DirName;
7391 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7392 D->getLocStart());
7393 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7394 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7395 return Res;
7396}
7397
Alexey Bataev68446b72014-07-18 07:47:19 +00007398template <typename Derived>
7399StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7400 OMPTaskyieldDirective *D) {
7401 DeclarationNameInfo DirName;
7402 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7403 D->getLocStart());
7404 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7405 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7406 return Res;
7407}
7408
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007409template <typename Derived>
7410StmtResult
7411TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7412 DeclarationNameInfo DirName;
7413 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7414 D->getLocStart());
7415 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7416 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7417 return Res;
7418}
7419
Alexey Bataev2df347a2014-07-18 10:17:07 +00007420template <typename Derived>
7421StmtResult
7422TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7423 DeclarationNameInfo DirName;
7424 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7425 D->getLocStart());
7426 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7427 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7428 return Res;
7429}
7430
Alexey Bataev6125da92014-07-21 11:26:11 +00007431template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007432StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7433 OMPTaskgroupDirective *D) {
7434 DeclarationNameInfo DirName;
7435 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7436 D->getLocStart());
7437 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7438 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7439 return Res;
7440}
7441
7442template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007443StmtResult
7444TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7445 DeclarationNameInfo DirName;
7446 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7447 D->getLocStart());
7448 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7449 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7450 return Res;
7451}
7452
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007453template <typename Derived>
7454StmtResult
7455TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7456 DeclarationNameInfo DirName;
7457 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7458 D->getLocStart());
7459 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7460 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7461 return Res;
7462}
7463
Alexey Bataev0162e452014-07-22 10:10:35 +00007464template <typename Derived>
7465StmtResult
7466TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7467 DeclarationNameInfo DirName;
7468 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7469 D->getLocStart());
7470 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7471 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7472 return Res;
7473}
7474
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007475template <typename Derived>
7476StmtResult
7477TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7478 DeclarationNameInfo DirName;
7479 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7480 D->getLocStart());
7481 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7482 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7483 return Res;
7484}
7485
Alexey Bataev13314bf2014-10-09 04:18:56 +00007486template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007487StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7488 OMPTargetDataDirective *D) {
7489 DeclarationNameInfo DirName;
7490 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7491 D->getLocStart());
7492 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7493 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7494 return Res;
7495}
7496
7497template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007498StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7499 OMPTargetEnterDataDirective *D) {
7500 DeclarationNameInfo DirName;
7501 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7502 nullptr, D->getLocStart());
7503 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7504 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7505 return Res;
7506}
7507
7508template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007509StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7510 OMPTargetExitDataDirective *D) {
7511 DeclarationNameInfo DirName;
7512 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7513 nullptr, D->getLocStart());
7514 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7515 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7516 return Res;
7517}
7518
7519template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007520StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7521 OMPTargetParallelDirective *D) {
7522 DeclarationNameInfo DirName;
7523 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7524 nullptr, D->getLocStart());
7525 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7526 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7527 return Res;
7528}
7529
7530template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007531StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7532 OMPTargetParallelForDirective *D) {
7533 DeclarationNameInfo DirName;
7534 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7535 nullptr, D->getLocStart());
7536 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7537 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7538 return Res;
7539}
7540
7541template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007542StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7543 OMPTargetUpdateDirective *D) {
7544 DeclarationNameInfo DirName;
7545 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7546 nullptr, D->getLocStart());
7547 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7548 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7549 return Res;
7550}
7551
7552template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007553StmtResult
7554TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7555 DeclarationNameInfo DirName;
7556 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7557 D->getLocStart());
7558 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7559 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7560 return Res;
7561}
7562
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007563template <typename Derived>
7564StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7565 OMPCancellationPointDirective *D) {
7566 DeclarationNameInfo DirName;
7567 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7568 nullptr, D->getLocStart());
7569 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7570 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7571 return Res;
7572}
7573
Alexey Bataev80909872015-07-02 11:25:17 +00007574template <typename Derived>
7575StmtResult
7576TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7577 DeclarationNameInfo DirName;
7578 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7579 D->getLocStart());
7580 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7581 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7582 return Res;
7583}
7584
Alexey Bataev49f6e782015-12-01 04:18:41 +00007585template <typename Derived>
7586StmtResult
7587TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7588 DeclarationNameInfo DirName;
7589 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7590 D->getLocStart());
7591 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7592 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7593 return Res;
7594}
7595
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007596template <typename Derived>
7597StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7598 OMPTaskLoopSimdDirective *D) {
7599 DeclarationNameInfo DirName;
7600 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7601 nullptr, D->getLocStart());
7602 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7603 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7604 return Res;
7605}
7606
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007607template <typename Derived>
7608StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7609 OMPDistributeDirective *D) {
7610 DeclarationNameInfo DirName;
7611 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7612 D->getLocStart());
7613 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7614 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7615 return Res;
7616}
7617
Carlo Bertolli9925f152016-06-27 14:55:37 +00007618template <typename Derived>
7619StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7620 OMPDistributeParallelForDirective *D) {
7621 DeclarationNameInfo DirName;
7622 getDerived().getSema().StartOpenMPDSABlock(
7623 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7624 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7625 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7626 return Res;
7627}
7628
Kelvin Li4a39add2016-07-05 05:00:15 +00007629template <typename Derived>
7630StmtResult
7631TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7632 OMPDistributeParallelForSimdDirective *D) {
7633 DeclarationNameInfo DirName;
7634 getDerived().getSema().StartOpenMPDSABlock(
7635 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7636 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7637 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7638 return Res;
7639}
7640
Kelvin Li787f3fc2016-07-06 04:45:38 +00007641template <typename Derived>
7642StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7643 OMPDistributeSimdDirective *D) {
7644 DeclarationNameInfo DirName;
7645 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7646 nullptr, D->getLocStart());
7647 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7648 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7649 return Res;
7650}
7651
Kelvin Lia579b912016-07-14 02:54:56 +00007652template <typename Derived>
7653StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7654 OMPTargetParallelForSimdDirective *D) {
7655 DeclarationNameInfo DirName;
7656 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7657 DirName, nullptr,
7658 D->getLocStart());
7659 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7660 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7661 return Res;
7662}
7663
Kelvin Li986330c2016-07-20 22:57:10 +00007664template <typename Derived>
7665StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7666 OMPTargetSimdDirective *D) {
7667 DeclarationNameInfo DirName;
7668 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7669 D->getLocStart());
7670 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7671 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7672 return Res;
7673}
7674
Kelvin Li02532872016-08-05 14:37:37 +00007675template <typename Derived>
7676StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7677 OMPTeamsDistributeDirective *D) {
7678 DeclarationNameInfo DirName;
7679 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7680 nullptr, D->getLocStart());
7681 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7682 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7683 return Res;
7684}
7685
Alexander Musman64d33f12014-06-04 07:53:32 +00007686//===----------------------------------------------------------------------===//
7687// OpenMP clause transformation
7688//===----------------------------------------------------------------------===//
7689template <typename Derived>
7690OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007691 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7692 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007693 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007694 return getDerived().RebuildOMPIfClause(
7695 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7696 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007697}
7698
Alexander Musman64d33f12014-06-04 07:53:32 +00007699template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007700OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7701 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7702 if (Cond.isInvalid())
7703 return nullptr;
7704 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7705 C->getLParenLoc(), C->getLocEnd());
7706}
7707
7708template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007709OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007710TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7711 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7712 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007713 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007714 return getDerived().RebuildOMPNumThreadsClause(
7715 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007716}
7717
Alexey Bataev62c87d22014-03-21 04:51:18 +00007718template <typename Derived>
7719OMPClause *
7720TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7721 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7722 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007723 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007724 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007725 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007726}
7727
Alexander Musman8bd31e62014-05-27 15:12:19 +00007728template <typename Derived>
7729OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007730TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7731 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7732 if (E.isInvalid())
7733 return nullptr;
7734 return getDerived().RebuildOMPSimdlenClause(
7735 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7736}
7737
7738template <typename Derived>
7739OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007740TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7741 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7742 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007743 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007744 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007745 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007746}
7747
Alexander Musman64d33f12014-06-04 07:53:32 +00007748template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007749OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007750TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007751 return getDerived().RebuildOMPDefaultClause(
7752 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7753 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007754}
7755
Alexander Musman64d33f12014-06-04 07:53:32 +00007756template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007757OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007758TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007759 return getDerived().RebuildOMPProcBindClause(
7760 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7761 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007762}
7763
Alexander Musman64d33f12014-06-04 07:53:32 +00007764template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007765OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007766TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7767 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7768 if (E.isInvalid())
7769 return nullptr;
7770 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007771 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007772 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007773 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007774 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7775}
7776
7777template <typename Derived>
7778OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007779TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007780 ExprResult E;
7781 if (auto *Num = C->getNumForLoops()) {
7782 E = getDerived().TransformExpr(Num);
7783 if (E.isInvalid())
7784 return nullptr;
7785 }
7786 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7787 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007788}
7789
7790template <typename Derived>
7791OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007792TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7793 // No need to rebuild this clause, no template-dependent parameters.
7794 return C;
7795}
7796
7797template <typename Derived>
7798OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007799TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7800 // No need to rebuild this clause, no template-dependent parameters.
7801 return C;
7802}
7803
7804template <typename Derived>
7805OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007806TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7807 // No need to rebuild this clause, no template-dependent parameters.
7808 return C;
7809}
7810
7811template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007812OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7813 // No need to rebuild this clause, no template-dependent parameters.
7814 return C;
7815}
7816
7817template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007818OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7819 // No need to rebuild this clause, no template-dependent parameters.
7820 return C;
7821}
7822
7823template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007824OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007825TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7826 // No need to rebuild this clause, no template-dependent parameters.
7827 return C;
7828}
7829
7830template <typename Derived>
7831OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007832TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7833 // No need to rebuild this clause, no template-dependent parameters.
7834 return C;
7835}
7836
7837template <typename Derived>
7838OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007839TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7840 // No need to rebuild this clause, no template-dependent parameters.
7841 return C;
7842}
7843
7844template <typename Derived>
7845OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007846TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7847 // No need to rebuild this clause, no template-dependent parameters.
7848 return C;
7849}
7850
7851template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007852OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7853 // No need to rebuild this clause, no template-dependent parameters.
7854 return C;
7855}
7856
7857template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007858OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007859TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7860 // No need to rebuild this clause, no template-dependent parameters.
7861 return C;
7862}
7863
7864template <typename Derived>
7865OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007866TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007867 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007868 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007869 for (auto *VE : C->varlists()) {
7870 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007871 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007872 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007873 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007874 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007875 return getDerived().RebuildOMPPrivateClause(
7876 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007877}
7878
Alexander Musman64d33f12014-06-04 07:53:32 +00007879template <typename Derived>
7880OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7881 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007882 llvm::SmallVector<Expr *, 16> Vars;
7883 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007884 for (auto *VE : C->varlists()) {
7885 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007886 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007887 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007888 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007889 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007890 return getDerived().RebuildOMPFirstprivateClause(
7891 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007892}
7893
Alexander Musman64d33f12014-06-04 07:53:32 +00007894template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007895OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007896TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7897 llvm::SmallVector<Expr *, 16> Vars;
7898 Vars.reserve(C->varlist_size());
7899 for (auto *VE : C->varlists()) {
7900 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7901 if (EVar.isInvalid())
7902 return nullptr;
7903 Vars.push_back(EVar.get());
7904 }
7905 return getDerived().RebuildOMPLastprivateClause(
7906 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7907}
7908
7909template <typename Derived>
7910OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007911TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7912 llvm::SmallVector<Expr *, 16> Vars;
7913 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007914 for (auto *VE : C->varlists()) {
7915 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007916 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007917 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007918 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007919 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007920 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7921 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007922}
7923
Alexander Musman64d33f12014-06-04 07:53:32 +00007924template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007925OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007926TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7927 llvm::SmallVector<Expr *, 16> Vars;
7928 Vars.reserve(C->varlist_size());
7929 for (auto *VE : C->varlists()) {
7930 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7931 if (EVar.isInvalid())
7932 return nullptr;
7933 Vars.push_back(EVar.get());
7934 }
7935 CXXScopeSpec ReductionIdScopeSpec;
7936 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7937
7938 DeclarationNameInfo NameInfo = C->getNameInfo();
7939 if (NameInfo.getName()) {
7940 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7941 if (!NameInfo.getName())
7942 return nullptr;
7943 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007944 // Build a list of all UDR decls with the same names ranged by the Scopes.
7945 // The Scope boundary is a duplication of the previous decl.
7946 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7947 for (auto *E : C->reduction_ops()) {
7948 // Transform all the decls.
7949 if (E) {
7950 auto *ULE = cast<UnresolvedLookupExpr>(E);
7951 UnresolvedSet<8> Decls;
7952 for (auto *D : ULE->decls()) {
7953 NamedDecl *InstD =
7954 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7955 Decls.addDecl(InstD, InstD->getAccess());
7956 }
7957 UnresolvedReductions.push_back(
7958 UnresolvedLookupExpr::Create(
7959 SemaRef.Context, /*NamingClass=*/nullptr,
7960 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7961 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7962 Decls.begin(), Decls.end()));
7963 } else
7964 UnresolvedReductions.push_back(nullptr);
7965 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007966 return getDerived().RebuildOMPReductionClause(
7967 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007968 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007969}
7970
7971template <typename Derived>
7972OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007973TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7974 llvm::SmallVector<Expr *, 16> Vars;
7975 Vars.reserve(C->varlist_size());
7976 for (auto *VE : C->varlists()) {
7977 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7978 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007979 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007980 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007981 }
7982 ExprResult Step = getDerived().TransformExpr(C->getStep());
7983 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007984 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007985 return getDerived().RebuildOMPLinearClause(
7986 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7987 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007988}
7989
Alexander Musman64d33f12014-06-04 07:53:32 +00007990template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007991OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007992TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7993 llvm::SmallVector<Expr *, 16> Vars;
7994 Vars.reserve(C->varlist_size());
7995 for (auto *VE : C->varlists()) {
7996 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7997 if (EVar.isInvalid())
7998 return nullptr;
7999 Vars.push_back(EVar.get());
8000 }
8001 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8002 if (Alignment.isInvalid())
8003 return nullptr;
8004 return getDerived().RebuildOMPAlignedClause(
8005 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8006 C->getColonLoc(), C->getLocEnd());
8007}
8008
Alexander Musman64d33f12014-06-04 07:53:32 +00008009template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008010OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008011TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8012 llvm::SmallVector<Expr *, 16> Vars;
8013 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008014 for (auto *VE : C->varlists()) {
8015 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008016 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008017 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008018 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008019 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008020 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8021 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008022}
8023
Alexey Bataevbae9a792014-06-27 10:37:06 +00008024template <typename Derived>
8025OMPClause *
8026TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8027 llvm::SmallVector<Expr *, 16> Vars;
8028 Vars.reserve(C->varlist_size());
8029 for (auto *VE : C->varlists()) {
8030 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8031 if (EVar.isInvalid())
8032 return nullptr;
8033 Vars.push_back(EVar.get());
8034 }
8035 return getDerived().RebuildOMPCopyprivateClause(
8036 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8037}
8038
Alexey Bataev6125da92014-07-21 11:26:11 +00008039template <typename Derived>
8040OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8041 llvm::SmallVector<Expr *, 16> Vars;
8042 Vars.reserve(C->varlist_size());
8043 for (auto *VE : C->varlists()) {
8044 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8045 if (EVar.isInvalid())
8046 return nullptr;
8047 Vars.push_back(EVar.get());
8048 }
8049 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8050 C->getLParenLoc(), C->getLocEnd());
8051}
8052
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008053template <typename Derived>
8054OMPClause *
8055TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8056 llvm::SmallVector<Expr *, 16> Vars;
8057 Vars.reserve(C->varlist_size());
8058 for (auto *VE : C->varlists()) {
8059 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8060 if (EVar.isInvalid())
8061 return nullptr;
8062 Vars.push_back(EVar.get());
8063 }
8064 return getDerived().RebuildOMPDependClause(
8065 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8066 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8067}
8068
Michael Wonge710d542015-08-07 16:16:36 +00008069template <typename Derived>
8070OMPClause *
8071TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8072 ExprResult E = getDerived().TransformExpr(C->getDevice());
8073 if (E.isInvalid())
8074 return nullptr;
8075 return getDerived().RebuildOMPDeviceClause(
8076 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8077}
8078
Kelvin Li0bff7af2015-11-23 05:32:03 +00008079template <typename Derived>
8080OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8081 llvm::SmallVector<Expr *, 16> Vars;
8082 Vars.reserve(C->varlist_size());
8083 for (auto *VE : C->varlists()) {
8084 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8085 if (EVar.isInvalid())
8086 return nullptr;
8087 Vars.push_back(EVar.get());
8088 }
8089 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008090 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8091 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8092 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008093}
8094
Kelvin Li099bb8c2015-11-24 20:50:12 +00008095template <typename Derived>
8096OMPClause *
8097TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8098 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8099 if (E.isInvalid())
8100 return nullptr;
8101 return getDerived().RebuildOMPNumTeamsClause(
8102 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8103}
8104
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008105template <typename Derived>
8106OMPClause *
8107TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8108 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8109 if (E.isInvalid())
8110 return nullptr;
8111 return getDerived().RebuildOMPThreadLimitClause(
8112 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8113}
8114
Alexey Bataeva0569352015-12-01 10:17:31 +00008115template <typename Derived>
8116OMPClause *
8117TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8118 ExprResult E = getDerived().TransformExpr(C->getPriority());
8119 if (E.isInvalid())
8120 return nullptr;
8121 return getDerived().RebuildOMPPriorityClause(
8122 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8123}
8124
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008125template <typename Derived>
8126OMPClause *
8127TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8128 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8129 if (E.isInvalid())
8130 return nullptr;
8131 return getDerived().RebuildOMPGrainsizeClause(
8132 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8133}
8134
Alexey Bataev382967a2015-12-08 12:06:20 +00008135template <typename Derived>
8136OMPClause *
8137TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8138 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8139 if (E.isInvalid())
8140 return nullptr;
8141 return getDerived().RebuildOMPNumTasksClause(
8142 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8143}
8144
Alexey Bataev28c75412015-12-15 08:19:24 +00008145template <typename Derived>
8146OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8147 ExprResult E = getDerived().TransformExpr(C->getHint());
8148 if (E.isInvalid())
8149 return nullptr;
8150 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8151 C->getLParenLoc(), C->getLocEnd());
8152}
8153
Carlo Bertollib4adf552016-01-15 18:50:31 +00008154template <typename Derived>
8155OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8156 OMPDistScheduleClause *C) {
8157 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8158 if (E.isInvalid())
8159 return nullptr;
8160 return getDerived().RebuildOMPDistScheduleClause(
8161 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8162 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8163}
8164
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008165template <typename Derived>
8166OMPClause *
8167TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8168 return C;
8169}
8170
Samuel Antao661c0902016-05-26 17:39:58 +00008171template <typename Derived>
8172OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8173 llvm::SmallVector<Expr *, 16> Vars;
8174 Vars.reserve(C->varlist_size());
8175 for (auto *VE : C->varlists()) {
8176 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8177 if (EVar.isInvalid())
8178 return 0;
8179 Vars.push_back(EVar.get());
8180 }
8181 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8182 C->getLParenLoc(), C->getLocEnd());
8183}
8184
Samuel Antaoec172c62016-05-26 17:49:04 +00008185template <typename Derived>
8186OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8187 llvm::SmallVector<Expr *, 16> Vars;
8188 Vars.reserve(C->varlist_size());
8189 for (auto *VE : C->varlists()) {
8190 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8191 if (EVar.isInvalid())
8192 return 0;
8193 Vars.push_back(EVar.get());
8194 }
8195 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8196 C->getLParenLoc(), C->getLocEnd());
8197}
8198
Carlo Bertolli2404b172016-07-13 15:37:16 +00008199template <typename Derived>
8200OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8201 OMPUseDevicePtrClause *C) {
8202 llvm::SmallVector<Expr *, 16> Vars;
8203 Vars.reserve(C->varlist_size());
8204 for (auto *VE : C->varlists()) {
8205 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8206 if (EVar.isInvalid())
8207 return nullptr;
8208 Vars.push_back(EVar.get());
8209 }
8210 return getDerived().RebuildOMPUseDevicePtrClause(
8211 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8212}
8213
Carlo Bertolli70594e92016-07-13 17:16:49 +00008214template <typename Derived>
8215OMPClause *
8216TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8217 llvm::SmallVector<Expr *, 16> Vars;
8218 Vars.reserve(C->varlist_size());
8219 for (auto *VE : C->varlists()) {
8220 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8221 if (EVar.isInvalid())
8222 return nullptr;
8223 Vars.push_back(EVar.get());
8224 }
8225 return getDerived().RebuildOMPIsDevicePtrClause(
8226 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8227}
8228
Douglas Gregorebe10102009-08-20 07:17:43 +00008229//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008230// Expression transformation
8231//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008234TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008235 if (!E->isTypeDependent())
8236 return E;
8237
8238 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8239 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008240}
Mike Stump11289f42009-09-09 15:08:12 +00008241
8242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008244TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008245 NestedNameSpecifierLoc QualifierLoc;
8246 if (E->getQualifierLoc()) {
8247 QualifierLoc
8248 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8249 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008250 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008251 }
John McCallce546572009-12-08 09:08:17 +00008252
8253 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008254 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8255 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008256 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008258
John McCall815039a2010-08-17 21:27:17 +00008259 DeclarationNameInfo NameInfo = E->getNameInfo();
8260 if (NameInfo.getName()) {
8261 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8262 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008263 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008264 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008265
8266 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008267 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008268 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008269 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008270 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008271
8272 // Mark it referenced in the new context regardless.
8273 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008274 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008275
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008276 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008277 }
John McCallce546572009-12-08 09:08:17 +00008278
Craig Topperc3ec1492014-05-26 06:22:03 +00008279 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008280 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008281 TemplateArgs = &TransArgs;
8282 TransArgs.setLAngleLoc(E->getLAngleLoc());
8283 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008284 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8285 E->getNumTemplateArgs(),
8286 TransArgs))
8287 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008288 }
8289
Chad Rosier1dcde962012-08-08 18:46:20 +00008290 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008291 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008292}
Mike Stump11289f42009-09-09 15:08:12 +00008293
Douglas Gregora16548e2009-08-11 05:31:07 +00008294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008295ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008296TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008297 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008298}
Mike Stump11289f42009-09-09 15:08:12 +00008299
Douglas Gregora16548e2009-08-11 05:31:07 +00008300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008301ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008302TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008303 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008304}
Mike Stump11289f42009-09-09 15:08:12 +00008305
Douglas Gregora16548e2009-08-11 05:31:07 +00008306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008307ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008308TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008309 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008310}
Mike Stump11289f42009-09-09 15:08:12 +00008311
Douglas Gregora16548e2009-08-11 05:31:07 +00008312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008314TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008315 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008316}
Mike Stump11289f42009-09-09 15:08:12 +00008317
Douglas Gregora16548e2009-08-11 05:31:07 +00008318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008320TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008321 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008322}
8323
8324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008325ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008326TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008327 if (FunctionDecl *FD = E->getDirectCallee())
8328 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008329 return SemaRef.MaybeBindToTemporary(E);
8330}
8331
8332template<typename Derived>
8333ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008334TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8335 ExprResult ControllingExpr =
8336 getDerived().TransformExpr(E->getControllingExpr());
8337 if (ControllingExpr.isInvalid())
8338 return ExprError();
8339
Chris Lattner01cf8db2011-07-20 06:58:45 +00008340 SmallVector<Expr *, 4> AssocExprs;
8341 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008342 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8343 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8344 if (TS) {
8345 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8346 if (!AssocType)
8347 return ExprError();
8348 AssocTypes.push_back(AssocType);
8349 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008350 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008351 }
8352
8353 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8354 if (AssocExpr.isInvalid())
8355 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008356 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008357 }
8358
8359 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8360 E->getDefaultLoc(),
8361 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008362 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008363 AssocTypes,
8364 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008365}
8366
8367template<typename Derived>
8368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008369TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008370 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008371 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008373
Douglas Gregora16548e2009-08-11 05:31:07 +00008374 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008375 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008376
John McCallb268a282010-08-23 23:25:46 +00008377 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008378 E->getRParen());
8379}
8380
Richard Smithdb2630f2012-10-21 03:28:35 +00008381/// \brief The operand of a unary address-of operator has special rules: it's
8382/// allowed to refer to a non-static member of a class even if there's no 'this'
8383/// object available.
8384template<typename Derived>
8385ExprResult
8386TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8387 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008388 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008389 else
8390 return getDerived().TransformExpr(E);
8391}
8392
Mike Stump11289f42009-09-09 15:08:12 +00008393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008395TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008396 ExprResult SubExpr;
8397 if (E->getOpcode() == UO_AddrOf)
8398 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8399 else
8400 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008401 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008403
Douglas Gregora16548e2009-08-11 05:31:07 +00008404 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008405 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008406
Douglas Gregora16548e2009-08-11 05:31:07 +00008407 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8408 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008409 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008410}
Mike Stump11289f42009-09-09 15:08:12 +00008411
Douglas Gregora16548e2009-08-11 05:31:07 +00008412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008413ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008414TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8415 // Transform the type.
8416 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8417 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008418 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008419
Douglas Gregor882211c2010-04-28 22:16:22 +00008420 // Transform all of the components into components similar to what the
8421 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008422 // FIXME: It would be slightly more efficient in the non-dependent case to
8423 // just map FieldDecls, rather than requiring the rebuilder to look for
8424 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008425 // template code that we don't care.
8426 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008427 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008428 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008429 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008430 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008431 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008432 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008433 Comp.LocStart = ON.getSourceRange().getBegin();
8434 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008435 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008436 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008437 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008438 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008439 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008440 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008441
Douglas Gregor882211c2010-04-28 22:16:22 +00008442 ExprChanged = ExprChanged || Index.get() != FromIndex;
8443 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008444 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008445 break;
8446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008447
James Y Knight7281c352015-12-29 22:31:18 +00008448 case OffsetOfNode::Field:
8449 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008450 Comp.isBrackets = false;
8451 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008452 if (!Comp.U.IdentInfo)
8453 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008454
Douglas Gregor882211c2010-04-28 22:16:22 +00008455 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008456
James Y Knight7281c352015-12-29 22:31:18 +00008457 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008458 // Will be recomputed during the rebuild.
8459 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008461
Douglas Gregor882211c2010-04-28 22:16:22 +00008462 Components.push_back(Comp);
8463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008464
Douglas Gregor882211c2010-04-28 22:16:22 +00008465 // If nothing changed, retain the existing expression.
8466 if (!getDerived().AlwaysRebuild() &&
8467 Type == E->getTypeSourceInfo() &&
8468 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008469 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008470
Douglas Gregor882211c2010-04-28 22:16:22 +00008471 // Build a new offsetof expression.
8472 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008473 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008474}
8475
8476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008477ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008478TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008479 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008480 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008481 return E;
John McCall8d69a212010-11-15 23:31:06 +00008482}
8483
8484template<typename Derived>
8485ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008486TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8487 return E;
8488}
8489
8490template<typename Derived>
8491ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008492TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008493 // Rebuild the syntactic form. The original syntactic form has
8494 // opaque-value expressions in it, so strip those away and rebuild
8495 // the result. This is a really awful way of doing this, but the
8496 // better solution (rebuilding the semantic expressions and
8497 // rebinding OVEs as necessary) doesn't work; we'd need
8498 // TreeTransform to not strip away implicit conversions.
8499 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8500 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008501 if (result.isInvalid()) return ExprError();
8502
8503 // If that gives us a pseudo-object result back, the pseudo-object
8504 // expression must have been an lvalue-to-rvalue conversion which we
8505 // should reapply.
8506 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008507 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008508
8509 return result;
8510}
8511
8512template<typename Derived>
8513ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008514TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8515 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008516 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008517 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008518
John McCallbcd03502009-12-07 02:54:59 +00008519 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008520 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008521 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008522
John McCall4c98fd82009-11-04 07:28:41 +00008523 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008524 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008525
Peter Collingbournee190dee2011-03-11 19:24:49 +00008526 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8527 E->getKind(),
8528 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008529 }
Mike Stump11289f42009-09-09 15:08:12 +00008530
Eli Friedmane4f22df2012-02-29 04:03:55 +00008531 // C++0x [expr.sizeof]p1:
8532 // The operand is either an expression, which is an unevaluated operand
8533 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008534 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8535 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008536
Reid Kleckner32506ed2014-06-12 23:03:48 +00008537 // Try to recover if we have something like sizeof(T::X) where X is a type.
8538 // Notably, there must be *exactly* one set of parens if X is a type.
8539 TypeSourceInfo *RecoveryTSI = nullptr;
8540 ExprResult SubExpr;
8541 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8542 if (auto *DRE =
8543 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8544 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8545 PE, DRE, false, &RecoveryTSI);
8546 else
8547 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8548
8549 if (RecoveryTSI) {
8550 return getDerived().RebuildUnaryExprOrTypeTrait(
8551 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8552 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008554
Eli Friedmane4f22df2012-02-29 04:03:55 +00008555 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008556 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008557
Peter Collingbournee190dee2011-03-11 19:24:49 +00008558 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8559 E->getOperatorLoc(),
8560 E->getKind(),
8561 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008562}
Mike Stump11289f42009-09-09 15:08:12 +00008563
Douglas Gregora16548e2009-08-11 05:31:07 +00008564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008566TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008567 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008568 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008569 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008570
John McCalldadc5752010-08-24 06:29:42 +00008571 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008572 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008574
8575
Douglas Gregora16548e2009-08-11 05:31:07 +00008576 if (!getDerived().AlwaysRebuild() &&
8577 LHS.get() == E->getLHS() &&
8578 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008579 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008580
John McCallb268a282010-08-23 23:25:46 +00008581 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008582 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008583 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008584 E->getRBracketLoc());
8585}
Mike Stump11289f42009-09-09 15:08:12 +00008586
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008587template <typename Derived>
8588ExprResult
8589TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8590 ExprResult Base = getDerived().TransformExpr(E->getBase());
8591 if (Base.isInvalid())
8592 return ExprError();
8593
8594 ExprResult LowerBound;
8595 if (E->getLowerBound()) {
8596 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8597 if (LowerBound.isInvalid())
8598 return ExprError();
8599 }
8600
8601 ExprResult Length;
8602 if (E->getLength()) {
8603 Length = getDerived().TransformExpr(E->getLength());
8604 if (Length.isInvalid())
8605 return ExprError();
8606 }
8607
8608 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8609 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8610 return E;
8611
8612 return getDerived().RebuildOMPArraySectionExpr(
8613 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8614 Length.get(), E->getRBracketLoc());
8615}
8616
Mike Stump11289f42009-09-09 15:08:12 +00008617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008619TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008620 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008621 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008622 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008623 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008624
8625 // Transform arguments.
8626 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008627 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008628 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008629 &ArgChanged))
8630 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008631
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 if (!getDerived().AlwaysRebuild() &&
8633 Callee.get() == E->getCallee() &&
8634 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008635 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008636
Douglas Gregora16548e2009-08-11 05:31:07 +00008637 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008638 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008640 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008641 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008642 E->getRParenLoc());
8643}
Mike Stump11289f42009-09-09 15:08:12 +00008644
8645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008647TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008648 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008649 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008651
Douglas Gregorea972d32011-02-28 21:54:11 +00008652 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008653 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008654 QualifierLoc
8655 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008656
Douglas Gregorea972d32011-02-28 21:54:11 +00008657 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008658 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008659 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008660 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008661
Eli Friedman2cfcef62009-12-04 06:40:45 +00008662 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008663 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8664 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008665 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008667
John McCall16df1e52010-03-30 21:47:33 +00008668 NamedDecl *FoundDecl = E->getFoundDecl();
8669 if (FoundDecl == E->getMemberDecl()) {
8670 FoundDecl = Member;
8671 } else {
8672 FoundDecl = cast_or_null<NamedDecl>(
8673 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8674 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008675 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008676 }
8677
Douglas Gregora16548e2009-08-11 05:31:07 +00008678 if (!getDerived().AlwaysRebuild() &&
8679 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008680 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008681 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008682 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008683 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008684
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008685 // Mark it referenced in the new context regardless.
8686 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008687 SemaRef.MarkMemberReferenced(E);
8688
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008689 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008690 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008691
John McCall6b51f282009-11-23 01:53:49 +00008692 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008693 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008694 TransArgs.setLAngleLoc(E->getLAngleLoc());
8695 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008696 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8697 E->getNumTemplateArgs(),
8698 TransArgs))
8699 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008700 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008701
Douglas Gregora16548e2009-08-11 05:31:07 +00008702 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008703 SourceLocation FakeOperatorLoc =
8704 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008705
John McCall38836f02010-01-15 08:34:02 +00008706 // FIXME: to do this check properly, we will need to preserve the
8707 // first-qualifier-in-scope here, just in case we had a dependent
8708 // base (and therefore couldn't do the check) and a
8709 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008710 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008711
John McCallb268a282010-08-23 23:25:46 +00008712 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008713 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008714 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008715 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008716 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008717 Member,
John McCall16df1e52010-03-30 21:47:33 +00008718 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008719 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008720 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008721 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008722}
Mike Stump11289f42009-09-09 15:08:12 +00008723
Douglas Gregora16548e2009-08-11 05:31:07 +00008724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008726TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008727 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008728 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008729 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008730
John McCalldadc5752010-08-24 06:29:42 +00008731 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008732 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008734
Douglas Gregora16548e2009-08-11 05:31:07 +00008735 if (!getDerived().AlwaysRebuild() &&
8736 LHS.get() == E->getLHS() &&
8737 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008738 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008739
Lang Hames5de91cc2012-10-02 04:45:10 +00008740 Sema::FPContractStateRAII FPContractState(getSema());
8741 getSema().FPFeatures.fp_contract = E->isFPContractable();
8742
Douglas Gregora16548e2009-08-11 05:31:07 +00008743 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008744 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008745}
8746
Mike Stump11289f42009-09-09 15:08:12 +00008747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008748ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008749TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008750 CompoundAssignOperator *E) {
8751 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008752}
Mike Stump11289f42009-09-09 15:08:12 +00008753
Douglas Gregora16548e2009-08-11 05:31:07 +00008754template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008755ExprResult TreeTransform<Derived>::
8756TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8757 // Just rebuild the common and RHS expressions and see whether we
8758 // get any changes.
8759
8760 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8761 if (commonExpr.isInvalid())
8762 return ExprError();
8763
8764 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8765 if (rhs.isInvalid())
8766 return ExprError();
8767
8768 if (!getDerived().AlwaysRebuild() &&
8769 commonExpr.get() == e->getCommon() &&
8770 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008771 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008772
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008773 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008774 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008775 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008776 e->getColonLoc(),
8777 rhs.get());
8778}
8779
8780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008782TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008783 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008784 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008786
John McCalldadc5752010-08-24 06:29:42 +00008787 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008788 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008789 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008790
John McCalldadc5752010-08-24 06:29:42 +00008791 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008792 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008793 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008794
Douglas Gregora16548e2009-08-11 05:31:07 +00008795 if (!getDerived().AlwaysRebuild() &&
8796 Cond.get() == E->getCond() &&
8797 LHS.get() == E->getLHS() &&
8798 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008799 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008800
John McCallb268a282010-08-23 23:25:46 +00008801 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008802 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008803 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008804 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008805 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008806}
Mike Stump11289f42009-09-09 15:08:12 +00008807
8808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008809ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008810TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008811 // Implicit casts are eliminated during transformation, since they
8812 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008813 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008814}
Mike Stump11289f42009-09-09 15:08:12 +00008815
Douglas Gregora16548e2009-08-11 05:31:07 +00008816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008817ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008818TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008819 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8820 if (!Type)
8821 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008822
John McCalldadc5752010-08-24 06:29:42 +00008823 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008824 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008825 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008827
Douglas Gregora16548e2009-08-11 05:31:07 +00008828 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008829 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008830 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008831 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008832
John McCall97513962010-01-15 18:39:57 +00008833 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008834 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008835 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008836 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008837}
Mike Stump11289f42009-09-09 15:08:12 +00008838
Douglas Gregora16548e2009-08-11 05:31:07 +00008839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008841TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008842 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8843 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8844 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008846
John McCalldadc5752010-08-24 06:29:42 +00008847 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008848 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008849 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008850
Douglas Gregora16548e2009-08-11 05:31:07 +00008851 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008852 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008853 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008854 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008855
John McCall5d7aa7f2010-01-19 22:33:45 +00008856 // Note: the expression type doesn't necessarily match the
8857 // type-as-written, but that's okay, because it should always be
8858 // derivable from the initializer.
8859
John McCalle15bbff2010-01-18 19:35:47 +00008860 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008861 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008862 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008863}
Mike Stump11289f42009-09-09 15:08:12 +00008864
Douglas Gregora16548e2009-08-11 05:31:07 +00008865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008867TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008868 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008871
Douglas Gregora16548e2009-08-11 05:31:07 +00008872 if (!getDerived().AlwaysRebuild() &&
8873 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008874 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008875
Douglas Gregora16548e2009-08-11 05:31:07 +00008876 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008877 SourceLocation FakeOperatorLoc =
8878 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008879 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008880 E->getAccessorLoc(),
8881 E->getAccessor());
8882}
Mike Stump11289f42009-09-09 15:08:12 +00008883
Douglas Gregora16548e2009-08-11 05:31:07 +00008884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008886TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008887 if (InitListExpr *Syntactic = E->getSyntacticForm())
8888 E = Syntactic;
8889
Douglas Gregora16548e2009-08-11 05:31:07 +00008890 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008891
Benjamin Kramerf0623432012-08-23 22:51:59 +00008892 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008893 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008894 Inits, &InitChanged))
8895 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008896
Richard Smith520449d2015-02-05 06:15:50 +00008897 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8898 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8899 // in some cases. We can't reuse it in general, because the syntactic and
8900 // semantic forms are linked, and we can't know that semantic form will
8901 // match even if the syntactic form does.
8902 }
Mike Stump11289f42009-09-09 15:08:12 +00008903
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008904 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008905 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008906}
Mike Stump11289f42009-09-09 15:08:12 +00008907
Douglas Gregora16548e2009-08-11 05:31:07 +00008908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008909ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008910TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008911 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008912
Douglas Gregorebe10102009-08-20 07:17:43 +00008913 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008914 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008915 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008917
Douglas Gregorebe10102009-08-20 07:17:43 +00008918 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008919 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008920 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008921 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8922 if (D.isFieldDesignator()) {
8923 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8924 D.getDotLoc(),
8925 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00008926 if (D.getField()) {
8927 FieldDecl *Field = cast_or_null<FieldDecl>(
8928 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
8929 if (Field != D.getField())
8930 // Rebuild the expression when the transformed FieldDecl is
8931 // different to the already assigned FieldDecl.
8932 ExprChanged = true;
8933 } else {
8934 // Ensure that the designator expression is rebuilt when there isn't
8935 // a resolved FieldDecl in the designator as we don't want to assign
8936 // a FieldDecl to a pattern designator that will be instantiated again.
8937 ExprChanged = true;
8938 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008939 continue;
8940 }
Mike Stump11289f42009-09-09 15:08:12 +00008941
David Majnemerf7e36092016-06-23 00:15:04 +00008942 if (D.isArrayDesignator()) {
8943 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008944 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008945 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008946
David Majnemerf7e36092016-06-23 00:15:04 +00008947 Desig.AddDesignator(
8948 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008949
David Majnemerf7e36092016-06-23 00:15:04 +00008950 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008951 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008952 continue;
8953 }
Mike Stump11289f42009-09-09 15:08:12 +00008954
David Majnemerf7e36092016-06-23 00:15:04 +00008955 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008956 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008957 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008958 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008959 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008960
David Majnemerf7e36092016-06-23 00:15:04 +00008961 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008962 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008964
8965 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008966 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008967 D.getLBracketLoc(),
8968 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008969
David Majnemerf7e36092016-06-23 00:15:04 +00008970 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8971 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008972
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008973 ArrayExprs.push_back(Start.get());
8974 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008975 }
Mike Stump11289f42009-09-09 15:08:12 +00008976
Douglas Gregora16548e2009-08-11 05:31:07 +00008977 if (!getDerived().AlwaysRebuild() &&
8978 Init.get() == E->getInit() &&
8979 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008980 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008981
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008982 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008983 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008984 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008985}
Mike Stump11289f42009-09-09 15:08:12 +00008986
Yunzhong Gaocb779302015-06-10 00:27:52 +00008987// Seems that if TransformInitListExpr() only works on the syntactic form of an
8988// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8989template<typename Derived>
8990ExprResult
8991TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8992 DesignatedInitUpdateExpr *E) {
8993 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8994 "initializer");
8995 return ExprError();
8996}
8997
8998template<typename Derived>
8999ExprResult
9000TreeTransform<Derived>::TransformNoInitExpr(
9001 NoInitExpr *E) {
9002 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9003 return ExprError();
9004}
9005
Douglas Gregora16548e2009-08-11 05:31:07 +00009006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009007ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009008TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009009 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009010 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009011
Douglas Gregor3da3c062009-10-28 00:29:27 +00009012 // FIXME: Will we ever have proper type location here? Will we actually
9013 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009014 QualType T = getDerived().TransformType(E->getType());
9015 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009016 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009017
Douglas Gregora16548e2009-08-11 05:31:07 +00009018 if (!getDerived().AlwaysRebuild() &&
9019 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009020 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009021
Douglas Gregora16548e2009-08-11 05:31:07 +00009022 return getDerived().RebuildImplicitValueInitExpr(T);
9023}
Mike Stump11289f42009-09-09 15:08:12 +00009024
Douglas Gregora16548e2009-08-11 05:31:07 +00009025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009027TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009028 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9029 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009031
John McCalldadc5752010-08-24 06:29:42 +00009032 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009033 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009035
Douglas Gregora16548e2009-08-11 05:31:07 +00009036 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009037 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009038 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009039 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009040
John McCallb268a282010-08-23 23:25:46 +00009041 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009042 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009043}
9044
9045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009047TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009048 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009049 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009050 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9051 &ArgumentChanged))
9052 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009053
Douglas Gregora16548e2009-08-11 05:31:07 +00009054 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009055 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009056 E->getRParenLoc());
9057}
Mike Stump11289f42009-09-09 15:08:12 +00009058
Douglas Gregora16548e2009-08-11 05:31:07 +00009059/// \brief Transform an address-of-label expression.
9060///
9061/// By default, the transformation of an address-of-label expression always
9062/// rebuilds the expression, so that the label identifier can be resolved to
9063/// the corresponding label statement by semantic analysis.
9064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009066TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009067 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9068 E->getLabel());
9069 if (!LD)
9070 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009071
Douglas Gregora16548e2009-08-11 05:31:07 +00009072 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009073 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009074}
Mike Stump11289f42009-09-09 15:08:12 +00009075
9076template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009078TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009079 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009080 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009081 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009082 if (SubStmt.isInvalid()) {
9083 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009084 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009085 }
Mike Stump11289f42009-09-09 15:08:12 +00009086
Douglas Gregora16548e2009-08-11 05:31:07 +00009087 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009088 SubStmt.get() == E->getSubStmt()) {
9089 // Calling this an 'error' is unintuitive, but it does the right thing.
9090 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009091 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009092 }
Mike Stump11289f42009-09-09 15:08:12 +00009093
9094 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009095 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009096 E->getRParenLoc());
9097}
Mike Stump11289f42009-09-09 15:08:12 +00009098
Douglas Gregora16548e2009-08-11 05:31:07 +00009099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009101TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009102 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009103 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009105
John McCalldadc5752010-08-24 06:29:42 +00009106 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009107 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009109
John McCalldadc5752010-08-24 06:29:42 +00009110 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009111 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009112 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009113
Douglas Gregora16548e2009-08-11 05:31:07 +00009114 if (!getDerived().AlwaysRebuild() &&
9115 Cond.get() == E->getCond() &&
9116 LHS.get() == E->getLHS() &&
9117 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009118 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009119
Douglas Gregora16548e2009-08-11 05:31:07 +00009120 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009121 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009122 E->getRParenLoc());
9123}
Mike Stump11289f42009-09-09 15:08:12 +00009124
Douglas Gregora16548e2009-08-11 05:31:07 +00009125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009127TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009128 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009129}
9130
9131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009133TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009134 switch (E->getOperator()) {
9135 case OO_New:
9136 case OO_Delete:
9137 case OO_Array_New:
9138 case OO_Array_Delete:
9139 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009140
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009141 case OO_Call: {
9142 // This is a call to an object's operator().
9143 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9144
9145 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009146 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009147 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009148 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009149
9150 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009151 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9152 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009153
9154 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009155 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009156 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009157 Args))
9158 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009159
John McCallb268a282010-08-23 23:25:46 +00009160 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009161 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009162 E->getLocEnd());
9163 }
9164
9165#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9166 case OO_##Name:
9167#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9168#include "clang/Basic/OperatorKinds.def"
9169 case OO_Subscript:
9170 // Handled below.
9171 break;
9172
9173 case OO_Conditional:
9174 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009175
9176 case OO_None:
9177 case NUM_OVERLOADED_OPERATORS:
9178 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009179 }
9180
John McCalldadc5752010-08-24 06:29:42 +00009181 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009182 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009183 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009184
Richard Smithdb2630f2012-10-21 03:28:35 +00009185 ExprResult First;
9186 if (E->getOperator() == OO_Amp)
9187 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9188 else
9189 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009190 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009191 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009192
John McCalldadc5752010-08-24 06:29:42 +00009193 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009194 if (E->getNumArgs() == 2) {
9195 Second = getDerived().TransformExpr(E->getArg(1));
9196 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009197 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009198 }
Mike Stump11289f42009-09-09 15:08:12 +00009199
Douglas Gregora16548e2009-08-11 05:31:07 +00009200 if (!getDerived().AlwaysRebuild() &&
9201 Callee.get() == E->getCallee() &&
9202 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009203 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009204 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009205
Lang Hames5de91cc2012-10-02 04:45:10 +00009206 Sema::FPContractStateRAII FPContractState(getSema());
9207 getSema().FPFeatures.fp_contract = E->isFPContractable();
9208
Douglas Gregora16548e2009-08-11 05:31:07 +00009209 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9210 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009211 Callee.get(),
9212 First.get(),
9213 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009214}
Mike Stump11289f42009-09-09 15:08:12 +00009215
Douglas Gregora16548e2009-08-11 05:31:07 +00009216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009217ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009218TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9219 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009220}
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
Peter Collingbourne41f85462011-02-09 21:07:24 +00009224TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9225 // Transform the callee.
9226 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9227 if (Callee.isInvalid())
9228 return ExprError();
9229
9230 // Transform exec config.
9231 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9232 if (EC.isInvalid())
9233 return ExprError();
9234
9235 // Transform arguments.
9236 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009237 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009238 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009239 &ArgChanged))
9240 return ExprError();
9241
9242 if (!getDerived().AlwaysRebuild() &&
9243 Callee.get() == E->getCallee() &&
9244 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009245 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009246
9247 // FIXME: Wrong source location information for the '('.
9248 SourceLocation FakeLParenLoc
9249 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9250 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009251 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009252 E->getRParenLoc(), EC.get());
9253}
9254
9255template<typename Derived>
9256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009257TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009258 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9259 if (!Type)
9260 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009261
John McCalldadc5752010-08-24 06:29:42 +00009262 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009263 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009264 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009265 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009266
Douglas Gregora16548e2009-08-11 05:31:07 +00009267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009268 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009269 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009270 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009271 return getDerived().RebuildCXXNamedCastExpr(
9272 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9273 Type, E->getAngleBrackets().getEnd(),
9274 // FIXME. this should be '(' location
9275 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009276}
Mike Stump11289f42009-09-09 15:08:12 +00009277
Douglas Gregora16548e2009-08-11 05:31:07 +00009278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009280TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9281 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009282}
Mike Stump11289f42009-09-09 15:08:12 +00009283
9284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009286TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9287 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009288}
9289
Douglas Gregora16548e2009-08-11 05:31:07 +00009290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009291ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009292TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009293 CXXReinterpretCastExpr *E) {
9294 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009295}
Mike Stump11289f42009-09-09 15:08:12 +00009296
Douglas Gregora16548e2009-08-11 05:31:07 +00009297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009298ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009299TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9300 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009301}
Mike Stump11289f42009-09-09 15:08:12 +00009302
Douglas Gregora16548e2009-08-11 05:31:07 +00009303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009304ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009305TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009306 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009307 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9308 if (!Type)
9309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009310
John McCalldadc5752010-08-24 06:29:42 +00009311 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009312 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009313 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009314 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009315
Douglas Gregora16548e2009-08-11 05:31:07 +00009316 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009317 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009318 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009319 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009320
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009321 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009322 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009323 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009324 E->getRParenLoc());
9325}
Mike Stump11289f42009-09-09 15:08:12 +00009326
Douglas Gregora16548e2009-08-11 05:31:07 +00009327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009328ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009329TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009330 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009331 TypeSourceInfo *TInfo
9332 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9333 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009334 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009335
Douglas Gregora16548e2009-08-11 05:31:07 +00009336 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009337 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009338 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009339
Douglas Gregor9da64192010-04-26 22:37:10 +00009340 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9341 E->getLocStart(),
9342 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009343 E->getLocEnd());
9344 }
Mike Stump11289f42009-09-09 15:08:12 +00009345
Eli Friedman456f0182012-01-20 01:26:23 +00009346 // We don't know whether the subexpression is potentially evaluated until
9347 // after we perform semantic analysis. We speculatively assume it is
9348 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009349 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009350 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9351 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009352
John McCalldadc5752010-08-24 06:29:42 +00009353 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009354 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009356
Douglas Gregora16548e2009-08-11 05:31:07 +00009357 if (!getDerived().AlwaysRebuild() &&
9358 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009359 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009360
Douglas Gregor9da64192010-04-26 22:37:10 +00009361 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9362 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009363 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009364 E->getLocEnd());
9365}
9366
9367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009368ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009369TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9370 if (E->isTypeOperand()) {
9371 TypeSourceInfo *TInfo
9372 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9373 if (!TInfo)
9374 return ExprError();
9375
9376 if (!getDerived().AlwaysRebuild() &&
9377 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009378 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009379
Douglas Gregor69735112011-03-06 17:40:41 +00009380 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009381 E->getLocStart(),
9382 TInfo,
9383 E->getLocEnd());
9384 }
9385
Francois Pichet9f4f2072010-09-08 12:20:18 +00009386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9387
9388 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9389 if (SubExpr.isInvalid())
9390 return ExprError();
9391
9392 if (!getDerived().AlwaysRebuild() &&
9393 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009394 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009395
9396 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9397 E->getLocStart(),
9398 SubExpr.get(),
9399 E->getLocEnd());
9400}
9401
9402template<typename Derived>
9403ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009404TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009405 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009406}
Mike Stump11289f42009-09-09 15:08:12 +00009407
Douglas Gregora16548e2009-08-11 05:31:07 +00009408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009409ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009410TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009411 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009412 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009413}
Mike Stump11289f42009-09-09 15:08:12 +00009414
Douglas Gregora16548e2009-08-11 05:31:07 +00009415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009417TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009418 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009419
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009420 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9421 // Make sure that we capture 'this'.
9422 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009423 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009425
Douglas Gregorb15af892010-01-07 23:12:05 +00009426 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009427}
Mike Stump11289f42009-09-09 15:08:12 +00009428
Douglas Gregora16548e2009-08-11 05:31:07 +00009429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009431TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009432 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009433 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009435
Douglas Gregora16548e2009-08-11 05:31:07 +00009436 if (!getDerived().AlwaysRebuild() &&
9437 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009438 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009439
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009440 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9441 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009442}
Mike Stump11289f42009-09-09 15:08:12 +00009443
Douglas Gregora16548e2009-08-11 05:31:07 +00009444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009446TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009447 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009448 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9449 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009450 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009452
Chandler Carruth794da4c2010-02-08 06:42:49 +00009453 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009454 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009455 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009456
Douglas Gregor033f6752009-12-23 23:03:06 +00009457 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009458}
Mike Stump11289f42009-09-09 15:08:12 +00009459
Douglas Gregora16548e2009-08-11 05:31:07 +00009460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009461ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009462TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9463 FieldDecl *Field
9464 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9465 E->getField()));
9466 if (!Field)
9467 return ExprError();
9468
9469 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009470 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009471
9472 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9473}
9474
9475template<typename Derived>
9476ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009477TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9478 CXXScalarValueInitExpr *E) {
9479 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9480 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009481 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009482
Douglas Gregora16548e2009-08-11 05:31:07 +00009483 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009484 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009485 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009486
Chad Rosier1dcde962012-08-08 18:46:20 +00009487 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009488 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009489 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009490}
Mike Stump11289f42009-09-09 15:08:12 +00009491
Douglas Gregora16548e2009-08-11 05:31:07 +00009492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009493ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009494TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009495 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009496 TypeSourceInfo *AllocTypeInfo
9497 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9498 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009499 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009500
Douglas Gregora16548e2009-08-11 05:31:07 +00009501 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009502 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009503 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009504 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009505
Douglas Gregora16548e2009-08-11 05:31:07 +00009506 // Transform the placement arguments (if any).
9507 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009508 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009509 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009510 E->getNumPlacementArgs(), true,
9511 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009513
Sebastian Redl6047f072012-02-16 12:22:20 +00009514 // Transform the initializer (if any).
9515 Expr *OldInit = E->getInitializer();
9516 ExprResult NewInit;
9517 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009518 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009519 if (NewInit.isInvalid())
9520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009521
Sebastian Redl6047f072012-02-16 12:22:20 +00009522 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009523 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009524 if (E->getOperatorNew()) {
9525 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009526 getDerived().TransformDecl(E->getLocStart(),
9527 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009528 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009529 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009530 }
9531
Craig Topperc3ec1492014-05-26 06:22:03 +00009532 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009533 if (E->getOperatorDelete()) {
9534 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009535 getDerived().TransformDecl(E->getLocStart(),
9536 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009537 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009538 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009539 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009540
Douglas Gregora16548e2009-08-11 05:31:07 +00009541 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009542 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009543 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009544 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009545 OperatorNew == E->getOperatorNew() &&
9546 OperatorDelete == E->getOperatorDelete() &&
9547 !ArgumentChanged) {
9548 // Mark any declarations we need as referenced.
9549 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009550 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009551 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009552 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009553 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009554
Sebastian Redl6047f072012-02-16 12:22:20 +00009555 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009556 QualType ElementType
9557 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9558 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9559 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9560 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009561 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009562 }
9563 }
9564 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009565
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009566 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009567 }
Mike Stump11289f42009-09-09 15:08:12 +00009568
Douglas Gregor0744ef62010-09-07 21:49:58 +00009569 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009570 if (!ArraySize.get()) {
9571 // If no array size was specified, but the new expression was
9572 // instantiated with an array type (e.g., "new T" where T is
9573 // instantiated with "int[4]"), extract the outer bound from the
9574 // array type as our array size. We do this with constant and
9575 // dependently-sized array types.
9576 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9577 if (!ArrayT) {
9578 // Do nothing
9579 } else if (const ConstantArrayType *ConsArrayT
9580 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009581 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9582 SemaRef.Context.getSizeType(),
9583 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009584 AllocType = ConsArrayT->getElementType();
9585 } else if (const DependentSizedArrayType *DepArrayT
9586 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9587 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009588 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009589 AllocType = DepArrayT->getElementType();
9590 }
9591 }
9592 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009593
Douglas Gregora16548e2009-08-11 05:31:07 +00009594 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9595 E->isGlobalNew(),
9596 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009597 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009598 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009599 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009600 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009601 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009602 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009603 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009604 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009605}
Mike Stump11289f42009-09-09 15:08:12 +00009606
Douglas Gregora16548e2009-08-11 05:31:07 +00009607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009609TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009610 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009611 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009612 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009613
Douglas Gregord2d9da02010-02-26 00:38:10 +00009614 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009615 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009616 if (E->getOperatorDelete()) {
9617 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009618 getDerived().TransformDecl(E->getLocStart(),
9619 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009620 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009621 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009622 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009623
Douglas Gregora16548e2009-08-11 05:31:07 +00009624 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009625 Operand.get() == E->getArgument() &&
9626 OperatorDelete == E->getOperatorDelete()) {
9627 // Mark any declarations we need as referenced.
9628 // FIXME: instantiation-specific.
9629 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009630 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009631
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009632 if (!E->getArgument()->isTypeDependent()) {
9633 QualType Destroyed = SemaRef.Context.getBaseElementType(
9634 E->getDestroyedType());
9635 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9636 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009637 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009638 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009639 }
9640 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009641
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009642 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009643 }
Mike Stump11289f42009-09-09 15:08:12 +00009644
Douglas Gregora16548e2009-08-11 05:31:07 +00009645 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9646 E->isGlobalDelete(),
9647 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009648 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009649}
Mike Stump11289f42009-09-09 15:08:12 +00009650
Douglas Gregora16548e2009-08-11 05:31:07 +00009651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009652ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009653TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009654 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009655 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009656 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009658
John McCallba7bf592010-08-24 05:47:05 +00009659 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009660 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009661 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009662 E->getOperatorLoc(),
9663 E->isArrow()? tok::arrow : tok::period,
9664 ObjectTypePtr,
9665 MayBePseudoDestructor);
9666 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009667 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009668
John McCallba7bf592010-08-24 05:47:05 +00009669 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009670 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9671 if (QualifierLoc) {
9672 QualifierLoc
9673 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9674 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009675 return ExprError();
9676 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009677 CXXScopeSpec SS;
9678 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009679
Douglas Gregor678f90d2010-02-25 01:56:36 +00009680 PseudoDestructorTypeStorage Destroyed;
9681 if (E->getDestroyedTypeInfo()) {
9682 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009683 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009684 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009685 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009686 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009687 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009688 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009689 // We aren't likely to be able to resolve the identifier down to a type
9690 // now anyway, so just retain the identifier.
9691 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9692 E->getDestroyedTypeLoc());
9693 } else {
9694 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009695 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009696 *E->getDestroyedTypeIdentifier(),
9697 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009698 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009699 SS, ObjectTypePtr,
9700 false);
9701 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009702 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009703
Douglas Gregor678f90d2010-02-25 01:56:36 +00009704 Destroyed
9705 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9706 E->getDestroyedTypeLoc());
9707 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009708
Craig Topperc3ec1492014-05-26 06:22:03 +00009709 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009710 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009711 CXXScopeSpec EmptySS;
9712 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009713 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009714 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009715 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009717
John McCallb268a282010-08-23 23:25:46 +00009718 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009719 E->getOperatorLoc(),
9720 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009721 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009722 ScopeTypeInfo,
9723 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009724 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009725 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009726}
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregorad8a3362009-09-04 17:36:40 +00009728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009729ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009730TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009731 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009732 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9733 Sema::LookupOrdinaryName);
9734
9735 // Transform all the decls.
9736 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9737 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009738 NamedDecl *InstD = static_cast<NamedDecl*>(
9739 getDerived().TransformDecl(Old->getNameLoc(),
9740 *I));
John McCall84d87672009-12-10 09:41:52 +00009741 if (!InstD) {
9742 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9743 // This can happen because of dependent hiding.
9744 if (isa<UsingShadowDecl>(*I))
9745 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009746 else {
9747 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009748 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009749 }
John McCall84d87672009-12-10 09:41:52 +00009750 }
John McCalle66edc12009-11-24 19:00:30 +00009751
9752 // Expand using declarations.
9753 if (isa<UsingDecl>(InstD)) {
9754 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009755 for (auto *I : UD->shadows())
9756 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009757 continue;
9758 }
9759
9760 R.addDecl(InstD);
9761 }
9762
9763 // Resolve a kind, but don't do any further analysis. If it's
9764 // ambiguous, the callee needs to deal with it.
9765 R.resolveKind();
9766
9767 // Rebuild the nested-name qualifier, if present.
9768 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009769 if (Old->getQualifierLoc()) {
9770 NestedNameSpecifierLoc QualifierLoc
9771 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9772 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009773 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009774
Douglas Gregor0da1d432011-02-28 20:01:57 +00009775 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009776 }
9777
Douglas Gregor9262f472010-04-27 18:19:34 +00009778 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009779 CXXRecordDecl *NamingClass
9780 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9781 Old->getNameLoc(),
9782 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009783 if (!NamingClass) {
9784 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009785 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009786 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009787
Douglas Gregorda7be082010-04-27 16:10:10 +00009788 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009789 }
9790
Abramo Bagnara7945c982012-01-27 09:46:47 +00009791 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9792
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009793 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009794 // it's a normal declaration name or member reference.
9795 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9796 NamedDecl *D = R.getAsSingle<NamedDecl>();
9797 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9798 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9799 // give a good diagnostic.
9800 if (D && D->isCXXInstanceMember()) {
9801 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9802 /*TemplateArgs=*/nullptr,
9803 /*Scope=*/nullptr);
9804 }
9805
John McCalle66edc12009-11-24 19:00:30 +00009806 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009807 }
John McCalle66edc12009-11-24 19:00:30 +00009808
9809 // If we have template arguments, rebuild them, then rebuild the
9810 // templateid expression.
9811 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009812 if (Old->hasExplicitTemplateArgs() &&
9813 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009814 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009815 TransArgs)) {
9816 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009817 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009818 }
John McCalle66edc12009-11-24 19:00:30 +00009819
Abramo Bagnara7945c982012-01-27 09:46:47 +00009820 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009821 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009822}
Mike Stump11289f42009-09-09 15:08:12 +00009823
Douglas Gregora16548e2009-08-11 05:31:07 +00009824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009825ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009826TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9827 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009828 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009829 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9830 TypeSourceInfo *From = E->getArg(I);
9831 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009832 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009833 TypeLocBuilder TLB;
9834 TLB.reserve(FromTL.getFullDataSize());
9835 QualType To = getDerived().TransformType(TLB, FromTL);
9836 if (To.isNull())
9837 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009838
Douglas Gregor29c42f22012-02-24 07:38:34 +00009839 if (To == From->getType())
9840 Args.push_back(From);
9841 else {
9842 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9843 ArgChanged = true;
9844 }
9845 continue;
9846 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009847
Douglas Gregor29c42f22012-02-24 07:38:34 +00009848 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009849
Douglas Gregor29c42f22012-02-24 07:38:34 +00009850 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009851 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009852 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9853 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9854 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009855
Douglas Gregor29c42f22012-02-24 07:38:34 +00009856 // Determine whether the set of unexpanded parameter packs can and should
9857 // be expanded.
9858 bool Expand = true;
9859 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009860 Optional<unsigned> OrigNumExpansions =
9861 ExpansionTL.getTypePtr()->getNumExpansions();
9862 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009863 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9864 PatternTL.getSourceRange(),
9865 Unexpanded,
9866 Expand, RetainExpansion,
9867 NumExpansions))
9868 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009869
Douglas Gregor29c42f22012-02-24 07:38:34 +00009870 if (!Expand) {
9871 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009872 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009873 // expansion.
9874 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009875
Douglas Gregor29c42f22012-02-24 07:38:34 +00009876 TypeLocBuilder TLB;
9877 TLB.reserve(From->getTypeLoc().getFullDataSize());
9878
9879 QualType To = getDerived().TransformType(TLB, PatternTL);
9880 if (To.isNull())
9881 return ExprError();
9882
Chad Rosier1dcde962012-08-08 18:46:20 +00009883 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009884 PatternTL.getSourceRange(),
9885 ExpansionTL.getEllipsisLoc(),
9886 NumExpansions);
9887 if (To.isNull())
9888 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009889
Douglas Gregor29c42f22012-02-24 07:38:34 +00009890 PackExpansionTypeLoc ToExpansionTL
9891 = TLB.push<PackExpansionTypeLoc>(To);
9892 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9893 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9894 continue;
9895 }
9896
9897 // Expand the pack expansion by substituting for each argument in the
9898 // pack(s).
9899 for (unsigned I = 0; I != *NumExpansions; ++I) {
9900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9901 TypeLocBuilder TLB;
9902 TLB.reserve(PatternTL.getFullDataSize());
9903 QualType To = getDerived().TransformType(TLB, PatternTL);
9904 if (To.isNull())
9905 return ExprError();
9906
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009907 if (To->containsUnexpandedParameterPack()) {
9908 To = getDerived().RebuildPackExpansionType(To,
9909 PatternTL.getSourceRange(),
9910 ExpansionTL.getEllipsisLoc(),
9911 NumExpansions);
9912 if (To.isNull())
9913 return ExprError();
9914
9915 PackExpansionTypeLoc ToExpansionTL
9916 = TLB.push<PackExpansionTypeLoc>(To);
9917 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9918 }
9919
Douglas Gregor29c42f22012-02-24 07:38:34 +00009920 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9921 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009922
Douglas Gregor29c42f22012-02-24 07:38:34 +00009923 if (!RetainExpansion)
9924 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009925
Douglas Gregor29c42f22012-02-24 07:38:34 +00009926 // If we're supposed to retain a pack expansion, do so by temporarily
9927 // forgetting the partially-substituted parameter pack.
9928 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9929
9930 TypeLocBuilder TLB;
9931 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009932
Douglas Gregor29c42f22012-02-24 07:38:34 +00009933 QualType To = getDerived().TransformType(TLB, PatternTL);
9934 if (To.isNull())
9935 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009936
9937 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009938 PatternTL.getSourceRange(),
9939 ExpansionTL.getEllipsisLoc(),
9940 NumExpansions);
9941 if (To.isNull())
9942 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009943
Douglas Gregor29c42f22012-02-24 07:38:34 +00009944 PackExpansionTypeLoc ToExpansionTL
9945 = TLB.push<PackExpansionTypeLoc>(To);
9946 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9947 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009949
Douglas Gregor29c42f22012-02-24 07:38:34 +00009950 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009951 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009952
9953 return getDerived().RebuildTypeTrait(E->getTrait(),
9954 E->getLocStart(),
9955 Args,
9956 E->getLocEnd());
9957}
9958
9959template<typename Derived>
9960ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009961TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9962 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9963 if (!T)
9964 return ExprError();
9965
9966 if (!getDerived().AlwaysRebuild() &&
9967 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009968 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009969
9970 ExprResult SubExpr;
9971 {
9972 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9973 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9974 if (SubExpr.isInvalid())
9975 return ExprError();
9976
9977 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009978 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009979 }
9980
9981 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9982 E->getLocStart(),
9983 T,
9984 SubExpr.get(),
9985 E->getLocEnd());
9986}
9987
9988template<typename Derived>
9989ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009990TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9991 ExprResult SubExpr;
9992 {
9993 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9994 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9995 if (SubExpr.isInvalid())
9996 return ExprError();
9997
9998 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009999 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010000 }
10001
10002 return getDerived().RebuildExpressionTrait(
10003 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10004}
10005
Reid Kleckner32506ed2014-06-12 23:03:48 +000010006template <typename Derived>
10007ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10008 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10009 TypeSourceInfo **RecoveryTSI) {
10010 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10011 DRE, AddrTaken, RecoveryTSI);
10012
10013 // Propagate both errors and recovered types, which return ExprEmpty.
10014 if (!NewDRE.isUsable())
10015 return NewDRE;
10016
10017 // We got an expr, wrap it up in parens.
10018 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10019 return PE;
10020 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10021 PE->getRParen());
10022}
10023
10024template <typename Derived>
10025ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10026 DependentScopeDeclRefExpr *E) {
10027 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10028 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010029}
10030
10031template<typename Derived>
10032ExprResult
10033TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10034 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010035 bool IsAddressOfOperand,
10036 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010037 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010038 NestedNameSpecifierLoc QualifierLoc
10039 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10040 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010041 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010042 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010043
John McCall31f82722010-11-12 08:19:04 +000010044 // TODO: If this is a conversion-function-id, verify that the
10045 // destination type name (if present) resolves the same way after
10046 // instantiation as it did in the local scope.
10047
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010048 DeclarationNameInfo NameInfo
10049 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10050 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010052
John McCalle66edc12009-11-24 19:00:30 +000010053 if (!E->hasExplicitTemplateArgs()) {
10054 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010055 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010056 // Note: it is sufficient to compare the Name component of NameInfo:
10057 // if name has not changed, DNLoc has not changed either.
10058 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010059 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010060
Reid Kleckner32506ed2014-06-12 23:03:48 +000010061 return getDerived().RebuildDependentScopeDeclRefExpr(
10062 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10063 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010064 }
John McCall6b51f282009-11-23 01:53:49 +000010065
10066 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010067 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10068 E->getNumTemplateArgs(),
10069 TransArgs))
10070 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010071
Reid Kleckner32506ed2014-06-12 23:03:48 +000010072 return getDerived().RebuildDependentScopeDeclRefExpr(
10073 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10074 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010075}
10076
10077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010079TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010080 // CXXConstructExprs other than for list-initialization and
10081 // CXXTemporaryObjectExpr are always implicit, so when we have
10082 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010083 if ((E->getNumArgs() == 1 ||
10084 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010085 (!getDerived().DropCallArgument(E->getArg(0))) &&
10086 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010087 return getDerived().TransformExpr(E->getArg(0));
10088
Douglas Gregora16548e2009-08-11 05:31:07 +000010089 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10090
10091 QualType T = getDerived().TransformType(E->getType());
10092 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010093 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010094
10095 CXXConstructorDecl *Constructor
10096 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010097 getDerived().TransformDecl(E->getLocStart(),
10098 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010099 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010101
Douglas Gregora16548e2009-08-11 05:31:07 +000010102 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010103 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010104 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010105 &ArgumentChanged))
10106 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010107
Douglas Gregora16548e2009-08-11 05:31:07 +000010108 if (!getDerived().AlwaysRebuild() &&
10109 T == E->getType() &&
10110 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010111 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010112 // Mark the constructor as referenced.
10113 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010114 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010115 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010116 }
Mike Stump11289f42009-09-09 15:08:12 +000010117
Douglas Gregordb121ba2009-12-14 16:27:04 +000010118 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010119 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010120 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010121 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010122 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010123 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010124 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010125 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010126 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010127}
Mike Stump11289f42009-09-09 15:08:12 +000010128
Richard Smith5179eb72016-06-28 19:03:57 +000010129template<typename Derived>
10130ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10131 CXXInheritedCtorInitExpr *E) {
10132 QualType T = getDerived().TransformType(E->getType());
10133 if (T.isNull())
10134 return ExprError();
10135
10136 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10137 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10138 if (!Constructor)
10139 return ExprError();
10140
10141 if (!getDerived().AlwaysRebuild() &&
10142 T == E->getType() &&
10143 Constructor == E->getConstructor()) {
10144 // Mark the constructor as referenced.
10145 // FIXME: Instantiation-specific
10146 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10147 return E;
10148 }
10149
10150 return getDerived().RebuildCXXInheritedCtorInitExpr(
10151 T, E->getLocation(), Constructor,
10152 E->constructsVBase(), E->inheritedFromVBase());
10153}
10154
Douglas Gregora16548e2009-08-11 05:31:07 +000010155/// \brief Transform a C++ temporary-binding expression.
10156///
Douglas Gregor363b1512009-12-24 18:51:59 +000010157/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10158/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010161TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010162 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010163}
Mike Stump11289f42009-09-09 15:08:12 +000010164
John McCall5d413782010-12-06 08:20:24 +000010165/// \brief Transform a C++ expression that contains cleanups that should
10166/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010167///
John McCall5d413782010-12-06 08:20:24 +000010168/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010169/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010171ExprResult
John McCall5d413782010-12-06 08:20:24 +000010172TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010173 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010174}
Mike Stump11289f42009-09-09 15:08:12 +000010175
Douglas Gregora16548e2009-08-11 05:31:07 +000010176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010177ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010178TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010179 CXXTemporaryObjectExpr *E) {
10180 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10181 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010182 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010183
Douglas Gregora16548e2009-08-11 05:31:07 +000010184 CXXConstructorDecl *Constructor
10185 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010186 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010187 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010188 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010190
Douglas Gregora16548e2009-08-11 05:31:07 +000010191 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010192 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010193 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010194 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010195 &ArgumentChanged))
10196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010197
Douglas Gregora16548e2009-08-11 05:31:07 +000010198 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010199 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010200 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010201 !ArgumentChanged) {
10202 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010203 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010204 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010205 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010206
Richard Smithd59b8322012-12-19 01:39:02 +000010207 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010208 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10209 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010210 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010211 E->getLocEnd());
10212}
Mike Stump11289f42009-09-09 15:08:12 +000010213
Douglas Gregora16548e2009-08-11 05:31:07 +000010214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010215ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010216TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010217 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010218 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010219 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010220 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10221 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010222 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010223 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010224 CEnd = E->capture_end();
10225 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010226 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010227 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010228 EnterExpressionEvaluationContext EEEC(getSema(),
10229 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010230 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10231 C->getCapturedVar()->getInit(),
10232 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010233
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010234 if (NewExprInitResult.isInvalid())
10235 return ExprError();
10236 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010237
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010238 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010239 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010240 getSema().buildLambdaInitCaptureInitialization(
10241 C->getLocation(), OldVD->getType()->isReferenceType(),
10242 OldVD->getIdentifier(),
10243 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010244 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010245 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10246 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010247 }
10248
Faisal Vali2cba1332013-10-23 06:44:28 +000010249 // Transform the template parameters, and add them to the current
10250 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010251 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010252 E->getTemplateParameterList());
10253
Richard Smith01014ce2014-11-20 23:53:14 +000010254 // Transform the type of the original lambda's call operator.
10255 // The transformation MUST be done in the CurrentInstantiationScope since
10256 // it introduces a mapping of the original to the newly created
10257 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010258 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010259 {
10260 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10261 FunctionProtoTypeLoc OldCallOpFPTL =
10262 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010263
10264 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010265 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010266 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010267 QualType NewCallOpType = TransformFunctionProtoType(
10268 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010269 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10270 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10271 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010272 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010273 if (NewCallOpType.isNull())
10274 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010275 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10276 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010277 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010278
Richard Smithc38498f2015-04-27 21:27:54 +000010279 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10280 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10281 LSI->GLTemplateParameterList = TPL;
10282
Eli Friedmand564afb2012-09-19 01:18:11 +000010283 // Create the local class that will describe the lambda.
10284 CXXRecordDecl *Class
10285 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010286 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010287 /*KnownDependent=*/false,
10288 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010289 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10290
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010291 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010292 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10293 Class, E->getIntroducerRange(), NewCallOpTSI,
10294 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010295 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10296 E->getCallOperator()->isConstexpr());
10297
Faisal Vali2cba1332013-10-23 06:44:28 +000010298 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010299
Faisal Vali2cba1332013-10-23 06:44:28 +000010300 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010301 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010302
Douglas Gregorb4328232012-02-14 00:00:48 +000010303 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010304 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010305 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010306
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010307 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010308 getSema().buildLambdaScope(LSI, NewCallOperator,
10309 E->getIntroducerRange(),
10310 E->getCaptureDefault(),
10311 E->getCaptureDefaultLoc(),
10312 E->hasExplicitParameters(),
10313 E->hasExplicitResultType(),
10314 E->isMutable());
10315
10316 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010317
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010318 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010319 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010320 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010321 CEnd = E->capture_end();
10322 C != CEnd; ++C) {
10323 // When we hit the first implicit capture, tell Sema that we've finished
10324 // the list of explicit captures.
10325 if (!FinishedExplicitCaptures && C->isImplicit()) {
10326 getSema().finishLambdaExplicitCaptures(LSI);
10327 FinishedExplicitCaptures = true;
10328 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010329
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010330 // Capturing 'this' is trivial.
10331 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010332 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10333 /*BuildAndDiagnose*/ true, nullptr,
10334 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010335 continue;
10336 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010337 // Captured expression will be recaptured during captured variables
10338 // rebuilding.
10339 if (C->capturesVLAType())
10340 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010341
Richard Smithba71c082013-05-16 06:20:58 +000010342 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010343 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010344 InitCaptureInfoTy InitExprTypePair =
10345 InitCaptureExprsAndTypes[C - E->capture_begin()];
10346 ExprResult Init = InitExprTypePair.first;
10347 QualType InitQualType = InitExprTypePair.second;
10348 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010349 Invalid = true;
10350 continue;
10351 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010352 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010353 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010354 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10355 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010356 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010357 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010358 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010359 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010360 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010361 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010362 continue;
10363 }
10364
10365 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10366
Douglas Gregor3e308b12012-02-14 19:27:52 +000010367 // Determine the capture kind for Sema.
10368 Sema::TryCaptureKind Kind
10369 = C->isImplicit()? Sema::TryCapture_Implicit
10370 : C->getCaptureKind() == LCK_ByCopy
10371 ? Sema::TryCapture_ExplicitByVal
10372 : Sema::TryCapture_ExplicitByRef;
10373 SourceLocation EllipsisLoc;
10374 if (C->isPackExpansion()) {
10375 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10376 bool ShouldExpand = false;
10377 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010378 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010379 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10380 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010381 Unexpanded,
10382 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010383 NumExpansions)) {
10384 Invalid = true;
10385 continue;
10386 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010387
Douglas Gregor3e308b12012-02-14 19:27:52 +000010388 if (ShouldExpand) {
10389 // The transform has determined that we should perform an expansion;
10390 // transform and capture each of the arguments.
10391 // expansion of the pattern. Do so.
10392 VarDecl *Pack = C->getCapturedVar();
10393 for (unsigned I = 0; I != *NumExpansions; ++I) {
10394 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10395 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010396 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010397 Pack));
10398 if (!CapturedVar) {
10399 Invalid = true;
10400 continue;
10401 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010402
Douglas Gregor3e308b12012-02-14 19:27:52 +000010403 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010404 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10405 }
Richard Smith9467be42014-06-06 17:33:35 +000010406
10407 // FIXME: Retain a pack expansion if RetainExpansion is true.
10408
Douglas Gregor3e308b12012-02-14 19:27:52 +000010409 continue;
10410 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010411
Douglas Gregor3e308b12012-02-14 19:27:52 +000010412 EllipsisLoc = C->getEllipsisLoc();
10413 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010414
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010415 // Transform the captured variable.
10416 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010417 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010418 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010419 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010420 Invalid = true;
10421 continue;
10422 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010423
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010424 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010425 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10426 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010427 }
10428 if (!FinishedExplicitCaptures)
10429 getSema().finishLambdaExplicitCaptures(LSI);
10430
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010431 // Enter a new evaluation context to insulate the lambda from any
10432 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010433 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010434
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010435 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010436 StmtResult Body =
10437 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10438
10439 // ActOnLambda* will pop the function scope for us.
10440 FuncScopeCleanup.disable();
10441
Douglas Gregorb4328232012-02-14 00:00:48 +000010442 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010443 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010444 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010445 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010446 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010447 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010448
Richard Smithc38498f2015-04-27 21:27:54 +000010449 // Copy the LSI before ActOnFinishFunctionBody removes it.
10450 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10451 // the call operator.
10452 auto LSICopy = *LSI;
10453 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10454 /*IsInstantiation*/ true);
10455 SavedContext.pop();
10456
10457 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10458 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010459}
10460
10461template<typename Derived>
10462ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010463TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010464 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010465 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10466 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010468
Douglas Gregora16548e2009-08-11 05:31:07 +000010469 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010470 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010471 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010472 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010473 &ArgumentChanged))
10474 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010475
Douglas Gregora16548e2009-08-11 05:31:07 +000010476 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010477 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010478 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010479 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010480
Douglas Gregora16548e2009-08-11 05:31:07 +000010481 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010482 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010483 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010484 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010485 E->getRParenLoc());
10486}
Mike Stump11289f42009-09-09 15:08:12 +000010487
Douglas Gregora16548e2009-08-11 05:31:07 +000010488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010489ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010490TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010491 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010492 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010493 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010494 Expr *OldBase;
10495 QualType BaseType;
10496 QualType ObjectType;
10497 if (!E->isImplicitAccess()) {
10498 OldBase = E->getBase();
10499 Base = getDerived().TransformExpr(OldBase);
10500 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010501 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010502
John McCall2d74de92009-12-01 22:10:20 +000010503 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010504 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010505 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010506 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010507 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010508 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010509 ObjectTy,
10510 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010511 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010512 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010513
John McCallba7bf592010-08-24 05:47:05 +000010514 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010515 BaseType = ((Expr*) Base.get())->getType();
10516 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010517 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010518 BaseType = getDerived().TransformType(E->getBaseType());
10519 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10520 }
Mike Stump11289f42009-09-09 15:08:12 +000010521
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010522 // Transform the first part of the nested-name-specifier that qualifies
10523 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010524 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010525 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010526 E->getFirstQualifierFoundInScope(),
10527 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010528
Douglas Gregore16af532011-02-28 18:50:33 +000010529 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010530 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010531 QualifierLoc
10532 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10533 ObjectType,
10534 FirstQualifierInScope);
10535 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010536 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010537 }
Mike Stump11289f42009-09-09 15:08:12 +000010538
Abramo Bagnara7945c982012-01-27 09:46:47 +000010539 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10540
John McCall31f82722010-11-12 08:19:04 +000010541 // TODO: If this is a conversion-function-id, verify that the
10542 // destination type name (if present) resolves the same way after
10543 // instantiation as it did in the local scope.
10544
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010545 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010546 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010547 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010549
John McCall2d74de92009-12-01 22:10:20 +000010550 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010551 // This is a reference to a member without an explicitly-specified
10552 // template argument list. Optimize for this common case.
10553 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010554 Base.get() == OldBase &&
10555 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010556 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010557 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010558 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010559 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010560
John McCallb268a282010-08-23 23:25:46 +000010561 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010562 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010563 E->isArrow(),
10564 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010565 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010566 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010567 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010568 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010569 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010570 }
10571
John McCall6b51f282009-11-23 01:53:49 +000010572 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010573 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10574 E->getNumTemplateArgs(),
10575 TransArgs))
10576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010577
John McCallb268a282010-08-23 23:25:46 +000010578 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010579 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010580 E->isArrow(),
10581 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010582 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010583 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010584 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010585 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010586 &TransArgs);
10587}
10588
10589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010591TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010592 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010593 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010594 QualType BaseType;
10595 if (!Old->isImplicitAccess()) {
10596 Base = getDerived().TransformExpr(Old->getBase());
10597 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010598 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010599 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010600 Old->isArrow());
10601 if (Base.isInvalid())
10602 return ExprError();
10603 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010604 } else {
10605 BaseType = getDerived().TransformType(Old->getBaseType());
10606 }
John McCall10eae182009-11-30 22:42:35 +000010607
Douglas Gregor0da1d432011-02-28 20:01:57 +000010608 NestedNameSpecifierLoc QualifierLoc;
10609 if (Old->getQualifierLoc()) {
10610 QualifierLoc
10611 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10612 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010613 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010614 }
10615
Abramo Bagnara7945c982012-01-27 09:46:47 +000010616 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10617
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010618 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010619 Sema::LookupOrdinaryName);
10620
10621 // Transform all the decls.
10622 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10623 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010624 NamedDecl *InstD = static_cast<NamedDecl*>(
10625 getDerived().TransformDecl(Old->getMemberLoc(),
10626 *I));
John McCall84d87672009-12-10 09:41:52 +000010627 if (!InstD) {
10628 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10629 // This can happen because of dependent hiding.
10630 if (isa<UsingShadowDecl>(*I))
10631 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010632 else {
10633 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010634 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010635 }
John McCall84d87672009-12-10 09:41:52 +000010636 }
John McCall10eae182009-11-30 22:42:35 +000010637
10638 // Expand using declarations.
10639 if (isa<UsingDecl>(InstD)) {
10640 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010641 for (auto *I : UD->shadows())
10642 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010643 continue;
10644 }
10645
10646 R.addDecl(InstD);
10647 }
10648
10649 R.resolveKind();
10650
Douglas Gregor9262f472010-04-27 18:19:34 +000010651 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010652 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010653 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010654 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010655 Old->getMemberLoc(),
10656 Old->getNamingClass()));
10657 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010658 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010659
Douglas Gregorda7be082010-04-27 16:10:10 +000010660 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010661 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010662
John McCall10eae182009-11-30 22:42:35 +000010663 TemplateArgumentListInfo TransArgs;
10664 if (Old->hasExplicitTemplateArgs()) {
10665 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10666 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010667 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10668 Old->getNumTemplateArgs(),
10669 TransArgs))
10670 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010671 }
John McCall38836f02010-01-15 08:34:02 +000010672
10673 // FIXME: to do this check properly, we will need to preserve the
10674 // first-qualifier-in-scope here, just in case we had a dependent
10675 // base (and therefore couldn't do the check) and a
10676 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010677 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010678
John McCallb268a282010-08-23 23:25:46 +000010679 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010680 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010681 Old->getOperatorLoc(),
10682 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010683 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010684 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010685 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010686 R,
10687 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010688 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010689}
10690
10691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010692ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010693TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010694 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010695 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10696 if (SubExpr.isInvalid())
10697 return ExprError();
10698
10699 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010700 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010701
10702 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10703}
10704
10705template<typename Derived>
10706ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010707TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010708 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10709 if (Pattern.isInvalid())
10710 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010711
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010712 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010713 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010714
Douglas Gregorb8840002011-01-14 21:20:45 +000010715 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10716 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010717}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010718
10719template<typename Derived>
10720ExprResult
10721TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10722 // If E is not value-dependent, then nothing will change when we transform it.
10723 // Note: This is an instantiation-centric view.
10724 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010725 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010726
Richard Smithd784e682015-09-23 21:41:42 +000010727 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010728
Richard Smithd784e682015-09-23 21:41:42 +000010729 ArrayRef<TemplateArgument> PackArgs;
10730 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010731
Richard Smithd784e682015-09-23 21:41:42 +000010732 // Find the argument list to transform.
10733 if (E->isPartiallySubstituted()) {
10734 PackArgs = E->getPartialArguments();
10735 } else if (E->isValueDependent()) {
10736 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10737 bool ShouldExpand = false;
10738 bool RetainExpansion = false;
10739 Optional<unsigned> NumExpansions;
10740 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10741 Unexpanded,
10742 ShouldExpand, RetainExpansion,
10743 NumExpansions))
10744 return ExprError();
10745
10746 // If we need to expand the pack, build a template argument from it and
10747 // expand that.
10748 if (ShouldExpand) {
10749 auto *Pack = E->getPack();
10750 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10751 ArgStorage = getSema().Context.getPackExpansionType(
10752 getSema().Context.getTypeDeclType(TTPD), None);
10753 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10754 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10755 } else {
10756 auto *VD = cast<ValueDecl>(Pack);
10757 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10758 VK_RValue, E->getPackLoc());
10759 if (DRE.isInvalid())
10760 return ExprError();
10761 ArgStorage = new (getSema().Context) PackExpansionExpr(
10762 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10763 }
10764 PackArgs = ArgStorage;
10765 }
10766 }
10767
10768 // If we're not expanding the pack, just transform the decl.
10769 if (!PackArgs.size()) {
10770 auto *Pack = cast_or_null<NamedDecl>(
10771 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010772 if (!Pack)
10773 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010774 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10775 E->getPackLoc(),
10776 E->getRParenLoc(), None, None);
10777 }
10778
Richard Smithc5452ed2016-10-19 22:18:42 +000010779 // Try to compute the result without performing a partial substitution.
10780 Optional<unsigned> Result = 0;
10781 for (const TemplateArgument &Arg : PackArgs) {
10782 if (!Arg.isPackExpansion()) {
10783 Result = *Result + 1;
10784 continue;
10785 }
10786
10787 TemplateArgumentLoc ArgLoc;
10788 InventTemplateArgumentLoc(Arg, ArgLoc);
10789
10790 // Find the pattern of the pack expansion.
10791 SourceLocation Ellipsis;
10792 Optional<unsigned> OrigNumExpansions;
10793 TemplateArgumentLoc Pattern =
10794 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
10795 OrigNumExpansions);
10796
10797 // Substitute under the pack expansion. Do not expand the pack (yet).
10798 TemplateArgumentLoc OutPattern;
10799 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10800 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
10801 /*Uneval*/ true))
10802 return true;
10803
10804 // See if we can determine the number of arguments from the result.
10805 Optional<unsigned> NumExpansions =
10806 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
10807 if (!NumExpansions) {
10808 // No: we must be in an alias template expansion, and we're going to need
10809 // to actually expand the packs.
10810 Result = None;
10811 break;
10812 }
10813
10814 Result = *Result + *NumExpansions;
10815 }
10816
10817 // Common case: we could determine the number of expansions without
10818 // substituting.
10819 if (Result)
10820 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10821 E->getPackLoc(),
10822 E->getRParenLoc(), *Result, None);
10823
Richard Smithd784e682015-09-23 21:41:42 +000010824 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10825 E->getPackLoc());
10826 {
10827 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10828 typedef TemplateArgumentLocInventIterator<
10829 Derived, const TemplateArgument*> PackLocIterator;
10830 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10831 PackLocIterator(*this, PackArgs.end()),
10832 TransformedPackArgs, /*Uneval*/true))
10833 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010834 }
10835
Richard Smithc5452ed2016-10-19 22:18:42 +000010836 // Check whether we managed to fully-expand the pack.
10837 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000010838 SmallVector<TemplateArgument, 8> Args;
10839 bool PartialSubstitution = false;
10840 for (auto &Loc : TransformedPackArgs.arguments()) {
10841 Args.push_back(Loc.getArgument());
10842 if (Loc.getArgument().isPackExpansion())
10843 PartialSubstitution = true;
10844 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010845
Richard Smithd784e682015-09-23 21:41:42 +000010846 if (PartialSubstitution)
10847 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10848 E->getPackLoc(),
10849 E->getRParenLoc(), None, Args);
10850
10851 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010852 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010853 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010854}
10855
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010856template<typename Derived>
10857ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010858TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10859 SubstNonTypeTemplateParmPackExpr *E) {
10860 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010861 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010862}
10863
10864template<typename Derived>
10865ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010866TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10867 SubstNonTypeTemplateParmExpr *E) {
10868 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010869 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010870}
10871
10872template<typename Derived>
10873ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010874TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10875 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010876 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010877}
10878
10879template<typename Derived>
10880ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010881TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10882 MaterializeTemporaryExpr *E) {
10883 return getDerived().TransformExpr(E->GetTemporaryExpr());
10884}
Chad Rosier1dcde962012-08-08 18:46:20 +000010885
Douglas Gregorfe314812011-06-21 17:03:29 +000010886template<typename Derived>
10887ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010888TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10889 Expr *Pattern = E->getPattern();
10890
10891 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10892 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10893 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10894
10895 // Determine whether the set of unexpanded parameter packs can and should
10896 // be expanded.
10897 bool Expand = true;
10898 bool RetainExpansion = false;
10899 Optional<unsigned> NumExpansions;
10900 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10901 Pattern->getSourceRange(),
10902 Unexpanded,
10903 Expand, RetainExpansion,
10904 NumExpansions))
10905 return true;
10906
10907 if (!Expand) {
10908 // Do not expand any packs here, just transform and rebuild a fold
10909 // expression.
10910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10911
10912 ExprResult LHS =
10913 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10914 if (LHS.isInvalid())
10915 return true;
10916
10917 ExprResult RHS =
10918 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10919 if (RHS.isInvalid())
10920 return true;
10921
10922 if (!getDerived().AlwaysRebuild() &&
10923 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10924 return E;
10925
10926 return getDerived().RebuildCXXFoldExpr(
10927 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10928 RHS.get(), E->getLocEnd());
10929 }
10930
10931 // The transform has determined that we should perform an elementwise
10932 // expansion of the pattern. Do so.
10933 ExprResult Result = getDerived().TransformExpr(E->getInit());
10934 if (Result.isInvalid())
10935 return true;
10936 bool LeftFold = E->isLeftFold();
10937
10938 // If we're retaining an expansion for a right fold, it is the innermost
10939 // component and takes the init (if any).
10940 if (!LeftFold && RetainExpansion) {
10941 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10942
10943 ExprResult Out = getDerived().TransformExpr(Pattern);
10944 if (Out.isInvalid())
10945 return true;
10946
10947 Result = getDerived().RebuildCXXFoldExpr(
10948 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10949 Result.get(), E->getLocEnd());
10950 if (Result.isInvalid())
10951 return true;
10952 }
10953
10954 for (unsigned I = 0; I != *NumExpansions; ++I) {
10955 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10956 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10957 ExprResult Out = getDerived().TransformExpr(Pattern);
10958 if (Out.isInvalid())
10959 return true;
10960
10961 if (Out.get()->containsUnexpandedParameterPack()) {
10962 // We still have a pack; retain a pack expansion for this slice.
10963 Result = getDerived().RebuildCXXFoldExpr(
10964 E->getLocStart(),
10965 LeftFold ? Result.get() : Out.get(),
10966 E->getOperator(), E->getEllipsisLoc(),
10967 LeftFold ? Out.get() : Result.get(),
10968 E->getLocEnd());
10969 } else if (Result.isUsable()) {
10970 // We've got down to a single element; build a binary operator.
10971 Result = getDerived().RebuildBinaryOperator(
10972 E->getEllipsisLoc(), E->getOperator(),
10973 LeftFold ? Result.get() : Out.get(),
10974 LeftFold ? Out.get() : Result.get());
10975 } else
10976 Result = Out;
10977
10978 if (Result.isInvalid())
10979 return true;
10980 }
10981
10982 // If we're retaining an expansion for a left fold, it is the outermost
10983 // component and takes the complete expansion so far as its init (if any).
10984 if (LeftFold && RetainExpansion) {
10985 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10986
10987 ExprResult Out = getDerived().TransformExpr(Pattern);
10988 if (Out.isInvalid())
10989 return true;
10990
10991 Result = getDerived().RebuildCXXFoldExpr(
10992 E->getLocStart(), Result.get(),
10993 E->getOperator(), E->getEllipsisLoc(),
10994 Out.get(), E->getLocEnd());
10995 if (Result.isInvalid())
10996 return true;
10997 }
10998
10999 // If we had no init and an empty pack, and we're not retaining an expansion,
11000 // then produce a fallback value or error.
11001 if (Result.isUnset())
11002 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11003 E->getOperator());
11004
11005 return Result;
11006}
11007
11008template<typename Derived>
11009ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011010TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11011 CXXStdInitializerListExpr *E) {
11012 return getDerived().TransformExpr(E->getSubExpr());
11013}
11014
11015template<typename Derived>
11016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011017TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011018 return SemaRef.MaybeBindToTemporary(E);
11019}
11020
11021template<typename Derived>
11022ExprResult
11023TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011024 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011025}
11026
11027template<typename Derived>
11028ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011029TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11030 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11031 if (SubExpr.isInvalid())
11032 return ExprError();
11033
11034 if (!getDerived().AlwaysRebuild() &&
11035 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011036 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011037
11038 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011039}
11040
11041template<typename Derived>
11042ExprResult
11043TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11044 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011045 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011046 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011047 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011048 /*IsCall=*/false, Elements, &ArgChanged))
11049 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011050
Ted Kremeneke65b0862012-03-06 20:05:56 +000011051 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11052 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011053
Ted Kremeneke65b0862012-03-06 20:05:56 +000011054 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11055 Elements.data(),
11056 Elements.size());
11057}
11058
11059template<typename Derived>
11060ExprResult
11061TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011062 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011063 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011064 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011065 bool ArgChanged = false;
11066 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11067 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011068
Ted Kremeneke65b0862012-03-06 20:05:56 +000011069 if (OrigElement.isPackExpansion()) {
11070 // This key/value element is a pack expansion.
11071 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11072 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11073 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11074 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11075
11076 // Determine whether the set of unexpanded parameter packs can
11077 // and should be expanded.
11078 bool Expand = true;
11079 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011080 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11081 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011082 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11083 OrigElement.Value->getLocEnd());
11084 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11085 PatternRange,
11086 Unexpanded,
11087 Expand, RetainExpansion,
11088 NumExpansions))
11089 return ExprError();
11090
11091 if (!Expand) {
11092 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011093 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011094 // expansion.
11095 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11096 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11097 if (Key.isInvalid())
11098 return ExprError();
11099
11100 if (Key.get() != OrigElement.Key)
11101 ArgChanged = true;
11102
11103 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11104 if (Value.isInvalid())
11105 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011106
Ted Kremeneke65b0862012-03-06 20:05:56 +000011107 if (Value.get() != OrigElement.Value)
11108 ArgChanged = true;
11109
Chad Rosier1dcde962012-08-08 18:46:20 +000011110 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011111 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11112 };
11113 Elements.push_back(Expansion);
11114 continue;
11115 }
11116
11117 // Record right away that the argument was changed. This needs
11118 // to happen even if the array expands to nothing.
11119 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011120
Ted Kremeneke65b0862012-03-06 20:05:56 +000011121 // The transform has determined that we should perform an elementwise
11122 // expansion of the pattern. Do so.
11123 for (unsigned I = 0; I != *NumExpansions; ++I) {
11124 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11125 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11126 if (Key.isInvalid())
11127 return ExprError();
11128
11129 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11130 if (Value.isInvalid())
11131 return ExprError();
11132
Chad Rosier1dcde962012-08-08 18:46:20 +000011133 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011134 Key.get(), Value.get(), SourceLocation(), NumExpansions
11135 };
11136
11137 // If any unexpanded parameter packs remain, we still have a
11138 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011139 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011140 if (Key.get()->containsUnexpandedParameterPack() ||
11141 Value.get()->containsUnexpandedParameterPack())
11142 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011143
Ted Kremeneke65b0862012-03-06 20:05:56 +000011144 Elements.push_back(Element);
11145 }
11146
Richard Smith9467be42014-06-06 17:33:35 +000011147 // FIXME: Retain a pack expansion if RetainExpansion is true.
11148
Ted Kremeneke65b0862012-03-06 20:05:56 +000011149 // We've finished with this pack expansion.
11150 continue;
11151 }
11152
11153 // Transform and check key.
11154 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11155 if (Key.isInvalid())
11156 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011157
Ted Kremeneke65b0862012-03-06 20:05:56 +000011158 if (Key.get() != OrigElement.Key)
11159 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011160
Ted Kremeneke65b0862012-03-06 20:05:56 +000011161 // Transform and check value.
11162 ExprResult Value
11163 = getDerived().TransformExpr(OrigElement.Value);
11164 if (Value.isInvalid())
11165 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011166
Ted Kremeneke65b0862012-03-06 20:05:56 +000011167 if (Value.get() != OrigElement.Value)
11168 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011169
11170 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011171 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011172 };
11173 Elements.push_back(Element);
11174 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011175
Ted Kremeneke65b0862012-03-06 20:05:56 +000011176 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11177 return SemaRef.MaybeBindToTemporary(E);
11178
11179 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011180 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011181}
11182
Mike Stump11289f42009-09-09 15:08:12 +000011183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011185TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011186 TypeSourceInfo *EncodedTypeInfo
11187 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11188 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011190
Douglas Gregora16548e2009-08-11 05:31:07 +000011191 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011192 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011193 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011194
11195 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011196 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011197 E->getRParenLoc());
11198}
Mike Stump11289f42009-09-09 15:08:12 +000011199
Douglas Gregora16548e2009-08-11 05:31:07 +000011200template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011201ExprResult TreeTransform<Derived>::
11202TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011203 // This is a kind of implicit conversion, and it needs to get dropped
11204 // and recomputed for the same general reasons that ImplicitCastExprs
11205 // do, as well a more specific one: this expression is only valid when
11206 // it appears *immediately* as an argument expression.
11207 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011208}
11209
11210template<typename Derived>
11211ExprResult TreeTransform<Derived>::
11212TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011213 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011214 = getDerived().TransformType(E->getTypeInfoAsWritten());
11215 if (!TSInfo)
11216 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011217
John McCall31168b02011-06-15 23:02:42 +000011218 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011219 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011220 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011221
John McCall31168b02011-06-15 23:02:42 +000011222 if (!getDerived().AlwaysRebuild() &&
11223 TSInfo == E->getTypeInfoAsWritten() &&
11224 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011225 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011226
John McCall31168b02011-06-15 23:02:42 +000011227 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011228 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011229 Result.get());
11230}
11231
Erik Pilkington29099de2016-07-16 00:35:23 +000011232template <typename Derived>
11233ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11234 ObjCAvailabilityCheckExpr *E) {
11235 return E;
11236}
11237
John McCall31168b02011-06-15 23:02:42 +000011238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011240TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011241 // Transform arguments.
11242 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011243 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011244 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011245 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011246 &ArgChanged))
11247 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011248
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011249 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11250 // Class message: transform the receiver type.
11251 TypeSourceInfo *ReceiverTypeInfo
11252 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11253 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011254 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011255
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011256 // If nothing changed, just retain the existing message send.
11257 if (!getDerived().AlwaysRebuild() &&
11258 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011259 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011260
11261 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011262 SmallVector<SourceLocation, 16> SelLocs;
11263 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011264 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11265 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011266 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011267 E->getMethodDecl(),
11268 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011269 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011270 E->getRightLoc());
11271 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011272 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11273 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011274 if (!E->getMethodDecl())
11275 return ExprError();
11276
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011277 // Build a new class message send to 'super'.
11278 SmallVector<SourceLocation, 16> SelLocs;
11279 E->getSelectorLocs(SelLocs);
11280 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11281 E->getSelector(),
11282 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011283 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011284 E->getMethodDecl(),
11285 E->getLeftLoc(),
11286 Args,
11287 E->getRightLoc());
11288 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011289
11290 // Instance message: transform the receiver
11291 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11292 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011293 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011294 = getDerived().TransformExpr(E->getInstanceReceiver());
11295 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011296 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011297
11298 // If nothing changed, just retain the existing message send.
11299 if (!getDerived().AlwaysRebuild() &&
11300 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011301 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011302
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011303 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011304 SmallVector<SourceLocation, 16> SelLocs;
11305 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011306 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011307 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011308 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011309 E->getMethodDecl(),
11310 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011311 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011312 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011313}
11314
Mike Stump11289f42009-09-09 15:08:12 +000011315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011317TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011318 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011319}
11320
Mike Stump11289f42009-09-09 15:08:12 +000011321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011323TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011324 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011325}
11326
Mike Stump11289f42009-09-09 15:08:12 +000011327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011328ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011329TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011330 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011331 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011332 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011333 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011334
11335 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011336
Douglas Gregord51d90d2010-04-26 20:11:03 +000011337 // If nothing changed, just retain the existing expression.
11338 if (!getDerived().AlwaysRebuild() &&
11339 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011340 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011341
John McCallb268a282010-08-23 23:25:46 +000011342 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011343 E->getLocation(),
11344 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011345}
11346
Mike Stump11289f42009-09-09 15:08:12 +000011347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011349TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011350 // 'super' and types never change. Property never changes. Just
11351 // retain the existing expression.
11352 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011353 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011354
Douglas Gregor9faee212010-04-26 20:47:02 +000011355 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011356 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011357 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011358 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011359
Douglas Gregor9faee212010-04-26 20:47:02 +000011360 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011361
Douglas Gregor9faee212010-04-26 20:47:02 +000011362 // If nothing changed, just retain the existing expression.
11363 if (!getDerived().AlwaysRebuild() &&
11364 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011365 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011366
John McCallb7bd14f2010-12-02 01:19:52 +000011367 if (E->isExplicitProperty())
11368 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11369 E->getExplicitProperty(),
11370 E->getLocation());
11371
11372 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011373 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011374 E->getImplicitPropertyGetter(),
11375 E->getImplicitPropertySetter(),
11376 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011377}
11378
Mike Stump11289f42009-09-09 15:08:12 +000011379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011380ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011381TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11382 // Transform the base expression.
11383 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11384 if (Base.isInvalid())
11385 return ExprError();
11386
11387 // Transform the key expression.
11388 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11389 if (Key.isInvalid())
11390 return ExprError();
11391
11392 // If nothing changed, just retain the existing expression.
11393 if (!getDerived().AlwaysRebuild() &&
11394 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011395 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011396
Chad Rosier1dcde962012-08-08 18:46:20 +000011397 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011398 Base.get(), Key.get(),
11399 E->getAtIndexMethodDecl(),
11400 E->setAtIndexMethodDecl());
11401}
11402
11403template<typename Derived>
11404ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011405TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011406 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011407 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011408 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011409 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011410
Douglas Gregord51d90d2010-04-26 20:11:03 +000011411 // If nothing changed, just retain the existing expression.
11412 if (!getDerived().AlwaysRebuild() &&
11413 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011414 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011415
John McCallb268a282010-08-23 23:25:46 +000011416 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011417 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011418 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011419}
11420
Mike Stump11289f42009-09-09 15:08:12 +000011421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011422ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011423TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011424 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011425 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011426 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011427 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011428 SubExprs, &ArgumentChanged))
11429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011430
Douglas Gregora16548e2009-08-11 05:31:07 +000011431 if (!getDerived().AlwaysRebuild() &&
11432 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011433 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011434
Douglas Gregora16548e2009-08-11 05:31:07 +000011435 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011436 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011437 E->getRParenLoc());
11438}
11439
Mike Stump11289f42009-09-09 15:08:12 +000011440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011441ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011442TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11443 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11444 if (SrcExpr.isInvalid())
11445 return ExprError();
11446
11447 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11448 if (!Type)
11449 return ExprError();
11450
11451 if (!getDerived().AlwaysRebuild() &&
11452 Type == E->getTypeSourceInfo() &&
11453 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011454 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011455
11456 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11457 SrcExpr.get(), Type,
11458 E->getRParenLoc());
11459}
11460
11461template<typename Derived>
11462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011463TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011464 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011465
Craig Topperc3ec1492014-05-26 06:22:03 +000011466 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011467 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11468
11469 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011470 blockScope->TheDecl->setBlockMissingReturnType(
11471 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011472
Chris Lattner01cf8db2011-07-20 06:58:45 +000011473 SmallVector<ParmVarDecl*, 4> params;
11474 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011475
John McCallc8e321d2016-03-01 02:09:25 +000011476 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11477
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011478 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011479 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011480 if (getDerived().TransformFunctionTypeParams(
11481 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11482 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11483 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011484 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011485 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011486 }
John McCall490112f2011-02-04 18:33:18 +000011487
Eli Friedman34b49062012-01-26 03:00:14 +000011488 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011489 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011490
John McCallc8e321d2016-03-01 02:09:25 +000011491 auto epi = exprFunctionType->getExtProtoInfo();
11492 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11493
Jordan Rose5c382722013-03-08 21:51:21 +000011494 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011495 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011496 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011497
11498 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011499 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011500 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011501
11502 if (!oldBlock->blockMissingReturnType()) {
11503 blockScope->HasImplicitReturnType = false;
11504 blockScope->ReturnType = exprResultType;
11505 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011506
John McCall3882ace2011-01-05 12:14:39 +000011507 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011508 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011509 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011510 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011511 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011512 }
John McCall3882ace2011-01-05 12:14:39 +000011513
John McCall490112f2011-02-04 18:33:18 +000011514#ifndef NDEBUG
11515 // In builds with assertions, make sure that we captured everything we
11516 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011517 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011518 for (const auto &I : oldBlock->captures()) {
11519 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011520
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011521 // Ignore parameter packs.
11522 if (isa<ParmVarDecl>(oldCapture) &&
11523 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11524 continue;
John McCall490112f2011-02-04 18:33:18 +000011525
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011526 VarDecl *newCapture =
11527 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11528 oldCapture));
11529 assert(blockScope->CaptureMap.count(newCapture));
11530 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011531 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011532 }
11533#endif
11534
11535 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011536 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011537}
11538
Mike Stump11289f42009-09-09 15:08:12 +000011539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011540ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011541TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011542 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011543}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011544
11545template<typename Derived>
11546ExprResult
11547TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011548 QualType RetTy = getDerived().TransformType(E->getType());
11549 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011550 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011551 SubExprs.reserve(E->getNumSubExprs());
11552 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11553 SubExprs, &ArgumentChanged))
11554 return ExprError();
11555
11556 if (!getDerived().AlwaysRebuild() &&
11557 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011558 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011559
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011560 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011561 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011562}
Chad Rosier1dcde962012-08-08 18:46:20 +000011563
Douglas Gregora16548e2009-08-11 05:31:07 +000011564//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011565// Type reconstruction
11566//===----------------------------------------------------------------------===//
11567
Mike Stump11289f42009-09-09 15:08:12 +000011568template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011569QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11570 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011571 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011572 getDerived().getBaseEntity());
11573}
11574
Mike Stump11289f42009-09-09 15:08:12 +000011575template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011576QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11577 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011578 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011579 getDerived().getBaseEntity());
11580}
11581
Mike Stump11289f42009-09-09 15:08:12 +000011582template<typename Derived>
11583QualType
John McCall70dd5f62009-10-30 00:06:24 +000011584TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11585 bool WrittenAsLValue,
11586 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011587 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011588 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011589}
11590
11591template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011592QualType
John McCall70dd5f62009-10-30 00:06:24 +000011593TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11594 QualType ClassType,
11595 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011596 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11597 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011598}
11599
11600template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000011601QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11602 const ObjCTypeParamDecl *Decl,
11603 SourceLocation ProtocolLAngleLoc,
11604 ArrayRef<ObjCProtocolDecl *> Protocols,
11605 ArrayRef<SourceLocation> ProtocolLocs,
11606 SourceLocation ProtocolRAngleLoc) {
11607 return SemaRef.BuildObjCTypeParamType(Decl,
11608 ProtocolLAngleLoc, Protocols,
11609 ProtocolLocs, ProtocolRAngleLoc,
11610 /*FailOnError=*/true);
11611}
11612
11613template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011614QualType TreeTransform<Derived>::RebuildObjCObjectType(
11615 QualType BaseType,
11616 SourceLocation Loc,
11617 SourceLocation TypeArgsLAngleLoc,
11618 ArrayRef<TypeSourceInfo *> TypeArgs,
11619 SourceLocation TypeArgsRAngleLoc,
11620 SourceLocation ProtocolLAngleLoc,
11621 ArrayRef<ObjCProtocolDecl *> Protocols,
11622 ArrayRef<SourceLocation> ProtocolLocs,
11623 SourceLocation ProtocolRAngleLoc) {
11624 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11625 TypeArgs, TypeArgsRAngleLoc,
11626 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11627 ProtocolRAngleLoc,
11628 /*FailOnError=*/true);
11629}
11630
11631template<typename Derived>
11632QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11633 QualType PointeeType,
11634 SourceLocation Star) {
11635 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11636}
11637
11638template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011639QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011640TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11641 ArrayType::ArraySizeModifier SizeMod,
11642 const llvm::APInt *Size,
11643 Expr *SizeExpr,
11644 unsigned IndexTypeQuals,
11645 SourceRange BracketsRange) {
11646 if (SizeExpr || !Size)
11647 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11648 IndexTypeQuals, BracketsRange,
11649 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011650
11651 QualType Types[] = {
11652 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11653 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11654 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011655 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011656 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011657 QualType SizeType;
11658 for (unsigned I = 0; I != NumTypes; ++I)
11659 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11660 SizeType = Types[I];
11661 break;
11662 }
Mike Stump11289f42009-09-09 15:08:12 +000011663
Eli Friedman9562f392012-01-25 23:20:27 +000011664 // Note that we can return a VariableArrayType here in the case where
11665 // the element type was a dependent VariableArrayType.
11666 IntegerLiteral *ArraySize
11667 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11668 /*FIXME*/BracketsRange.getBegin());
11669 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011670 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011671 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011672}
Mike Stump11289f42009-09-09 15:08:12 +000011673
Douglas Gregord6ff3322009-08-04 16:50:30 +000011674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011675QualType
11676TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011677 ArrayType::ArraySizeModifier SizeMod,
11678 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011679 unsigned IndexTypeQuals,
11680 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011681 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011682 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011683}
11684
11685template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011686QualType
Mike Stump11289f42009-09-09 15:08:12 +000011687TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011688 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011689 unsigned IndexTypeQuals,
11690 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011691 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011692 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011693}
Mike Stump11289f42009-09-09 15:08:12 +000011694
Douglas Gregord6ff3322009-08-04 16:50:30 +000011695template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011696QualType
11697TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011698 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011699 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011700 unsigned IndexTypeQuals,
11701 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011702 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011703 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011704 IndexTypeQuals, BracketsRange);
11705}
11706
11707template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011708QualType
11709TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011710 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011711 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011712 unsigned IndexTypeQuals,
11713 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011714 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011715 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011716 IndexTypeQuals, BracketsRange);
11717}
11718
11719template<typename Derived>
11720QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011721 unsigned NumElements,
11722 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011723 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011724 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011725}
Mike Stump11289f42009-09-09 15:08:12 +000011726
Douglas Gregord6ff3322009-08-04 16:50:30 +000011727template<typename Derived>
11728QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11729 unsigned NumElements,
11730 SourceLocation AttributeLoc) {
11731 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11732 NumElements, true);
11733 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011734 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11735 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011736 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011737}
Mike Stump11289f42009-09-09 15:08:12 +000011738
Douglas Gregord6ff3322009-08-04 16:50:30 +000011739template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011740QualType
11741TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011742 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011743 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011744 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011745}
Mike Stump11289f42009-09-09 15:08:12 +000011746
Douglas Gregord6ff3322009-08-04 16:50:30 +000011747template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011748QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11749 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011750 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011751 const FunctionProtoType::ExtProtoInfo &EPI) {
11752 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011753 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011754 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011755 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011756}
Mike Stump11289f42009-09-09 15:08:12 +000011757
Douglas Gregord6ff3322009-08-04 16:50:30 +000011758template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011759QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11760 return SemaRef.Context.getFunctionNoProtoType(T);
11761}
11762
11763template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011764QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11765 assert(D && "no decl found");
11766 if (D->isInvalidDecl()) return QualType();
11767
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011768 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011769 TypeDecl *Ty;
11770 if (isa<UsingDecl>(D)) {
11771 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011772 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011773 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11774
11775 // A valid resolved using typename decl points to exactly one type decl.
11776 assert(++Using->shadow_begin() == Using->shadow_end());
11777 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011778
John McCallb96ec562009-12-04 22:46:56 +000011779 } else {
11780 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11781 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11782 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11783 }
11784
11785 return SemaRef.Context.getTypeDeclType(Ty);
11786}
11787
11788template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011789QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11790 SourceLocation Loc) {
11791 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011792}
11793
11794template<typename Derived>
11795QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11796 return SemaRef.Context.getTypeOfType(Underlying);
11797}
11798
11799template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011800QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11801 SourceLocation Loc) {
11802 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011803}
11804
11805template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011806QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11807 UnaryTransformType::UTTKind UKind,
11808 SourceLocation Loc) {
11809 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11810}
11811
11812template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011813QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011814 TemplateName Template,
11815 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011816 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011817 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011818}
Mike Stump11289f42009-09-09 15:08:12 +000011819
Douglas Gregor1135c352009-08-06 05:28:30 +000011820template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011821QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11822 SourceLocation KWLoc) {
11823 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11824}
11825
11826template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011827QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11828 SourceLocation KWLoc) {
11829 return SemaRef.BuildPipeType(ValueType, KWLoc);
11830}
11831
11832template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011833TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011834TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011835 bool TemplateKW,
11836 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011837 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011838 Template);
11839}
11840
11841template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011842TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011843TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11844 const IdentifierInfo &Name,
11845 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011846 QualType ObjectType,
11847 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011848 UnqualifiedId TemplateName;
11849 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011850 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011851 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011852 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011853 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011854 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011855 /*EnteringContext=*/false,
11856 Template);
John McCall31f82722010-11-12 08:19:04 +000011857 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011858}
Mike Stump11289f42009-09-09 15:08:12 +000011859
Douglas Gregora16548e2009-08-11 05:31:07 +000011860template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011861TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011862TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011863 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011864 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011865 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011866 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011867 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011868 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011869 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011870 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011871 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011872 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011873 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011874 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011875 /*EnteringContext=*/false,
11876 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011877 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011878}
Chad Rosier1dcde962012-08-08 18:46:20 +000011879
Douglas Gregor71395fa2009-11-04 00:56:37 +000011880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011881ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011882TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11883 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011884 Expr *OrigCallee,
11885 Expr *First,
11886 Expr *Second) {
11887 Expr *Callee = OrigCallee->IgnoreParenCasts();
11888 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011889
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011890 if (First->getObjectKind() == OK_ObjCProperty) {
11891 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11892 if (BinaryOperator::isAssignmentOp(Opc))
11893 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11894 First, Second);
11895 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11896 if (Result.isInvalid())
11897 return ExprError();
11898 First = Result.get();
11899 }
11900
11901 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11902 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11903 if (Result.isInvalid())
11904 return ExprError();
11905 Second = Result.get();
11906 }
11907
Douglas Gregora16548e2009-08-11 05:31:07 +000011908 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011909 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011910 if (!First->getType()->isOverloadableType() &&
11911 !Second->getType()->isOverloadableType())
11912 return getSema().CreateBuiltinArraySubscriptExpr(First,
11913 Callee->getLocStart(),
11914 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011915 } else if (Op == OO_Arrow) {
11916 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011917 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11918 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011919 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011920 // The argument is not of overloadable type, so try to create a
11921 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011922 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011923 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011924
John McCallb268a282010-08-23 23:25:46 +000011925 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011926 }
11927 } else {
John McCallb268a282010-08-23 23:25:46 +000011928 if (!First->getType()->isOverloadableType() &&
11929 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011930 // Neither of the arguments is an overloadable type, so try to
11931 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011932 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011933 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011934 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011935 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011937
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011938 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011939 }
11940 }
Mike Stump11289f42009-09-09 15:08:12 +000011941
11942 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011943 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011944 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011945
John McCallb268a282010-08-23 23:25:46 +000011946 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011947 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011948 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011949 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011950 // If we've resolved this to a particular non-member function, just call
11951 // that function. If we resolved it to a member function,
11952 // CreateOverloaded* will find that function for us.
11953 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11954 if (!isa<CXXMethodDecl>(ND))
11955 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011956 }
Mike Stump11289f42009-09-09 15:08:12 +000011957
Douglas Gregora16548e2009-08-11 05:31:07 +000011958 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011959 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011960 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011961
Douglas Gregora16548e2009-08-11 05:31:07 +000011962 // Create the overloaded operator invocation for unary operators.
11963 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011964 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011965 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011966 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011967 }
Mike Stump11289f42009-09-09 15:08:12 +000011968
Douglas Gregore9d62932011-07-15 16:25:15 +000011969 if (Op == OO_Subscript) {
11970 SourceLocation LBrace;
11971 SourceLocation RBrace;
11972
11973 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011974 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011975 LBrace = SourceLocation::getFromRawEncoding(
11976 NameLoc.CXXOperatorName.BeginOpNameLoc);
11977 RBrace = SourceLocation::getFromRawEncoding(
11978 NameLoc.CXXOperatorName.EndOpNameLoc);
11979 } else {
11980 LBrace = Callee->getLocStart();
11981 RBrace = OpLoc;
11982 }
11983
11984 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11985 First, Second);
11986 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011987
Douglas Gregora16548e2009-08-11 05:31:07 +000011988 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011989 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011990 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011991 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11992 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011994
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011995 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011996}
Mike Stump11289f42009-09-09 15:08:12 +000011997
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011998template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011999ExprResult
John McCallb268a282010-08-23 23:25:46 +000012000TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012001 SourceLocation OperatorLoc,
12002 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012003 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012004 TypeSourceInfo *ScopeType,
12005 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012006 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012007 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012008 QualType BaseType = Base->getType();
12009 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012010 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012011 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012012 !BaseType->getAs<PointerType>()->getPointeeType()
12013 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012014 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012015 return SemaRef.BuildPseudoDestructorExpr(
12016 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12017 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012018 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012019
Douglas Gregor678f90d2010-02-25 01:56:36 +000012020 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012021 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12022 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12023 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12024 NameInfo.setNamedTypeInfo(DestroyedType);
12025
Richard Smith8e4a3862012-05-15 06:15:11 +000012026 // The scope type is now known to be a valid nested name specifier
12027 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012028 if (ScopeType) {
12029 if (!ScopeType->getType()->getAs<TagType>()) {
12030 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12031 diag::err_expected_class_or_namespace)
12032 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12033 return ExprError();
12034 }
12035 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12036 CCLoc);
12037 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012038
Abramo Bagnara7945c982012-01-27 09:46:47 +000012039 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012040 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012041 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012042 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012043 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012044 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012045 /*TemplateArgs*/ nullptr,
12046 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012047}
12048
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012049template<typename Derived>
12050StmtResult
12051TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012052 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012053 CapturedDecl *CD = S->getCapturedDecl();
12054 unsigned NumParams = CD->getNumParams();
12055 unsigned ContextParamPos = CD->getContextParamPosition();
12056 SmallVector<Sema::CapturedParamNameType, 4> Params;
12057 for (unsigned I = 0; I < NumParams; ++I) {
12058 if (I != ContextParamPos) {
12059 Params.push_back(
12060 std::make_pair(
12061 CD->getParam(I)->getName(),
12062 getDerived().TransformType(CD->getParam(I)->getType())));
12063 } else {
12064 Params.push_back(std::make_pair(StringRef(), QualType()));
12065 }
12066 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012067 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012068 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012069 StmtResult Body;
12070 {
12071 Sema::CompoundScopeRAII CompoundScope(getSema());
12072 Body = getDerived().TransformStmt(S->getCapturedStmt());
12073 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012074
12075 if (Body.isInvalid()) {
12076 getSema().ActOnCapturedRegionError();
12077 return StmtError();
12078 }
12079
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012080 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012081}
12082
Douglas Gregord6ff3322009-08-04 16:50:30 +000012083} // end namespace clang
12084
Hans Wennborg59dbe862015-09-29 20:56:43 +000012085#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H