blob: 3b435731952f2f1a464f890d7f46d1b6ce32814d [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
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000610 SmallVectorImpl<QualType> &PTypes,
611 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000612
613 /// \brief Transforms a single function-type parameter. Return null
614 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 ///
616 /// \param indexAdjustment - A number to add to the parameter's
617 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000618 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000619 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000620 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000621 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000622
John McCall31f82722010-11-12 08:19:04 +0000623 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000624
John McCalldadc5752010-08-24 06:29:42 +0000625 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000693 /// \brief Build an Objective-C object type.
694 ///
695 /// By default, performs semantic analysis when building the object type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildObjCObjectType(QualType BaseType,
698 SourceLocation Loc,
699 SourceLocation TypeArgsLAngleLoc,
700 ArrayRef<TypeSourceInfo *> TypeArgs,
701 SourceLocation TypeArgsRAngleLoc,
702 SourceLocation ProtocolLAngleLoc,
703 ArrayRef<ObjCProtocolDecl *> Protocols,
704 ArrayRef<SourceLocation> ProtocolLocs,
705 SourceLocation ProtocolRAngleLoc);
706
707 /// \brief Build a new Objective-C object pointer type given the pointee type.
708 ///
709 /// By default, directly builds the pointer type, with no additional semantic
710 /// analysis.
711 QualType RebuildObjCObjectPointerType(QualType PointeeType,
712 SourceLocation Star);
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new array type given the element type, size
715 /// modifier, size of the array (if known), size expression, and index type
716 /// qualifiers.
717 ///
718 /// By default, performs semantic analysis when building the array type.
719 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 QualType RebuildArrayType(QualType ElementType,
722 ArrayType::ArraySizeModifier SizeMod,
723 const llvm::APInt *Size,
724 Expr *SizeExpr,
725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728 /// \brief Build a new constant array type given the element type, size
729 /// modifier, (known) size of the array, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
735 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new incomplete array type given the element type, size
740 /// modifier, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Mike Stump11289f42009-09-09 15:08:12 +0000749 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// size modifier, size expression, and index type qualifiers.
751 ///
752 /// By default, performs semantic analysis when building the array type.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000754 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 unsigned IndexTypeQuals,
758 SourceRange BracketsRange);
759
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 /// size modifier, size expression, and index type qualifiers.
762 ///
763 /// By default, performs semantic analysis when building the array type.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000765 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 unsigned IndexTypeQuals,
769 SourceRange BracketsRange);
770
771 /// \brief Build a new vector type given the element type and
772 /// number of elements.
773 ///
774 /// By default, performs semantic analysis when building the vector type.
775 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000776 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000777 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// \brief Build a new extended vector type given the element type and
780 /// number of elements.
781 ///
782 /// By default, performs semantic analysis when building the vector type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000786
787 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// given the element type and number of elements.
789 ///
790 /// By default, performs semantic analysis when building the vector type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new function type.
797 ///
798 /// By default, performs semantic analysis when building the function type.
799 /// Subclasses may override this routine to provide different behavior.
800 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000802 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000803
John McCall550e0c22009-10-21 00:40:46 +0000804 /// \brief Build a new unprototyped function type.
805 QualType RebuildFunctionNoProtoType(QualType ResultType);
806
John McCallb96ec562009-12-04 22:46:56 +0000807 /// \brief Rebuild an unresolved typename type, given the decl that
808 /// the UnresolvedUsingTypenameDecl was transformed to.
809 QualType RebuildUnresolvedUsingType(Decl *D);
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000812 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 return SemaRef.Context.getTypeDeclType(Typedef);
814 }
815
816 /// \brief Build a new class/struct/union type.
817 QualType RebuildRecordType(RecordDecl *Record) {
818 return SemaRef.Context.getTypeDeclType(Record);
819 }
820
821 /// \brief Build a new Enum type.
822 QualType RebuildEnumType(EnumDecl *Enum) {
823 return SemaRef.Context.getTypeDeclType(Enum);
824 }
John McCallfcc33b02009-09-05 00:15:47 +0000825
Mike Stump11289f42009-09-09 15:08:12 +0000826 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 ///
828 /// By default, performs semantic analysis when building the typeof type.
829 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000830 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831
Mike Stump11289f42009-09-09 15:08:12 +0000832 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 ///
834 /// By default, builds a new TypeOfType with the given underlying type.
835 QualType RebuildTypeOfType(QualType Underlying);
836
Alexis Hunte852b102011-05-24 22:41:36 +0000837 /// \brief Build a new unary transform type.
838 QualType RebuildUnaryTransformType(QualType BaseType,
839 UnaryTransformType::UTTKind UKind,
840 SourceLocation Loc);
841
Richard Smith74aeef52013-04-26 16:15:35 +0000842 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, performs semantic analysis when building the decltype type.
845 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000846 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000847
Richard Smith74aeef52013-04-26 16:15:35 +0000848 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000849 ///
850 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000851 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000852 // Note, IsDependent is always false here: we implicitly convert an 'auto'
853 // which has been deduced to a dependent type into an undeduced 'auto', so
854 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000855 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000856 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000857 }
858
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// \brief Build a new template specialization type.
860 ///
861 /// By default, performs semantic analysis when building the template
862 /// specialization type. Subclasses may override this routine to provide
863 /// different behavior.
864 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000865 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000866 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000868 /// \brief Build a new parenthesized type.
869 ///
870 /// By default, builds a new ParenType type from the inner type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildParenType(QualType InnerType) {
873 return SemaRef.Context.getParenType(InnerType);
874 }
875
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 /// \brief Build a new qualified name type.
877 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 /// By default, builds a new ElaboratedType type from the keyword,
879 /// the nested-name-specifier and the named type.
880 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000881 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
882 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 NestedNameSpecifierLoc QualifierLoc,
884 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000887 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889
890 /// \brief Build a new typename type that refers to a template-id.
891 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000892 /// By default, builds a new DependentNameType type from the
893 /// nested-name-specifier and the given type. Subclasses may override
894 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000895 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 ElaboratedTypeKeyword Keyword,
897 NestedNameSpecifierLoc QualifierLoc,
898 const IdentifierInfo *Name,
899 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000900 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000901 // Rebuild the template name.
902 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000903 CXXScopeSpec SS;
904 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000905 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000906 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000908
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 if (InstName.isNull())
910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000911
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 // If it's still dependent, make a dependent specialization.
913 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915 QualifierLoc.getNestedNameSpecifier(),
916 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000917 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 // Otherwise, make an elaborated type wrapping a non-dependent
920 // specialization.
921 QualType T =
922 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000924
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000930 T);
931 }
932
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// \brief Build a new typename type that refers to an identifier.
934 ///
935 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000936 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000937 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 NestedNameSpecifierLoc QualifierLoc,
941 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000944 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 // If the name is still dependent, just build a new dependent name type.
948 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000949 return SemaRef.Context.getDependentNameType(Keyword,
950 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 }
953
Abramo Bagnara6150c882010-05-11 21:36:43 +0000954 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000956 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957
958 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
959
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 // into a non-dependent elaborated-type-specifier. Find the tag we're
962 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965 if (!DC)
966 return QualType();
967
John McCallbf8c5192010-05-27 06:40:31 +0000968 if (SemaRef.RequireCompleteDeclContext(SS, DC))
969 return QualType();
970
Craig Topperc3ec1492014-05-26 06:22:03 +0000971 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.LookupQualifiedName(Result, DC);
973 switch (Result.getResultKind()) {
974 case LookupResult::NotFound:
975 case LookupResult::NotFoundInCurrentInstantiation:
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::Found:
979 Tag = Result.getAsSingle<TagDecl>();
980 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::FoundOverloaded:
983 case LookupResult::FoundUnresolvedValue:
984 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000985
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 case LookupResult::Ambiguous:
987 // Let the LookupResult structure handle ambiguities.
988 return QualType();
989 }
990
991 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000992 // Check where the name exists but isn't a tag type and use that to emit
993 // better diagnostics.
994 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995 SemaRef.LookupQualifiedName(Result, DC);
996 switch (Result.getResultKind()) {
997 case LookupResult::Found:
998 case LookupResult::FoundOverloaded:
999 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001000 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 unsigned Kind = 0;
1002 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001003 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001008 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001009 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001011 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 break;
1013 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001014 return QualType();
1015 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001016
Richard Trieucaa33d32011-06-10 03:11:26 +00001017 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001018 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001020 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021 return QualType();
1022 }
1023
1024 // Build the elaborated-type-specifier type.
1025 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001026 return SemaRef.Context.getElaboratedType(Keyword,
1027 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 /// \brief Build a new pack expansion type.
1032 ///
1033 /// By default, builds a new PackExpansionType type from the given pattern.
1034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001037 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001038 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 }
1042
Eli Friedman0dfb8892011-10-06 23:00:33 +00001043 /// \brief Build a new atomic type given its value type.
1044 ///
1045 /// By default, performs semantic analysis when building the atomic type.
1046 /// Subclasses may override this routine to provide different behavior.
1047 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048
Xiuli Pan9c14e282016-01-09 12:53:17 +00001049 /// \brief Build a new pipe type given its value type.
1050 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1051
Douglas Gregor71dc5092009-08-06 06:41:21 +00001052 /// \brief Build a new template name given a nested name specifier, a flag
1053 /// indicating whether the "template" keyword was provided, and the template
1054 /// that the template name refers to.
1055 ///
1056 /// By default, builds the new template name directly. Subclasses may override
1057 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001058 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001059 bool TemplateKW,
1060 TemplateDecl *Template);
1061
Douglas Gregor71dc5092009-08-06 06:41:21 +00001062 /// \brief Build a new template name given a nested name specifier and the
1063 /// name that is referred to as a template.
1064 ///
1065 /// By default, performs semantic analysis to determine whether the name can
1066 /// be resolved to a specific template, then builds the appropriate kind of
1067 /// template name. Subclasses may override this routine to provide different
1068 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001069 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1070 const IdentifierInfo &Name,
1071 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001072 QualType ObjectType,
1073 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregor71395fa2009-11-04 00:56:37 +00001075 /// \brief Build a new template name given a nested name specifier and the
1076 /// overloaded operator name that is referred to as a template.
1077 ///
1078 /// By default, performs semantic analysis to determine whether the name can
1079 /// be resolved to a specific template, then builds the appropriate kind of
1080 /// template name. Subclasses may override this routine to provide different
1081 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001082 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001083 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001084 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001085 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001086
1087 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001088 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001089 ///
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.
1094 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1095 const TemplateArgument &ArgPack) {
1096 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1097 }
1098
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 /// \brief Build a new compound statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001103 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 MultiStmtArg Statements,
1105 SourceLocation RBraceLoc,
1106 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001107 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001108 IsStmtExpr);
1109 }
1110
1111 /// \brief Build a new case 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001116 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001117 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001118 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001120 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 ColonLoc);
1122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Douglas Gregorebe10102009-08-20 07:17:43 +00001124 /// \brief Attach the body to a new case statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001129 getSema().ActOnCaseStmtBody(S, Body);
1130 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 }
Mike Stump11289f42009-09-09 15:08:12 +00001132
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 /// \brief Build a new default statement.
1134 ///
1135 /// By default, performs semantic analysis to build the new statement.
1136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001137 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001138 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001139 Stmt *SubStmt) {
1140 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001141 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 }
Mike Stump11289f42009-09-09 15:08:12 +00001143
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 /// \brief Build a new label statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001148 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1149 SourceLocation ColonLoc, Stmt *SubStmt) {
1150 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 }
Mike Stump11289f42009-09-09 15:08:12 +00001152
Richard Smithc202b282012-04-14 00:33:13 +00001153 /// \brief Build a new label statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001157 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1158 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001159 Stmt *SubStmt) {
1160 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1161 }
1162
Douglas Gregorebe10102009-08-20 07:17:43 +00001163 /// \brief Build a new "if" statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001167 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001168 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001169 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001170 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 /// \brief Start building a new switch statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001177 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001178 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001179 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001180 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 /// \brief Attach the body to the switch statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001188 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
1191
1192 /// \brief Build a new while statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001196 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1197 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001198 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 }
Mike Stump11289f42009-09-09 15:08:12 +00001200
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 /// \brief Build a new do-while statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001205 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001206 SourceLocation WhileLoc, SourceLocation LParenLoc,
1207 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001208 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1209 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 }
1211
1212 /// \brief Build a new for statement.
1213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001216 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001217 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 VarDecl *CondVar, Sema::FullExprArg Inc,
1219 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001220 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001221 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 }
Mike Stump11289f42009-09-09 15:08:12 +00001223
Douglas Gregorebe10102009-08-20 07:17:43 +00001224 /// \brief Build a new goto 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 RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1229 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001230 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 }
1232
1233 /// \brief Build a new indirect goto statement.
1234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001237 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001238 SourceLocation StarLoc,
1239 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001240 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 /// \brief Build a new return statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001247 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001248 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 /// \brief Build a new declaration statement.
1252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001255 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001256 SourceLocation StartLoc, SourceLocation EndLoc) {
1257 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001258 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Anders Carlssonaaeef072010-01-24 05:50:09 +00001261 /// \brief Build a new inline asm statement.
1262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001265 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1266 bool IsVolatile, unsigned NumOutputs,
1267 unsigned NumInputs, IdentifierInfo **Names,
1268 MultiExprArg Constraints, MultiExprArg Exprs,
1269 Expr *AsmString, MultiExprArg Clobbers,
1270 SourceLocation RParenLoc) {
1271 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1272 NumInputs, Names, Constraints, Exprs,
1273 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001274 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001275
Chad Rosier32503022012-06-11 20:47:18 +00001276 /// \brief Build a new MS style inline asm statement.
1277 ///
1278 /// By default, performs semantic analysis to build the new statement.
1279 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001280 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001281 ArrayRef<Token> AsmToks,
1282 StringRef AsmString,
1283 unsigned NumOutputs, unsigned NumInputs,
1284 ArrayRef<StringRef> Constraints,
1285 ArrayRef<StringRef> Clobbers,
1286 ArrayRef<Expr*> Exprs,
1287 SourceLocation EndLoc) {
1288 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1289 NumOutputs, NumInputs,
1290 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001291 }
1292
Richard Smith9f690bd2015-10-27 06:02:45 +00001293 /// \brief Build a new co_return statement.
1294 ///
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
1297 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1298 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1299 }
1300
1301 /// \brief Build a new co_await expression.
1302 ///
1303 /// By default, performs semantic analysis to build the new expression.
1304 /// Subclasses may override this routine to provide different behavior.
1305 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1306 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1307 }
1308
1309 /// \brief Build a new co_yield expression.
1310 ///
1311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1314 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1315 }
1316
James Dennett2a4d13c2012-06-15 07:13:21 +00001317 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001318 ///
1319 /// By default, performs semantic analysis to build the new statement.
1320 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001321 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001322 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001323 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001324 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001325 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001326 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001327 }
1328
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001329 /// \brief Rebuild an Objective-C exception declaration.
1330 ///
1331 /// By default, performs semantic analysis to build the new declaration.
1332 /// Subclasses may override this routine to provide different behavior.
1333 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1334 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001335 return getSema().BuildObjCExceptionDecl(TInfo, T,
1336 ExceptionDecl->getInnerLocStart(),
1337 ExceptionDecl->getLocation(),
1338 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001339 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001340
James Dennett2a4d13c2012-06-15 07:13:21 +00001341 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001346 SourceLocation RParenLoc,
1347 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001348 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001349 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001350 Var, Body);
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 \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +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 RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Stmt *Body) {
1359 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001361
James Dennett2a4d13c2012-06-15 07:13:21 +00001362 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001366 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001367 Expr *Operand) {
1368 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001370
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001371 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001375 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001376 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001377 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001378 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001379 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001380 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001381 return getSema().ActOnOpenMPExecutableDirective(
1382 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001383 }
1384
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001385 /// \brief Build a new OpenMP 'if' clause.
1386 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001387 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001388 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001389 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1390 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001391 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001392 SourceLocation NameModifierLoc,
1393 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001394 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001395 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1396 LParenLoc, NameModifierLoc, ColonLoc,
1397 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001398 }
1399
Alexey Bataev3778b602014-07-17 07:32:53 +00001400 /// \brief Build a new OpenMP 'final' clause.
1401 ///
1402 /// By default, performs semantic analysis to build the new OpenMP clause.
1403 /// Subclasses may override this routine to provide different behavior.
1404 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1405 SourceLocation LParenLoc,
1406 SourceLocation EndLoc) {
1407 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1408 EndLoc);
1409 }
1410
Alexey Bataev568a8332014-03-06 06:15:19 +00001411 /// \brief Build a new OpenMP 'num_threads' clause.
1412 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001413 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001414 /// Subclasses may override this routine to provide different behavior.
1415 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1416 SourceLocation StartLoc,
1417 SourceLocation LParenLoc,
1418 SourceLocation EndLoc) {
1419 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1420 LParenLoc, EndLoc);
1421 }
1422
Alexey Bataev62c87d22014-03-21 04:51:18 +00001423 /// \brief Build a new OpenMP 'safelen' clause.
1424 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001425 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001426 /// Subclasses may override this routine to provide different behavior.
1427 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1428 SourceLocation LParenLoc,
1429 SourceLocation EndLoc) {
1430 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1431 }
1432
Alexey Bataev66b15b52015-08-21 11:14:16 +00001433 /// \brief Build a new OpenMP 'simdlen' clause.
1434 ///
1435 /// By default, performs semantic analysis to build the new OpenMP clause.
1436 /// Subclasses may override this routine to provide different behavior.
1437 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1438 SourceLocation LParenLoc,
1439 SourceLocation EndLoc) {
1440 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1441 }
1442
Alexander Musman8bd31e62014-05-27 15:12:19 +00001443 /// \brief Build a new OpenMP 'collapse' clause.
1444 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001445 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001446 /// Subclasses may override this routine to provide different behavior.
1447 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1448 SourceLocation LParenLoc,
1449 SourceLocation EndLoc) {
1450 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1451 EndLoc);
1452 }
1453
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001454 /// \brief Build a new OpenMP 'default' clause.
1455 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001456 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001457 /// Subclasses may override this routine to provide different behavior.
1458 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1459 SourceLocation KindKwLoc,
1460 SourceLocation StartLoc,
1461 SourceLocation LParenLoc,
1462 SourceLocation EndLoc) {
1463 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1464 StartLoc, LParenLoc, EndLoc);
1465 }
1466
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001467 /// \brief Build a new OpenMP 'proc_bind' clause.
1468 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001469 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001470 /// Subclasses may override this routine to provide different behavior.
1471 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1472 SourceLocation KindKwLoc,
1473 SourceLocation StartLoc,
1474 SourceLocation LParenLoc,
1475 SourceLocation EndLoc) {
1476 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1477 StartLoc, LParenLoc, EndLoc);
1478 }
1479
Alexey Bataev56dafe82014-06-20 07:16:17 +00001480 /// \brief Build a new OpenMP 'schedule' clause.
1481 ///
1482 /// By default, performs semantic analysis to build the new OpenMP clause.
1483 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001484 OMPClause *RebuildOMPScheduleClause(
1485 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1486 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1487 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1488 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001489 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001490 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1491 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001492 }
1493
Alexey Bataev10e775f2015-07-30 11:36:16 +00001494 /// \brief Build a new OpenMP 'ordered' clause.
1495 ///
1496 /// By default, performs semantic analysis to build the new OpenMP clause.
1497 /// Subclasses may override this routine to provide different behavior.
1498 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1499 SourceLocation EndLoc,
1500 SourceLocation LParenLoc, Expr *Num) {
1501 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1502 }
1503
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001504 /// \brief Build a new OpenMP 'private' clause.
1505 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001506 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001507 /// Subclasses may override this routine to provide different behavior.
1508 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1509 SourceLocation StartLoc,
1510 SourceLocation LParenLoc,
1511 SourceLocation EndLoc) {
1512 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1513 EndLoc);
1514 }
1515
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001516 /// \brief Build a new OpenMP 'firstprivate' clause.
1517 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001518 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001519 /// Subclasses may override this routine to provide different behavior.
1520 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1521 SourceLocation StartLoc,
1522 SourceLocation LParenLoc,
1523 SourceLocation EndLoc) {
1524 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1525 EndLoc);
1526 }
1527
Alexander Musman1bb328c2014-06-04 13:06:39 +00001528 /// \brief Build a new OpenMP 'lastprivate' clause.
1529 ///
1530 /// By default, performs semantic analysis to build the new OpenMP clause.
1531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1533 SourceLocation StartLoc,
1534 SourceLocation LParenLoc,
1535 SourceLocation EndLoc) {
1536 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1537 EndLoc);
1538 }
1539
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001540 /// \brief Build a new OpenMP 'shared' clause.
1541 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001542 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001543 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001544 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1549 EndLoc);
1550 }
1551
Alexey Bataevc5e02582014-06-16 07:08:35 +00001552 /// \brief Build a new OpenMP 'reduction' clause.
1553 ///
1554 /// By default, performs semantic analysis to build the new statement.
1555 /// Subclasses may override this routine to provide different behavior.
1556 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1557 SourceLocation StartLoc,
1558 SourceLocation LParenLoc,
1559 SourceLocation ColonLoc,
1560 SourceLocation EndLoc,
1561 CXXScopeSpec &ReductionIdScopeSpec,
1562 const DeclarationNameInfo &ReductionId) {
1563 return getSema().ActOnOpenMPReductionClause(
1564 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1565 ReductionId);
1566 }
1567
Alexander Musman8dba6642014-04-22 13:09:42 +00001568 /// \brief Build a new OpenMP 'linear' clause.
1569 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001570 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001571 /// Subclasses may override this routine to provide different behavior.
1572 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1573 SourceLocation StartLoc,
1574 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001575 OpenMPLinearClauseKind Modifier,
1576 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001577 SourceLocation ColonLoc,
1578 SourceLocation EndLoc) {
1579 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001580 Modifier, ModifierLoc, ColonLoc,
1581 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001582 }
1583
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001584 /// \brief Build a new OpenMP 'aligned' clause.
1585 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001586 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001587 /// Subclasses may override this routine to provide different behavior.
1588 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1589 SourceLocation StartLoc,
1590 SourceLocation LParenLoc,
1591 SourceLocation ColonLoc,
1592 SourceLocation EndLoc) {
1593 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1594 LParenLoc, ColonLoc, EndLoc);
1595 }
1596
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001597 /// \brief Build a new OpenMP 'copyin' clause.
1598 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001599 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001600 /// Subclasses may override this routine to provide different behavior.
1601 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1602 SourceLocation StartLoc,
1603 SourceLocation LParenLoc,
1604 SourceLocation EndLoc) {
1605 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1606 EndLoc);
1607 }
1608
Alexey Bataevbae9a792014-06-27 10:37:06 +00001609 /// \brief Build a new OpenMP 'copyprivate' clause.
1610 ///
1611 /// By default, performs semantic analysis to build the new OpenMP clause.
1612 /// Subclasses may override this routine to provide different behavior.
1613 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1614 SourceLocation StartLoc,
1615 SourceLocation LParenLoc,
1616 SourceLocation EndLoc) {
1617 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1618 EndLoc);
1619 }
1620
Alexey Bataev6125da92014-07-21 11:26:11 +00001621 /// \brief Build a new OpenMP 'flush' pseudo clause.
1622 ///
1623 /// By default, performs semantic analysis to build the new OpenMP clause.
1624 /// Subclasses may override this routine to provide different behavior.
1625 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1626 SourceLocation StartLoc,
1627 SourceLocation LParenLoc,
1628 SourceLocation EndLoc) {
1629 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1630 EndLoc);
1631 }
1632
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001633 /// \brief Build a new OpenMP 'depend' pseudo clause.
1634 ///
1635 /// By default, performs semantic analysis to build the new OpenMP clause.
1636 /// Subclasses may override this routine to provide different behavior.
1637 OMPClause *
1638 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1639 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1640 SourceLocation StartLoc, SourceLocation LParenLoc,
1641 SourceLocation EndLoc) {
1642 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1643 StartLoc, LParenLoc, EndLoc);
1644 }
1645
Michael Wonge710d542015-08-07 16:16:36 +00001646 /// \brief Build a new OpenMP 'device' clause.
1647 ///
1648 /// By default, performs semantic analysis to build the new statement.
1649 /// Subclasses may override this routine to provide different behavior.
1650 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1651 SourceLocation LParenLoc,
1652 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001653 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001654 EndLoc);
1655 }
1656
Kelvin Li0bff7af2015-11-23 05:32:03 +00001657 /// \brief Build a new OpenMP 'map' clause.
1658 ///
1659 /// By default, performs semantic analysis to build the new OpenMP clause.
1660 /// Subclasses may override this routine to provide different behavior.
1661 OMPClause *RebuildOMPMapClause(
1662 OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType,
1663 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1664 SourceLocation StartLoc, SourceLocation LParenLoc,
1665 SourceLocation EndLoc) {
1666 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, MapLoc,
1667 ColonLoc, VarList,StartLoc,
1668 LParenLoc, EndLoc);
1669 }
1670
Kelvin Li099bb8c2015-11-24 20:50:12 +00001671 /// \brief Build a new OpenMP 'num_teams' clause.
1672 ///
1673 /// By default, performs semantic analysis to build the new statement.
1674 /// Subclasses may override this routine to provide different behavior.
1675 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1676 SourceLocation LParenLoc,
1677 SourceLocation EndLoc) {
1678 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1679 EndLoc);
1680 }
1681
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001682 /// \brief Build a new OpenMP 'thread_limit' clause.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
1686 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1687 SourceLocation StartLoc,
1688 SourceLocation LParenLoc,
1689 SourceLocation EndLoc) {
1690 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1691 LParenLoc, EndLoc);
1692 }
1693
Alexey Bataeva0569352015-12-01 10:17:31 +00001694 /// \brief Build a new OpenMP 'priority' clause.
1695 ///
1696 /// By default, performs semantic analysis to build the new statement.
1697 /// Subclasses may override this routine to provide different behavior.
1698 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1699 SourceLocation LParenLoc,
1700 SourceLocation EndLoc) {
1701 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1702 EndLoc);
1703 }
1704
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001705 /// \brief Build a new OpenMP 'grainsize' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new statement.
1708 /// Subclasses may override this routine to provide different behavior.
1709 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1710 SourceLocation LParenLoc,
1711 SourceLocation EndLoc) {
1712 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1713 EndLoc);
1714 }
1715
Alexey Bataev382967a2015-12-08 12:06:20 +00001716 /// \brief Build a new OpenMP 'num_tasks' clause.
1717 ///
1718 /// By default, performs semantic analysis to build the new statement.
1719 /// Subclasses may override this routine to provide different behavior.
1720 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1721 SourceLocation LParenLoc,
1722 SourceLocation EndLoc) {
1723 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1724 EndLoc);
1725 }
1726
Alexey Bataev28c75412015-12-15 08:19:24 +00001727 /// \brief Build a new OpenMP 'hint' clause.
1728 ///
1729 /// By default, performs semantic analysis to build the new statement.
1730 /// Subclasses may override this routine to provide different behavior.
1731 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1735 }
1736
Carlo Bertollib4adf552016-01-15 18:50:31 +00001737 /// \brief Build a new OpenMP 'dist_schedule' clause.
1738 ///
1739 /// By default, performs semantic analysis to build the new OpenMP clause.
1740 /// Subclasses may override this routine to provide different behavior.
1741 OMPClause *
1742 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1743 Expr *ChunkSize, SourceLocation StartLoc,
1744 SourceLocation LParenLoc, SourceLocation KindLoc,
1745 SourceLocation CommaLoc, SourceLocation EndLoc) {
1746 return getSema().ActOnOpenMPDistScheduleClause(
1747 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1748 }
1749
James Dennett2a4d13c2012-06-15 07:13:21 +00001750 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001751 ///
1752 /// By default, performs semantic analysis to build the new statement.
1753 /// Subclasses may override this routine to provide different behavior.
1754 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1755 Expr *object) {
1756 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1757 }
1758
James Dennett2a4d13c2012-06-15 07:13:21 +00001759 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001760 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001761 /// By default, performs semantic analysis to build the new statement.
1762 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001763 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001764 Expr *Object, Stmt *Body) {
1765 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001766 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001767
James Dennett2a4d13c2012-06-15 07:13:21 +00001768 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001769 ///
1770 /// By default, performs semantic analysis to build the new statement.
1771 /// Subclasses may override this routine to provide different behavior.
1772 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1773 Stmt *Body) {
1774 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1775 }
John McCall53848232011-07-27 01:07:15 +00001776
Douglas Gregorf68a5082010-04-22 23:10:45 +00001777 /// \brief Build a new Objective-C fast enumeration statement.
1778 ///
1779 /// By default, performs semantic analysis to build the new statement.
1780 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001781 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001782 Stmt *Element,
1783 Expr *Collection,
1784 SourceLocation RParenLoc,
1785 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001786 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001787 Element,
John McCallb268a282010-08-23 23:25:46 +00001788 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001789 RParenLoc);
1790 if (ForEachStmt.isInvalid())
1791 return StmtError();
1792
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001793 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001794 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001795
Douglas Gregorebe10102009-08-20 07:17:43 +00001796 /// \brief Build a new C++ exception declaration.
1797 ///
1798 /// By default, performs semantic analysis to build the new decaration.
1799 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001800 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001801 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001802 SourceLocation StartLoc,
1803 SourceLocation IdLoc,
1804 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001805 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001806 StartLoc, IdLoc, Id);
1807 if (Var)
1808 getSema().CurContext->addDecl(Var);
1809 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001810 }
1811
1812 /// \brief Build a new C++ catch statement.
1813 ///
1814 /// By default, performs semantic analysis to build the new statement.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001817 VarDecl *ExceptionDecl,
1818 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001819 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1820 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001821 }
Mike Stump11289f42009-09-09 15:08:12 +00001822
Douglas Gregorebe10102009-08-20 07:17:43 +00001823 /// \brief Build a new C++ try statement.
1824 ///
1825 /// By default, performs semantic analysis to build the new statement.
1826 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001827 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1828 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001829 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001830 }
Mike Stump11289f42009-09-09 15:08:12 +00001831
Richard Smith02e85f32011-04-14 22:09:26 +00001832 /// \brief Build a new C++0x range-based for statement.
1833 ///
1834 /// By default, performs semantic analysis to build the new statement.
1835 /// Subclasses may override this routine to provide different behavior.
1836 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001837 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001838 SourceLocation ColonLoc,
1839 Stmt *Range, Stmt *BeginEnd,
1840 Expr *Cond, Expr *Inc,
1841 Stmt *LoopVar,
1842 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001843 // If we've just learned that the range is actually an Objective-C
1844 // collection, treat this as an Objective-C fast enumeration loop.
1845 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1846 if (RangeStmt->isSingleDecl()) {
1847 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001848 if (RangeVar->isInvalidDecl())
1849 return StmtError();
1850
Douglas Gregorf7106af2013-04-08 18:40:13 +00001851 Expr *RangeExpr = RangeVar->getInit();
1852 if (!RangeExpr->isTypeDependent() &&
1853 RangeExpr->getType()->isObjCObjectPointerType())
1854 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1855 RParenLoc);
1856 }
1857 }
1858 }
1859
Richard Smithcfd53b42015-10-22 06:13:50 +00001860 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1861 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001862 Cond, Inc, LoopVar, RParenLoc,
1863 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001864 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001865
1866 /// \brief Build a new C++0x range-based for statement.
1867 ///
1868 /// By default, performs semantic analysis to build the new statement.
1869 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001870 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001871 bool IsIfExists,
1872 NestedNameSpecifierLoc QualifierLoc,
1873 DeclarationNameInfo NameInfo,
1874 Stmt *Nested) {
1875 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1876 QualifierLoc, NameInfo, Nested);
1877 }
1878
Richard Smith02e85f32011-04-14 22:09:26 +00001879 /// \brief Attach body to a C++0x range-based for statement.
1880 ///
1881 /// By default, performs semantic analysis to finish the new statement.
1882 /// Subclasses may override this routine to provide different behavior.
1883 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1884 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1885 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001886
David Majnemerfad8f482013-10-15 09:33:02 +00001887 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001888 Stmt *TryBlock, Stmt *Handler) {
1889 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001890 }
1891
David Majnemerfad8f482013-10-15 09:33:02 +00001892 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001893 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001894 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001895 }
1896
David Majnemerfad8f482013-10-15 09:33:02 +00001897 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001898 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001899 }
1900
Alexey Bataevec474782014-10-09 08:45:04 +00001901 /// \brief Build a new predefined expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
1905 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1906 PredefinedExpr::IdentType IT) {
1907 return getSema().BuildPredefinedExpr(Loc, IT);
1908 }
1909
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 /// \brief Build a new expression that references a declaration.
1911 ///
1912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001914 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001915 LookupResult &R,
1916 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001917 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1918 }
1919
1920
1921 /// \brief Build a new expression that references a declaration.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001925 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001926 ValueDecl *VD,
1927 const DeclarationNameInfo &NameInfo,
1928 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001929 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001930 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001931
1932 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001933
1934 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 }
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001938 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001943 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 }
1945
Douglas Gregorad8a3362009-09-04 17:36:40 +00001946 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001947 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001950 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001951 SourceLocation OperatorLoc,
1952 bool isArrow,
1953 CXXScopeSpec &SS,
1954 TypeSourceInfo *ScopeType,
1955 SourceLocation CCLoc,
1956 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001957 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001960 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001964 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001965 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001966 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 }
Mike Stump11289f42009-09-09 15:08:12 +00001968
Douglas Gregor882211c2010-04-28 22:16:22 +00001969 /// \brief Build a new builtin offsetof expression.
1970 ///
1971 /// By default, performs semantic analysis to build the new expression.
1972 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001973 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001974 TypeSourceInfo *Type,
1975 ArrayRef<Sema::OffsetOfComponent> Components,
1976 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001977 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001978 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001980
1981 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001982 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001983 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001986 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1987 SourceLocation OpLoc,
1988 UnaryExprOrTypeTrait ExprKind,
1989 SourceRange R) {
1990 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
1992
Peter Collingbournee190dee2011-03-11 19:24:49 +00001993 /// \brief Build a new sizeof, alignof or vec step expression with an
1994 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001995 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001998 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1999 UnaryExprOrTypeTrait ExprKind,
2000 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002002 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002005
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002006 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002013 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002015 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002017 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002018 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 RBracketLoc);
2020 }
2021
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002022 /// \brief Build a new array section expression.
2023 ///
2024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
2026 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2027 Expr *LowerBound,
2028 SourceLocation ColonLoc, Expr *Length,
2029 SourceLocation RBracketLoc) {
2030 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2031 ColonLoc, Length, RBracketLoc);
2032 }
2033
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002035 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002038 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002040 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002041 Expr *ExecConfig = nullptr) {
2042 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002043 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 }
2045
2046 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002047 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002050 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002051 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002052 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002053 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002054 const DeclarationNameInfo &MemberNameInfo,
2055 ValueDecl *Member,
2056 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002057 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002058 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002059 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2060 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002061 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002062 // We have a reference to an unnamed field. This is always the
2063 // base of an anonymous struct/union member access, i.e. the
2064 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002065 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002066 assert(Member->getType()->isRecordType() &&
2067 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002068
Richard Smithcab9a7d2011-10-26 19:06:56 +00002069 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002070 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002071 QualifierLoc.getNestedNameSpecifier(),
2072 FoundDecl, Member);
2073 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002074 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002075 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002076 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002077 MemberExpr *ME = new (getSema().Context)
2078 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2079 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002080 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002081 }
Mike Stump11289f42009-09-09 15:08:12 +00002082
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002083 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002084 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002085
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002086 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002087 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002088
John McCall16df1e52010-03-30 21:47:33 +00002089 // FIXME: this involves duplicating earlier analysis in a lot of
2090 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002091 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002092 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002093 R.resolveKind();
2094
John McCallb268a282010-08-23 23:25:46 +00002095 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002096 SS, TemplateKWLoc,
2097 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002098 R, ExplicitTemplateArgs,
2099 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 }
Mike Stump11289f42009-09-09 15:08:12 +00002101
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002106 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002107 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002108 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002109 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 }
2111
2112 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002113 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// By default, performs semantic analysis to build the new expression.
2115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002116 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002117 SourceLocation QuestionLoc,
2118 Expr *LHS,
2119 SourceLocation ColonLoc,
2120 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002121 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2122 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 }
2124
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002126 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002129 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002130 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002132 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002133 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002134 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 }
Mike Stump11289f42009-09-09 15:08:12 +00002136
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002138 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 /// By default, performs semantic analysis to build the new expression.
2140 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002141 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002142 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002144 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002145 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002146 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
Douglas Gregora16548e2009-08-11 05:31:07 +00002149 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002150 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 SourceLocation OpLoc,
2155 SourceLocation AccessorLoc,
2156 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002157
John McCall10eae182009-11-30 22:42:35 +00002158 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002159 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002160 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002161 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002162 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002163 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002164 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002165 /* TemplateArgs */ nullptr,
2166 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 }
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002170 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002174 MultiExprArg Inits,
2175 SourceLocation RBraceLoc,
2176 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002178 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002179 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002180 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002181
Douglas Gregord3d93062009-11-09 17:16:50 +00002182 // Patch in the result type we were given, which may have been computed
2183 // when the initial InitListExpr was built.
2184 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2185 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002186 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 }
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002190 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 /// By default, performs semantic analysis to build the new expression.
2192 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002193 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 MultiExprArg ArrayExprs,
2195 SourceLocation EqualOrColonLoc,
2196 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002197 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002198 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002200 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002203
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002204 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 }
Mike Stump11289f42009-09-09 15:08:12 +00002206
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002208 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 /// By default, builds the implicit value initialization without performing
2210 /// any semantic analysis. Subclasses may override this routine to provide
2211 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002212 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002213 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 }
Mike Stump11289f42009-09-09 15:08:12 +00002215
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002217 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002220 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002221 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002222 SourceLocation RParenLoc) {
2223 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002224 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002225 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 }
2227
2228 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002229 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002232 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002233 MultiExprArg SubExprs,
2234 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002235 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 }
Mike Stump11289f42009-09-09 15:08:12 +00002237
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002239 ///
2240 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 /// rather than attempting to map the label statement itself.
2242 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002243 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002244 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002245 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 }
Mike Stump11289f42009-09-09 15:08:12 +00002247
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002249 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002252 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002253 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002255 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 }
Mike Stump11289f42009-09-09 15:08:12 +00002257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new __builtin_choose_expr expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002262 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002263 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 SourceLocation RParenLoc) {
2265 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002266 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 RParenLoc);
2268 }
Mike Stump11289f42009-09-09 15:08:12 +00002269
Peter Collingbourne91147592011-04-15 00:35:48 +00002270 /// \brief Build a new generic selection expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
2274 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2275 SourceLocation DefaultLoc,
2276 SourceLocation RParenLoc,
2277 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002278 ArrayRef<TypeSourceInfo *> Types,
2279 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002280 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002281 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002282 }
2283
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 /// \brief Build a new overloaded operator call expression.
2285 ///
2286 /// By default, performs semantic analysis to build the new expression.
2287 /// The semantic analysis provides the behavior of template instantiation,
2288 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002289 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 /// argument-dependent lookup, etc. Subclasses may override this routine to
2291 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002292 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002294 Expr *Callee,
2295 Expr *First,
2296 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002297
2298 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// reinterpret_cast.
2300 ///
2301 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002302 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002304 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 Stmt::StmtClass Class,
2306 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002307 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 SourceLocation RAngleLoc,
2309 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002310 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 SourceLocation RParenLoc) {
2312 switch (Class) {
2313 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002314 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002315 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002316 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002317
2318 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002319 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002320 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002321 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002324 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002325 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002326 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002330 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002331 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002332 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002333
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002335 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 }
Mike Stump11289f42009-09-09 15:08:12 +00002338
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 /// \brief Build a new C++ static_cast expression.
2340 ///
2341 /// By default, performs semantic analysis to build the new expression.
2342 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002343 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002345 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 SourceLocation RAngleLoc,
2347 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002348 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002350 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002351 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002352 SourceRange(LAngleLoc, RAngleLoc),
2353 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 }
2355
2356 /// \brief Build a new C++ dynamic_cast expression.
2357 ///
2358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002360 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002362 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 SourceLocation RAngleLoc,
2364 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002365 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002367 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002368 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002369 SourceRange(LAngleLoc, RAngleLoc),
2370 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 }
2372
2373 /// \brief Build a new C++ reinterpret_cast expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002379 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 SourceLocation RAngleLoc,
2381 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002382 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002384 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002385 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002386 SourceRange(LAngleLoc, RAngleLoc),
2387 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 }
2389
2390 /// \brief Build a new C++ const_cast expression.
2391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002394 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002396 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 SourceLocation RAngleLoc,
2398 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002399 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002401 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002402 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002403 SourceRange(LAngleLoc, RAngleLoc),
2404 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 }
Mike Stump11289f42009-09-09 15:08:12 +00002406
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 /// \brief Build a new C++ functional-style cast expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002411 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2412 SourceLocation LParenLoc,
2413 Expr *Sub,
2414 SourceLocation RParenLoc) {
2415 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002416 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 RParenLoc);
2418 }
Mike Stump11289f42009-09-09 15:08:12 +00002419
Douglas Gregora16548e2009-08-11 05:31:07 +00002420 /// \brief Build a new C++ typeid(type) expression.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002424 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002425 SourceLocation TypeidLoc,
2426 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002428 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002429 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 }
Mike Stump11289f42009-09-09 15:08:12 +00002431
Francois Pichet9f4f2072010-09-08 12:20:18 +00002432
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 /// \brief Build a new C++ typeid(expr) expression.
2434 ///
2435 /// By default, performs semantic analysis to build the new expression.
2436 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002437 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002438 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002439 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002441 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002442 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002443 }
2444
Francois Pichet9f4f2072010-09-08 12:20:18 +00002445 /// \brief Build a new C++ __uuidof(type) expression.
2446 ///
2447 /// By default, performs semantic analysis to build the new expression.
2448 /// Subclasses may override this routine to provide different behavior.
2449 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2450 SourceLocation TypeidLoc,
2451 TypeSourceInfo *Operand,
2452 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002453 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002454 RParenLoc);
2455 }
2456
2457 /// \brief Build a new C++ __uuidof(expr) expression.
2458 ///
2459 /// By default, performs semantic analysis to build the new expression.
2460 /// Subclasses may override this routine to provide different behavior.
2461 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2462 SourceLocation TypeidLoc,
2463 Expr *Operand,
2464 SourceLocation RParenLoc) {
2465 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2466 RParenLoc);
2467 }
2468
Douglas Gregora16548e2009-08-11 05:31:07 +00002469 /// \brief Build a new C++ "this" expression.
2470 ///
2471 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002472 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002474 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002475 QualType ThisType,
2476 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002477 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002478 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002479 }
2480
2481 /// \brief Build a new C++ throw expression.
2482 ///
2483 /// By default, performs semantic analysis to build the new expression.
2484 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002485 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2486 bool IsThrownVariableInScope) {
2487 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 }
2489
2490 /// \brief Build a new C++ default-argument expression.
2491 ///
2492 /// By default, builds a new default-argument expression, which does not
2493 /// require any semantic analysis. Subclasses may override this routine to
2494 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002495 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002496 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002497 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 }
2499
Richard Smith852c9db2013-04-20 22:23:05 +00002500 /// \brief Build a new C++11 default-initialization expression.
2501 ///
2502 /// By default, builds a new default field initialization expression, which
2503 /// does not require any semantic analysis. Subclasses may override this
2504 /// routine to provide different behavior.
2505 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2506 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002507 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002508 }
2509
Douglas Gregora16548e2009-08-11 05:31:07 +00002510 /// \brief Build a new C++ zero-initialization expression.
2511 ///
2512 /// By default, performs semantic analysis to build the new expression.
2513 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002514 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2515 SourceLocation LParenLoc,
2516 SourceLocation RParenLoc) {
2517 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002518 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002519 }
Mike Stump11289f42009-09-09 15:08:12 +00002520
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 /// \brief Build a new C++ "new" expression.
2522 ///
2523 /// By default, performs semantic analysis to build the new expression.
2524 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002525 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002526 bool UseGlobal,
2527 SourceLocation PlacementLParen,
2528 MultiExprArg PlacementArgs,
2529 SourceLocation PlacementRParen,
2530 SourceRange TypeIdParens,
2531 QualType AllocatedType,
2532 TypeSourceInfo *AllocatedTypeInfo,
2533 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002534 SourceRange DirectInitRange,
2535 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002536 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002538 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002540 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002541 AllocatedType,
2542 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002543 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002544 DirectInitRange,
2545 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 }
Mike Stump11289f42009-09-09 15:08:12 +00002547
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 /// \brief Build a new C++ "delete" expression.
2549 ///
2550 /// By default, performs semantic analysis to build the new expression.
2551 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002552 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 bool IsGlobalDelete,
2554 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002555 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002556 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002557 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 }
Mike Stump11289f42009-09-09 15:08:12 +00002559
Douglas Gregor29c42f22012-02-24 07:38:34 +00002560 /// \brief Build a new type trait expression.
2561 ///
2562 /// By default, performs semantic analysis to build the new expression.
2563 /// Subclasses may override this routine to provide different behavior.
2564 ExprResult RebuildTypeTrait(TypeTrait Trait,
2565 SourceLocation StartLoc,
2566 ArrayRef<TypeSourceInfo *> Args,
2567 SourceLocation RParenLoc) {
2568 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2569 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002570
John Wiegley6242b6a2011-04-28 00:16:57 +00002571 /// \brief Build a new array type trait expression.
2572 ///
2573 /// By default, performs semantic analysis to build the new expression.
2574 /// Subclasses may override this routine to provide different behavior.
2575 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2576 SourceLocation StartLoc,
2577 TypeSourceInfo *TSInfo,
2578 Expr *DimExpr,
2579 SourceLocation RParenLoc) {
2580 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2581 }
2582
John Wiegleyf9f65842011-04-25 06:54:41 +00002583 /// \brief Build a new expression trait expression.
2584 ///
2585 /// By default, performs semantic analysis to build the new expression.
2586 /// Subclasses may override this routine to provide different behavior.
2587 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2588 SourceLocation StartLoc,
2589 Expr *Queried,
2590 SourceLocation RParenLoc) {
2591 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2592 }
2593
Mike Stump11289f42009-09-09 15:08:12 +00002594 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002595 /// expression.
2596 ///
2597 /// By default, performs semantic analysis to build the new expression.
2598 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002599 ExprResult RebuildDependentScopeDeclRefExpr(
2600 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002601 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002602 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002603 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002604 bool IsAddressOfOperand,
2605 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002606 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002607 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002608
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002609 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002610 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2611 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002612
Reid Kleckner32506ed2014-06-12 23:03:48 +00002613 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002614 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002615 }
2616
2617 /// \brief Build a new template-id expression.
2618 ///
2619 /// By default, performs semantic analysis to build the new expression.
2620 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002621 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002622 SourceLocation TemplateKWLoc,
2623 LookupResult &R,
2624 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002625 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002626 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2627 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002628 }
2629
2630 /// \brief Build a new object-construction expression.
2631 ///
2632 /// By default, performs semantic analysis to build the new expression.
2633 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002634 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002635 SourceLocation Loc,
2636 CXXConstructorDecl *Constructor,
2637 bool IsElidable,
2638 MultiExprArg Args,
2639 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002640 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002641 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002642 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002643 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002644 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002645 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002646 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002647 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002648 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002649
Douglas Gregordb121ba2009-12-14 16:27:04 +00002650 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002651 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002652 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002653 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002654 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002655 RequiresZeroInit, ConstructKind,
2656 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002657 }
2658
2659 /// \brief Build a new object-construction expression.
2660 ///
2661 /// By default, performs semantic analysis to build the new expression.
2662 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002663 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2664 SourceLocation LParenLoc,
2665 MultiExprArg Args,
2666 SourceLocation RParenLoc) {
2667 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002669 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002670 RParenLoc);
2671 }
2672
2673 /// \brief Build a new object-construction expression.
2674 ///
2675 /// By default, performs semantic analysis to build the new expression.
2676 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002677 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2678 SourceLocation LParenLoc,
2679 MultiExprArg Args,
2680 SourceLocation RParenLoc) {
2681 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002682 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002683 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002684 RParenLoc);
2685 }
Mike Stump11289f42009-09-09 15:08:12 +00002686
Douglas Gregora16548e2009-08-11 05:31:07 +00002687 /// \brief Build a new member reference expression.
2688 ///
2689 /// By default, performs semantic analysis to build the new expression.
2690 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002691 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002692 QualType BaseType,
2693 bool IsArrow,
2694 SourceLocation OperatorLoc,
2695 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002696 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002697 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002698 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002699 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002700 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002701 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002702
John McCallb268a282010-08-23 23:25:46 +00002703 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002704 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002705 SS, TemplateKWLoc,
2706 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002707 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002708 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002709 }
2710
John McCall10eae182009-11-30 22:42:35 +00002711 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002712 ///
2713 /// By default, performs semantic analysis to build the new expression.
2714 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002715 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2716 SourceLocation OperatorLoc,
2717 bool IsArrow,
2718 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002719 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002720 NamedDecl *FirstQualifierInScope,
2721 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002722 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002723 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002724 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002725
John McCallb268a282010-08-23 23:25:46 +00002726 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002727 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002728 SS, TemplateKWLoc,
2729 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002730 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002731 }
Mike Stump11289f42009-09-09 15:08:12 +00002732
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002733 /// \brief Build a new noexcept expression.
2734 ///
2735 /// By default, performs semantic analysis to build the new expression.
2736 /// Subclasses may override this routine to provide different behavior.
2737 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2738 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2739 }
2740
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002741 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002742 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2743 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002744 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002745 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002746 Optional<unsigned> Length,
2747 ArrayRef<TemplateArgument> PartialArgs) {
2748 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2749 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002750 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002751
Patrick Beard0caa3942012-04-19 00:25:12 +00002752 /// \brief Build a new Objective-C boxed expression.
2753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
2756 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2757 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2758 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002759
Ted Kremeneke65b0862012-03-06 20:05:56 +00002760 /// \brief Build a new Objective-C array literal.
2761 ///
2762 /// By default, performs semantic analysis to build the new expression.
2763 /// Subclasses may override this routine to provide different behavior.
2764 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2765 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002766 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002767 MultiExprArg(Elements, NumElements));
2768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002769
2770 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002771 Expr *Base, Expr *Key,
2772 ObjCMethodDecl *getterMethod,
2773 ObjCMethodDecl *setterMethod) {
2774 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2775 getterMethod, setterMethod);
2776 }
2777
2778 /// \brief Build a new Objective-C dictionary literal.
2779 ///
2780 /// By default, performs semantic analysis to build the new expression.
2781 /// Subclasses may override this routine to provide different behavior.
2782 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002783 MutableArrayRef<ObjCDictionaryElement> Elements) {
2784 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002785 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002786
James Dennett2a4d13c2012-06-15 07:13:21 +00002787 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002788 ///
2789 /// By default, performs semantic analysis to build the new expression.
2790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002791 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002792 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002793 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002794 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002795 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002796
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002797 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002798 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002799 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002800 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002801 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002802 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002803 MultiExprArg Args,
2804 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002805 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2806 ReceiverTypeInfo->getType(),
2807 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002808 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002809 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002810 }
2811
2812 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002813 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002814 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002815 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002816 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002817 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002818 MultiExprArg Args,
2819 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002820 return SemaRef.BuildInstanceMessage(Receiver,
2821 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002822 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002823 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002824 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002825 }
2826
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002827 /// \brief Build a new Objective-C instance/class message to 'super'.
2828 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2829 Selector Sel,
2830 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002831 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002832 ObjCMethodDecl *Method,
2833 SourceLocation LBracLoc,
2834 MultiExprArg Args,
2835 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002836 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002837 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002838 SuperLoc,
2839 Sel, Method, LBracLoc, SelectorLocs,
2840 RBracLoc, Args)
2841 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002842 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002843 SuperLoc,
2844 Sel, Method, LBracLoc, SelectorLocs,
2845 RBracLoc, Args);
2846
2847
2848 }
2849
Douglas Gregord51d90d2010-04-26 20:11:03 +00002850 /// \brief Build a new Objective-C ivar reference expression.
2851 ///
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002854 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002855 SourceLocation IvarLoc,
2856 bool IsArrow, bool IsFreeIvar) {
2857 // FIXME: We lose track of the IsFreeIvar bit.
2858 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002859 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2860 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002861 /*FIXME:*/IvarLoc, IsArrow,
2862 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002863 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002864 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002865 /*TemplateArgs=*/nullptr,
2866 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002867 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002868
2869 /// \brief Build a new Objective-C property reference expression.
2870 ///
2871 /// By default, performs semantic analysis to build the new expression.
2872 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002873 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002874 ObjCPropertyDecl *Property,
2875 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002876 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002877 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2878 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2879 /*FIXME:*/PropertyLoc,
2880 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002881 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002882 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002883 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002884 /*TemplateArgs=*/nullptr,
2885 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002887
John McCallb7bd14f2010-12-02 01:19:52 +00002888 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002889 ///
2890 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002891 /// Subclasses may override this routine to provide different behavior.
2892 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2893 ObjCMethodDecl *Getter,
2894 ObjCMethodDecl *Setter,
2895 SourceLocation PropertyLoc) {
2896 // Since these expressions can only be value-dependent, we do not
2897 // need to perform semantic analysis again.
2898 return Owned(
2899 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2900 VK_LValue, OK_ObjCProperty,
2901 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002902 }
2903
Douglas Gregord51d90d2010-04-26 20:11:03 +00002904 /// \brief Build a new Objective-C "isa" expression.
2905 ///
2906 /// By default, performs semantic analysis to build the new expression.
2907 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002908 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002909 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002910 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002911 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2912 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002913 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002914 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002915 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002916 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002917 /*TemplateArgs=*/nullptr,
2918 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002919 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002920
Douglas Gregora16548e2009-08-11 05:31:07 +00002921 /// \brief Build a new shuffle vector expression.
2922 ///
2923 /// By default, performs semantic analysis to build the new expression.
2924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002925 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002926 MultiExprArg SubExprs,
2927 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002928 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002929 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002930 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2931 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2932 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002933 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002934
Douglas Gregora16548e2009-08-11 05:31:07 +00002935 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002936 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002937 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2938 SemaRef.Context.BuiltinFnTy,
2939 VK_RValue, BuiltinLoc);
2940 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2941 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002942 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002943
2944 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002945 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002946 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002947 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002948
Douglas Gregora16548e2009-08-11 05:31:07 +00002949 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002950 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002951 }
John McCall31f82722010-11-12 08:19:04 +00002952
Hal Finkelc4d7c822013-09-18 03:29:45 +00002953 /// \brief Build a new convert vector expression.
2954 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2955 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2956 SourceLocation RParenLoc) {
2957 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2958 BuiltinLoc, RParenLoc);
2959 }
2960
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002961 /// \brief Build a new template argument pack expansion.
2962 ///
2963 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002964 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002965 /// different behavior.
2966 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002967 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002968 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002969 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002970 case TemplateArgument::Expression: {
2971 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002972 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2973 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002974 if (Result.isInvalid())
2975 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002976
Douglas Gregor98318c22011-01-03 21:37:45 +00002977 return TemplateArgumentLoc(Result.get(), Result.get());
2978 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002979
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002980 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002981 return TemplateArgumentLoc(TemplateArgument(
2982 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002983 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002984 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002985 Pattern.getTemplateNameLoc(),
2986 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002987
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002988 case TemplateArgument::Null:
2989 case TemplateArgument::Integral:
2990 case TemplateArgument::Declaration:
2991 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002992 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002993 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002994 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002995
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002996 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002997 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002998 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002999 EllipsisLoc,
3000 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003001 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3002 Expansion);
3003 break;
3004 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003005
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003006 return TemplateArgumentLoc();
3007 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003008
Douglas Gregor968f23a2011-01-03 19:31:53 +00003009 /// \brief Build a new expression pack expansion.
3010 ///
3011 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003012 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003013 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003014 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003015 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003016 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003017 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003018
Richard Smith0f0af192014-11-08 05:07:16 +00003019 /// \brief Build a new C++1z fold-expression.
3020 ///
3021 /// By default, performs semantic analysis in order to build a new fold
3022 /// expression.
3023 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3024 BinaryOperatorKind Operator,
3025 SourceLocation EllipsisLoc, Expr *RHS,
3026 SourceLocation RParenLoc) {
3027 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3028 RHS, RParenLoc);
3029 }
3030
3031 /// \brief Build an empty C++1z fold-expression with the given operator.
3032 ///
3033 /// By default, produces the fallback value for the fold-expression, or
3034 /// produce an error if there is no fallback value.
3035 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3036 BinaryOperatorKind Operator) {
3037 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3038 }
3039
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003040 /// \brief Build a new atomic operation expression.
3041 ///
3042 /// By default, performs semantic analysis to build the new expression.
3043 /// Subclasses may override this routine to provide different behavior.
3044 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3045 MultiExprArg SubExprs,
3046 QualType RetTy,
3047 AtomicExpr::AtomicOp Op,
3048 SourceLocation RParenLoc) {
3049 // Just create the expression; there is not any interesting semantic
3050 // analysis here because we can't actually build an AtomicExpr until
3051 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003052 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003053 RParenLoc);
3054 }
3055
John McCall31f82722010-11-12 08:19:04 +00003056private:
Douglas Gregor14454802011-02-25 02:25:35 +00003057 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3058 QualType ObjectType,
3059 NamedDecl *FirstQualifierInScope,
3060 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003061
3062 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3063 QualType ObjectType,
3064 NamedDecl *FirstQualifierInScope,
3065 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003066
3067 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3068 NamedDecl *FirstQualifierInScope,
3069 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003070};
Douglas Gregora16548e2009-08-11 05:31:07 +00003071
Douglas Gregorebe10102009-08-20 07:17:43 +00003072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003073StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003074 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003075 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003076
Douglas Gregorebe10102009-08-20 07:17:43 +00003077 switch (S->getStmtClass()) {
3078 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003079
Douglas Gregorebe10102009-08-20 07:17:43 +00003080 // Transform individual statement nodes
3081#define STMT(Node, Parent) \
3082 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003083#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003084#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003085#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003086
Douglas Gregorebe10102009-08-20 07:17:43 +00003087 // Transform expressions by calling TransformExpr.
3088#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003089#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003090#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003091#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003092 {
John McCalldadc5752010-08-24 06:29:42 +00003093 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003094 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003095 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003096
Richard Smith945f8d32013-01-14 22:39:08 +00003097 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003098 }
Mike Stump11289f42009-09-09 15:08:12 +00003099 }
3100
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003101 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003102}
Mike Stump11289f42009-09-09 15:08:12 +00003103
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003104template<typename Derived>
3105OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3106 if (!S)
3107 return S;
3108
3109 switch (S->getClauseKind()) {
3110 default: break;
3111 // Transform individual clause nodes
3112#define OPENMP_CLAUSE(Name, Class) \
3113 case OMPC_ ## Name : \
3114 return getDerived().Transform ## Class(cast<Class>(S));
3115#include "clang/Basic/OpenMPKinds.def"
3116 }
3117
3118 return S;
3119}
3120
Mike Stump11289f42009-09-09 15:08:12 +00003121
Douglas Gregore922c772009-08-04 22:27:00 +00003122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003123ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003124 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003125 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003126
3127 switch (E->getStmtClass()) {
3128 case Stmt::NoStmtClass: break;
3129#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003130#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003131#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003132 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003133#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003134 }
3135
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003136 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003137}
3138
3139template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003140ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003141 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003142 // Initializers are instantiated like expressions, except that various outer
3143 // layers are stripped.
3144 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003145 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003146
3147 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3148 Init = ExprTemp->getSubExpr();
3149
Richard Smithe6ca4752013-05-30 22:40:16 +00003150 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3151 Init = MTE->GetTemporaryExpr();
3152
Richard Smithd59b8322012-12-19 01:39:02 +00003153 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3154 Init = Binder->getSubExpr();
3155
3156 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3157 Init = ICE->getSubExprAsWritten();
3158
Richard Smithcc1b96d2013-06-12 22:31:48 +00003159 if (CXXStdInitializerListExpr *ILE =
3160 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003161 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003162
Richard Smithc6abd962014-07-25 01:12:44 +00003163 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003164 // InitListExprs. Other forms of copy-initialization will be a no-op if
3165 // the initializer is already the right type.
3166 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003167 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003168 return getDerived().TransformExpr(Init);
3169
3170 // Revert value-initialization back to empty parens.
3171 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3172 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003173 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003174 Parens.getEnd());
3175 }
3176
3177 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3178 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003179 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003180 SourceLocation());
3181
3182 // Revert initialization by constructor back to a parenthesized or braced list
3183 // of expressions. Any other form of initializer can just be reused directly.
3184 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003185 return getDerived().TransformExpr(Init);
3186
Richard Smithf8adcdc2014-07-17 05:12:35 +00003187 // If the initialization implicitly converted an initializer list to a
3188 // std::initializer_list object, unwrap the std::initializer_list too.
3189 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003190 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003191
Richard Smithd59b8322012-12-19 01:39:02 +00003192 SmallVector<Expr*, 8> NewArgs;
3193 bool ArgChanged = false;
3194 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003195 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003196 return ExprError();
3197
3198 // If this was list initialization, revert to list form.
3199 if (Construct->isListInitialization())
3200 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3201 Construct->getLocEnd(),
3202 Construct->getType());
3203
Richard Smithd59b8322012-12-19 01:39:02 +00003204 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003205 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003206 if (Parens.isInvalid()) {
3207 // This was a variable declaration's initialization for which no initializer
3208 // was specified.
3209 assert(NewArgs.empty() &&
3210 "no parens or braces but have direct init with arguments?");
3211 return ExprEmpty();
3212 }
Richard Smithd59b8322012-12-19 01:39:02 +00003213 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3214 Parens.getEnd());
3215}
3216
3217template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003218bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003219 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003220 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003221 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003222 bool *ArgChanged) {
3223 for (unsigned I = 0; I != NumInputs; ++I) {
3224 // If requested, drop call arguments that need to be dropped.
3225 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3226 if (ArgChanged)
3227 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003228
Douglas Gregora3efea12011-01-03 19:04:46 +00003229 break;
3230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003231
Douglas Gregor968f23a2011-01-03 19:31:53 +00003232 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3233 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003234
Chris Lattner01cf8db2011-07-20 06:58:45 +00003235 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003236 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3237 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003238
Douglas Gregor968f23a2011-01-03 19:31:53 +00003239 // Determine whether the set of unexpanded parameter packs can and should
3240 // be expanded.
3241 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003242 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003243 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3244 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003245 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3246 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003247 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003248 Expand, RetainExpansion,
3249 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003250 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003251
Douglas Gregor968f23a2011-01-03 19:31:53 +00003252 if (!Expand) {
3253 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003254 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003255 // expansion.
3256 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3257 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3258 if (OutPattern.isInvalid())
3259 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003260
3261 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003262 Expansion->getEllipsisLoc(),
3263 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003264 if (Out.isInvalid())
3265 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003266
Douglas Gregor968f23a2011-01-03 19:31:53 +00003267 if (ArgChanged)
3268 *ArgChanged = true;
3269 Outputs.push_back(Out.get());
3270 continue;
3271 }
John McCall542e7c62011-07-06 07:30:07 +00003272
3273 // Record right away that the argument was changed. This needs
3274 // to happen even if the array expands to nothing.
3275 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor968f23a2011-01-03 19:31:53 +00003277 // The transform has determined that we should perform an elementwise
3278 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003279 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003280 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3281 ExprResult Out = getDerived().TransformExpr(Pattern);
3282 if (Out.isInvalid())
3283 return true;
3284
Richard Smith9467be42014-06-06 17:33:35 +00003285 // FIXME: Can this happen? We should not try to expand the pack
3286 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003287 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003288 Out = getDerived().RebuildPackExpansion(
3289 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003290 if (Out.isInvalid())
3291 return true;
3292 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003293
Douglas Gregor968f23a2011-01-03 19:31:53 +00003294 Outputs.push_back(Out.get());
3295 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003296
Richard Smith9467be42014-06-06 17:33:35 +00003297 // If we're supposed to retain a pack expansion, do so by temporarily
3298 // forgetting the partially-substituted parameter pack.
3299 if (RetainExpansion) {
3300 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3301
3302 ExprResult Out = getDerived().TransformExpr(Pattern);
3303 if (Out.isInvalid())
3304 return true;
3305
3306 Out = getDerived().RebuildPackExpansion(
3307 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3308 if (Out.isInvalid())
3309 return true;
3310
3311 Outputs.push_back(Out.get());
3312 }
3313
Douglas Gregor968f23a2011-01-03 19:31:53 +00003314 continue;
3315 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Richard Smithd59b8322012-12-19 01:39:02 +00003317 ExprResult Result =
3318 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3319 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003320 if (Result.isInvalid())
3321 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003322
Douglas Gregora3efea12011-01-03 19:04:46 +00003323 if (Result.get() != Inputs[I] && ArgChanged)
3324 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003325
3326 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003328
Douglas Gregora3efea12011-01-03 19:04:46 +00003329 return false;
3330}
3331
3332template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003333NestedNameSpecifierLoc
3334TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3335 NestedNameSpecifierLoc NNS,
3336 QualType ObjectType,
3337 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003338 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003339 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003340 Qualifier = Qualifier.getPrefix())
3341 Qualifiers.push_back(Qualifier);
3342
3343 CXXScopeSpec SS;
3344 while (!Qualifiers.empty()) {
3345 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3346 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003347
Douglas Gregor14454802011-02-25 02:25:35 +00003348 switch (QNNS->getKind()) {
3349 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003350 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003351 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003352 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003353 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003354 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003355 FirstQualifierInScope, false))
3356 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor14454802011-02-25 02:25:35 +00003358 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
Douglas Gregor14454802011-02-25 02:25:35 +00003360 case NestedNameSpecifier::Namespace: {
3361 NamespaceDecl *NS
3362 = cast_or_null<NamespaceDecl>(
3363 getDerived().TransformDecl(
3364 Q.getLocalBeginLoc(),
3365 QNNS->getAsNamespace()));
3366 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3367 break;
3368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Douglas Gregor14454802011-02-25 02:25:35 +00003370 case NestedNameSpecifier::NamespaceAlias: {
3371 NamespaceAliasDecl *Alias
3372 = cast_or_null<NamespaceAliasDecl>(
3373 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3374 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003375 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003376 Q.getLocalEndLoc());
3377 break;
3378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor14454802011-02-25 02:25:35 +00003380 case NestedNameSpecifier::Global:
3381 // There is no meaningful transformation that one could perform on the
3382 // global scope.
3383 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3384 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Nikola Smiljanic67860242014-09-26 00:28:20 +00003386 case NestedNameSpecifier::Super: {
3387 CXXRecordDecl *RD =
3388 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3389 SourceLocation(), QNNS->getAsRecordDecl()));
3390 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3391 break;
3392 }
3393
Douglas Gregor14454802011-02-25 02:25:35 +00003394 case NestedNameSpecifier::TypeSpecWithTemplate:
3395 case NestedNameSpecifier::TypeSpec: {
3396 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3397 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003398
Douglas Gregor14454802011-02-25 02:25:35 +00003399 if (!TL)
3400 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003401
Douglas Gregor14454802011-02-25 02:25:35 +00003402 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003403 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003404 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003405 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003406 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003407 if (TL.getType()->isEnumeralType())
3408 SemaRef.Diag(TL.getBeginLoc(),
3409 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003410 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3411 Q.getLocalEndLoc());
3412 break;
3413 }
Richard Trieude756fb2011-05-07 01:36:37 +00003414 // If the nested-name-specifier is an invalid type def, don't emit an
3415 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003416 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3417 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003418 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003419 << TL.getType() << SS.getRange();
3420 }
Douglas Gregor14454802011-02-25 02:25:35 +00003421 return NestedNameSpecifierLoc();
3422 }
Douglas Gregore16af532011-02-28 18:50:33 +00003423 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003424
Douglas Gregore16af532011-02-28 18:50:33 +00003425 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003426 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003427 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor14454802011-02-25 02:25:35 +00003430 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003431 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003432 !getDerived().AlwaysRebuild())
3433 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003434
3435 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003436 // nested-name-specifier, do so.
3437 if (SS.location_size() == NNS.getDataLength() &&
3438 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3439 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3440
3441 // Allocate new nested-name-specifier location information.
3442 return SS.getWithLocInContext(SemaRef.Context);
3443}
3444
3445template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003446DeclarationNameInfo
3447TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003448::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003449 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003450 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003451 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003452
3453 switch (Name.getNameKind()) {
3454 case DeclarationName::Identifier:
3455 case DeclarationName::ObjCZeroArgSelector:
3456 case DeclarationName::ObjCOneArgSelector:
3457 case DeclarationName::ObjCMultiArgSelector:
3458 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003459 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003460 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003461 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003462
Douglas Gregorf816bd72009-09-03 22:13:48 +00003463 case DeclarationName::CXXConstructorName:
3464 case DeclarationName::CXXDestructorName:
3465 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003466 TypeSourceInfo *NewTInfo;
3467 CanQualType NewCanTy;
3468 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003469 NewTInfo = getDerived().TransformType(OldTInfo);
3470 if (!NewTInfo)
3471 return DeclarationNameInfo();
3472 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003473 }
3474 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003475 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003476 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003477 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003478 if (NewT.isNull())
3479 return DeclarationNameInfo();
3480 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3481 }
Mike Stump11289f42009-09-09 15:08:12 +00003482
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003483 DeclarationName NewName
3484 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3485 NewCanTy);
3486 DeclarationNameInfo NewNameInfo(NameInfo);
3487 NewNameInfo.setName(NewName);
3488 NewNameInfo.setNamedTypeInfo(NewTInfo);
3489 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003490 }
Mike Stump11289f42009-09-09 15:08:12 +00003491 }
3492
David Blaikie83d382b2011-09-23 05:06:16 +00003493 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003494}
3495
3496template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003497TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003498TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3499 TemplateName Name,
3500 SourceLocation NameLoc,
3501 QualType ObjectType,
3502 NamedDecl *FirstQualifierInScope) {
3503 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3504 TemplateDecl *Template = QTN->getTemplateDecl();
3505 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003506
Douglas Gregor9db53502011-03-02 18:07:45 +00003507 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003508 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003509 Template));
3510 if (!TransTemplate)
3511 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003512
Douglas Gregor9db53502011-03-02 18:07:45 +00003513 if (!getDerived().AlwaysRebuild() &&
3514 SS.getScopeRep() == QTN->getQualifier() &&
3515 TransTemplate == Template)
3516 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Douglas Gregor9db53502011-03-02 18:07:45 +00003518 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3519 TransTemplate);
3520 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor9db53502011-03-02 18:07:45 +00003522 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3523 if (SS.getScopeRep()) {
3524 // These apply to the scope specifier, not the template.
3525 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003526 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003527 }
3528
Douglas Gregor9db53502011-03-02 18:07:45 +00003529 if (!getDerived().AlwaysRebuild() &&
3530 SS.getScopeRep() == DTN->getQualifier() &&
3531 ObjectType.isNull())
3532 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003533
Douglas Gregor9db53502011-03-02 18:07:45 +00003534 if (DTN->isIdentifier()) {
3535 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003536 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003537 NameLoc,
3538 ObjectType,
3539 FirstQualifierInScope);
3540 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003541
Douglas Gregor9db53502011-03-02 18:07:45 +00003542 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3543 ObjectType);
3544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregor9db53502011-03-02 18:07:45 +00003546 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3547 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003548 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003549 Template));
3550 if (!TransTemplate)
3551 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003552
Douglas Gregor9db53502011-03-02 18:07:45 +00003553 if (!getDerived().AlwaysRebuild() &&
3554 TransTemplate == Template)
3555 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003556
Douglas Gregor9db53502011-03-02 18:07:45 +00003557 return TemplateName(TransTemplate);
3558 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregor9db53502011-03-02 18:07:45 +00003560 if (SubstTemplateTemplateParmPackStorage *SubstPack
3561 = Name.getAsSubstTemplateTemplateParmPack()) {
3562 TemplateTemplateParmDecl *TransParam
3563 = cast_or_null<TemplateTemplateParmDecl>(
3564 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3565 if (!TransParam)
3566 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003567
Douglas Gregor9db53502011-03-02 18:07:45 +00003568 if (!getDerived().AlwaysRebuild() &&
3569 TransParam == SubstPack->getParameterPack())
3570 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
3572 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003573 SubstPack->getArgumentPack());
3574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003575
Douglas Gregor9db53502011-03-02 18:07:45 +00003576 // These should be getting filtered out before they reach the AST.
3577 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003578}
3579
3580template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003581void TreeTransform<Derived>::InventTemplateArgumentLoc(
3582 const TemplateArgument &Arg,
3583 TemplateArgumentLoc &Output) {
3584 SourceLocation Loc = getDerived().getBaseLocation();
3585 switch (Arg.getKind()) {
3586 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003587 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003588 break;
3589
3590 case TemplateArgument::Type:
3591 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003592 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
John McCall0ad16662009-10-29 08:12:44 +00003594 break;
3595
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003596 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003597 case TemplateArgument::TemplateExpansion: {
3598 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003599 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003600 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3601 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3602 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3603 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor9d802122011-03-02 17:09:35 +00003605 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003606 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003607 Builder.getWithLocInContext(SemaRef.Context),
3608 Loc);
3609 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003610 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003611 Builder.getWithLocInContext(SemaRef.Context),
3612 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003614 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003615 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003616
John McCall0ad16662009-10-29 08:12:44 +00003617 case TemplateArgument::Expression:
3618 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3619 break;
3620
3621 case TemplateArgument::Declaration:
3622 case TemplateArgument::Integral:
3623 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003624 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003625 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003626 break;
3627 }
3628}
3629
3630template<typename Derived>
3631bool TreeTransform<Derived>::TransformTemplateArgument(
3632 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003633 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003634 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003635 switch (Arg.getKind()) {
3636 case TemplateArgument::Null:
3637 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003638 case TemplateArgument::Pack:
3639 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003640 case TemplateArgument::NullPtr:
3641 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003642
Douglas Gregore922c772009-08-04 22:27:00 +00003643 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003644 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003645 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003646 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003647
3648 DI = getDerived().TransformType(DI);
3649 if (!DI) return true;
3650
3651 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3652 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003653 }
Mike Stump11289f42009-09-09 15:08:12 +00003654
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003655 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003656 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3657 if (QualifierLoc) {
3658 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3659 if (!QualifierLoc)
3660 return true;
3661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003662
Douglas Gregordf846d12011-03-02 18:46:51 +00003663 CXXScopeSpec SS;
3664 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003665 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003666 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3667 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003668 if (Template.isNull())
3669 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003670
Douglas Gregor9d802122011-03-02 17:09:35 +00003671 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003672 Input.getTemplateNameLoc());
3673 return false;
3674 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003675
3676 case TemplateArgument::TemplateExpansion:
3677 llvm_unreachable("Caller should expand pack expansions");
3678
Douglas Gregore922c772009-08-04 22:27:00 +00003679 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003680 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003681 EnterExpressionEvaluationContext Unevaluated(
3682 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003683
John McCall0ad16662009-10-29 08:12:44 +00003684 Expr *InputExpr = Input.getSourceExpression();
3685 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3686
Chris Lattnercdb591a2011-04-25 20:37:58 +00003687 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003688 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003689 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003690 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003691 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003692 }
Douglas Gregore922c772009-08-04 22:27:00 +00003693 }
Mike Stump11289f42009-09-09 15:08:12 +00003694
Douglas Gregore922c772009-08-04 22:27:00 +00003695 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003696 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003697}
3698
Douglas Gregorfe921a72010-12-20 23:36:19 +00003699/// \brief Iterator adaptor that invents template argument location information
3700/// for each of the template arguments in its underlying iterator.
3701template<typename Derived, typename InputIterator>
3702class TemplateArgumentLocInventIterator {
3703 TreeTransform<Derived> &Self;
3704 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Douglas Gregorfe921a72010-12-20 23:36:19 +00003706public:
3707 typedef TemplateArgumentLoc value_type;
3708 typedef TemplateArgumentLoc reference;
3709 typedef typename std::iterator_traits<InputIterator>::difference_type
3710 difference_type;
3711 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003712
Douglas Gregorfe921a72010-12-20 23:36:19 +00003713 class pointer {
3714 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003715
Douglas Gregorfe921a72010-12-20 23:36:19 +00003716 public:
3717 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003718
Douglas Gregorfe921a72010-12-20 23:36:19 +00003719 const TemplateArgumentLoc *operator->() const { return &Arg; }
3720 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003721
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003722 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003723
Douglas Gregorfe921a72010-12-20 23:36:19 +00003724 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3725 InputIterator Iter)
3726 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Douglas Gregorfe921a72010-12-20 23:36:19 +00003728 TemplateArgumentLocInventIterator &operator++() {
3729 ++Iter;
3730 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003731 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003732
Douglas Gregorfe921a72010-12-20 23:36:19 +00003733 TemplateArgumentLocInventIterator operator++(int) {
3734 TemplateArgumentLocInventIterator Old(*this);
3735 ++(*this);
3736 return Old;
3737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003738
Douglas Gregorfe921a72010-12-20 23:36:19 +00003739 reference operator*() const {
3740 TemplateArgumentLoc Result;
3741 Self.InventTemplateArgumentLoc(*Iter, Result);
3742 return Result;
3743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003744
Douglas Gregorfe921a72010-12-20 23:36:19 +00003745 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
Douglas Gregorfe921a72010-12-20 23:36:19 +00003747 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3748 const TemplateArgumentLocInventIterator &Y) {
3749 return X.Iter == Y.Iter;
3750 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003751
Douglas Gregorfe921a72010-12-20 23:36:19 +00003752 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3753 const TemplateArgumentLocInventIterator &Y) {
3754 return X.Iter != Y.Iter;
3755 }
3756};
Chad Rosier1dcde962012-08-08 18:46:20 +00003757
Douglas Gregor42cafa82010-12-20 17:42:22 +00003758template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003759template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003760bool TreeTransform<Derived>::TransformTemplateArguments(
3761 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3762 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003763 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003764 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003765 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003767 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3768 // Unpack argument packs, which we translate them into separate
3769 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003770 // FIXME: We could do much better if we could guarantee that the
3771 // TemplateArgumentLocInfo for the pack expansion would be usable for
3772 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003773 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003774 TemplateArgument::pack_iterator>
3775 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003776 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003777 In.getArgument().pack_begin()),
3778 PackLocIterator(*this,
3779 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003780 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003781 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003783 continue;
3784 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003785
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003786 if (In.getArgument().isPackExpansion()) {
3787 // We have a pack expansion, for which we will be substituting into
3788 // the pattern.
3789 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003790 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003791 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003792 = getSema().getTemplateArgumentPackExpansionPattern(
3793 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003794
Chris Lattner01cf8db2011-07-20 06:58:45 +00003795 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003796 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3797 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003799 // Determine whether the set of unexpanded parameter packs can and should
3800 // be expanded.
3801 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003802 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003803 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003804 if (getDerived().TryExpandParameterPacks(Ellipsis,
3805 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003806 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003807 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003808 RetainExpansion,
3809 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003810 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003811
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003812 if (!Expand) {
3813 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003814 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003815 // expansion.
3816 TemplateArgumentLoc OutPattern;
3817 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003818 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003819 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003821 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3822 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003823 if (Out.getArgument().isNull())
3824 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003826 Outputs.addArgument(Out);
3827 continue;
3828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003829
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003830 // The transform has determined that we should perform an elementwise
3831 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003832 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003833 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3834
Richard Smithd784e682015-09-23 21:41:42 +00003835 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003836 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003837
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003838 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003839 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3840 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003841 if (Out.getArgument().isNull())
3842 return true;
3843 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003844
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003845 Outputs.addArgument(Out);
3846 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003847
Douglas Gregor48d24112011-01-10 20:53:55 +00003848 // If we're supposed to retain a pack expansion, do so by temporarily
3849 // forgetting the partially-substituted parameter pack.
3850 if (RetainExpansion) {
3851 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003852
Richard Smithd784e682015-09-23 21:41:42 +00003853 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003854 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003855
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003856 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3857 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003858 if (Out.getArgument().isNull())
3859 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003860
Douglas Gregor48d24112011-01-10 20:53:55 +00003861 Outputs.addArgument(Out);
3862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003863
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003864 continue;
3865 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003866
3867 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003868 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003869 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003870
Douglas Gregor42cafa82010-12-20 17:42:22 +00003871 Outputs.addArgument(Out);
3872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003873
Douglas Gregor42cafa82010-12-20 17:42:22 +00003874 return false;
3875
3876}
3877
Douglas Gregord6ff3322009-08-04 16:50:30 +00003878//===----------------------------------------------------------------------===//
3879// Type transformation
3880//===----------------------------------------------------------------------===//
3881
3882template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003883QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003884 if (getDerived().AlreadyTransformed(T))
3885 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003886
John McCall550e0c22009-10-21 00:40:46 +00003887 // Temporary workaround. All of these transformations should
3888 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003889 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3890 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003891
John McCall31f82722010-11-12 08:19:04 +00003892 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003893
John McCall550e0c22009-10-21 00:40:46 +00003894 if (!NewDI)
3895 return QualType();
3896
3897 return NewDI->getType();
3898}
3899
3900template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003901TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003902 // Refine the base location to the type's location.
3903 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3904 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003905 if (getDerived().AlreadyTransformed(DI->getType()))
3906 return DI;
3907
3908 TypeLocBuilder TLB;
3909
3910 TypeLoc TL = DI->getTypeLoc();
3911 TLB.reserve(TL.getFullDataSize());
3912
John McCall31f82722010-11-12 08:19:04 +00003913 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003914 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003915 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003916
John McCallbcd03502009-12-07 02:54:59 +00003917 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003918}
3919
3920template<typename Derived>
3921QualType
John McCall31f82722010-11-12 08:19:04 +00003922TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003923 switch (T.getTypeLocClass()) {
3924#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003925#define TYPELOC(CLASS, PARENT) \
3926 case TypeLoc::CLASS: \
3927 return getDerived().Transform##CLASS##Type(TLB, \
3928 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003929#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003930 }
Mike Stump11289f42009-09-09 15:08:12 +00003931
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003932 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003933}
3934
3935/// FIXME: By default, this routine adds type qualifiers only to types
3936/// that can have qualifiers, and silently suppresses those qualifiers
3937/// that are not permitted (e.g., qualifiers on reference or function
3938/// types). This is the right thing for template instantiation, but
3939/// probably not for other clients.
3940template<typename Derived>
3941QualType
3942TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003943 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003944 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003945
John McCall31f82722010-11-12 08:19:04 +00003946 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003947 if (Result.isNull())
3948 return QualType();
3949
3950 // Silently suppress qualifiers if the result type can't be qualified.
3951 // FIXME: this is the right thing for template instantiation, but
3952 // probably not for other clients.
3953 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003954 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003955
John McCall31168b02011-06-15 23:02:42 +00003956 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003957 // resulting type.
3958 if (Quals.hasObjCLifetime()) {
3959 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3960 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003961 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003962 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003963 // A lifetime qualifier applied to a substituted template parameter
3964 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003965 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003966 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003967 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3968 QualType Replacement = SubstTypeParam->getReplacementType();
3969 Qualifiers Qs = Replacement.getQualifiers();
3970 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003971 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003972 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3973 Qs);
3974 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003975 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003976 Replacement);
3977 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003978 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3979 // 'auto' types behave the same way as template parameters.
3980 QualType Deduced = AutoTy->getDeducedType();
3981 Qualifiers Qs = Deduced.getQualifiers();
3982 Qs.removeObjCLifetime();
3983 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3984 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00003985 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00003986 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003987 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003988 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003989 // Otherwise, complain about the addition of a qualifier to an
3990 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003991 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003992 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003993 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003994
Douglas Gregore46db902011-06-17 22:11:49 +00003995 Quals.removeObjCLifetime();
3996 }
3997 }
3998 }
John McCallcb0f89a2010-06-05 06:41:15 +00003999 if (!Quals.empty()) {
4000 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004001 // BuildQualifiedType might not add qualifiers if they are invalid.
4002 if (Result.hasLocalQualifiers())
4003 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004004 // No location information to preserve.
4005 }
John McCall550e0c22009-10-21 00:40:46 +00004006
4007 return Result;
4008}
4009
Douglas Gregor14454802011-02-25 02:25:35 +00004010template<typename Derived>
4011TypeLoc
4012TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4013 QualType ObjectType,
4014 NamedDecl *UnqualLookup,
4015 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004016 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004017 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004018
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004019 TypeSourceInfo *TSI =
4020 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4021 if (TSI)
4022 return TSI->getTypeLoc();
4023 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004024}
4025
Douglas Gregor579c15f2011-03-02 18:32:08 +00004026template<typename Derived>
4027TypeSourceInfo *
4028TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4029 QualType ObjectType,
4030 NamedDecl *UnqualLookup,
4031 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004032 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004033 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004034
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004035 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4036 UnqualLookup, SS);
4037}
4038
4039template <typename Derived>
4040TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4041 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4042 CXXScopeSpec &SS) {
4043 QualType T = TL.getType();
4044 assert(!getDerived().AlreadyTransformed(T));
4045
Douglas Gregor579c15f2011-03-02 18:32:08 +00004046 TypeLocBuilder TLB;
4047 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004048
Douglas Gregor579c15f2011-03-02 18:32:08 +00004049 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004050 TemplateSpecializationTypeLoc SpecTL =
4051 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004052
Douglas Gregor579c15f2011-03-02 18:32:08 +00004053 TemplateName Template
4054 = getDerived().TransformTemplateName(SS,
4055 SpecTL.getTypePtr()->getTemplateName(),
4056 SpecTL.getTemplateNameLoc(),
4057 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004058 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004059 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004060
4061 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004062 Template);
4063 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004064 DependentTemplateSpecializationTypeLoc SpecTL =
4065 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004066
Douglas Gregor579c15f2011-03-02 18:32:08 +00004067 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004068 = getDerived().RebuildTemplateName(SS,
4069 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004070 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004071 ObjectType, UnqualLookup);
4072 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004073 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
4075 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004076 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004077 Template,
4078 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004079 } else {
4080 // Nothing special needs to be done for these.
4081 Result = getDerived().TransformType(TLB, TL);
4082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004083
4084 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004085 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004086
Douglas Gregor579c15f2011-03-02 18:32:08 +00004087 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4088}
4089
John McCall550e0c22009-10-21 00:40:46 +00004090template <class TyLoc> static inline
4091QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4092 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4093 NewT.setNameLoc(T.getNameLoc());
4094 return T.getType();
4095}
4096
John McCall550e0c22009-10-21 00:40:46 +00004097template<typename Derived>
4098QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004099 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004100 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4101 NewT.setBuiltinLoc(T.getBuiltinLoc());
4102 if (T.needsExtraLocalData())
4103 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4104 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004105}
Mike Stump11289f42009-09-09 15:08:12 +00004106
Douglas Gregord6ff3322009-08-04 16:50:30 +00004107template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004108QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004109 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004110 // FIXME: recurse?
4111 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004112}
Mike Stump11289f42009-09-09 15:08:12 +00004113
Reid Kleckner0503a872013-12-05 01:23:43 +00004114template <typename Derived>
4115QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4116 AdjustedTypeLoc TL) {
4117 // Adjustments applied during transformation are handled elsewhere.
4118 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4119}
4120
Douglas Gregord6ff3322009-08-04 16:50:30 +00004121template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004122QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4123 DecayedTypeLoc TL) {
4124 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4125 if (OriginalType.isNull())
4126 return QualType();
4127
4128 QualType Result = TL.getType();
4129 if (getDerived().AlwaysRebuild() ||
4130 OriginalType != TL.getOriginalLoc().getType())
4131 Result = SemaRef.Context.getDecayedType(OriginalType);
4132 TLB.push<DecayedTypeLoc>(Result);
4133 // Nothing to set for DecayedTypeLoc.
4134 return Result;
4135}
4136
4137template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004138QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004139 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004140 QualType PointeeType
4141 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004142 if (PointeeType.isNull())
4143 return QualType();
4144
4145 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004146 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004147 // A dependent pointer type 'T *' has is being transformed such
4148 // that an Objective-C class type is being replaced for 'T'. The
4149 // resulting pointer type is an ObjCObjectPointerType, not a
4150 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004151 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004152
John McCall8b07ec22010-05-15 11:32:37 +00004153 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4154 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004155 return Result;
4156 }
John McCall31f82722010-11-12 08:19:04 +00004157
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004158 if (getDerived().AlwaysRebuild() ||
4159 PointeeType != TL.getPointeeLoc().getType()) {
4160 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4161 if (Result.isNull())
4162 return QualType();
4163 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004164
John McCall31168b02011-06-15 23:02:42 +00004165 // Objective-C ARC can add lifetime qualifiers to the type that we're
4166 // pointing to.
4167 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004168
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004169 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4170 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004171 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004172}
Mike Stump11289f42009-09-09 15:08:12 +00004173
4174template<typename Derived>
4175QualType
John McCall550e0c22009-10-21 00:40:46 +00004176TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004177 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004178 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004179 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4180 if (PointeeType.isNull())
4181 return QualType();
4182
4183 QualType Result = TL.getType();
4184 if (getDerived().AlwaysRebuild() ||
4185 PointeeType != TL.getPointeeLoc().getType()) {
4186 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004187 TL.getSigilLoc());
4188 if (Result.isNull())
4189 return QualType();
4190 }
4191
Douglas Gregor049211a2010-04-22 16:50:51 +00004192 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004193 NewT.setSigilLoc(TL.getSigilLoc());
4194 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195}
4196
John McCall70dd5f62009-10-30 00:06:24 +00004197/// Transforms a reference type. Note that somewhat paradoxically we
4198/// don't care whether the type itself is an l-value type or an r-value
4199/// type; we only care if the type was *written* as an l-value type
4200/// or an r-value type.
4201template<typename Derived>
4202QualType
4203TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004204 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004205 const ReferenceType *T = TL.getTypePtr();
4206
4207 // Note that this works with the pointee-as-written.
4208 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4209 if (PointeeType.isNull())
4210 return QualType();
4211
4212 QualType Result = TL.getType();
4213 if (getDerived().AlwaysRebuild() ||
4214 PointeeType != T->getPointeeTypeAsWritten()) {
4215 Result = getDerived().RebuildReferenceType(PointeeType,
4216 T->isSpelledAsLValue(),
4217 TL.getSigilLoc());
4218 if (Result.isNull())
4219 return QualType();
4220 }
4221
John McCall31168b02011-06-15 23:02:42 +00004222 // Objective-C ARC can add lifetime qualifiers to the type that we're
4223 // referring to.
4224 TLB.TypeWasModifiedSafely(
4225 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4226
John McCall70dd5f62009-10-30 00:06:24 +00004227 // r-value references can be rebuilt as l-value references.
4228 ReferenceTypeLoc NewTL;
4229 if (isa<LValueReferenceType>(Result))
4230 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4231 else
4232 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4233 NewTL.setSigilLoc(TL.getSigilLoc());
4234
4235 return Result;
4236}
4237
Mike Stump11289f42009-09-09 15:08:12 +00004238template<typename Derived>
4239QualType
John McCall550e0c22009-10-21 00:40:46 +00004240TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004241 LValueReferenceTypeLoc TL) {
4242 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004243}
4244
Mike Stump11289f42009-09-09 15:08:12 +00004245template<typename Derived>
4246QualType
John McCall550e0c22009-10-21 00:40:46 +00004247TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004248 RValueReferenceTypeLoc TL) {
4249 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004250}
Mike Stump11289f42009-09-09 15:08:12 +00004251
Douglas Gregord6ff3322009-08-04 16:50:30 +00004252template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004253QualType
John McCall550e0c22009-10-21 00:40:46 +00004254TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004255 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004256 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004257 if (PointeeType.isNull())
4258 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004259
Abramo Bagnara509357842011-03-05 14:42:21 +00004260 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004261 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004262 if (OldClsTInfo) {
4263 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4264 if (!NewClsTInfo)
4265 return QualType();
4266 }
4267
4268 const MemberPointerType *T = TL.getTypePtr();
4269 QualType OldClsType = QualType(T->getClass(), 0);
4270 QualType NewClsType;
4271 if (NewClsTInfo)
4272 NewClsType = NewClsTInfo->getType();
4273 else {
4274 NewClsType = getDerived().TransformType(OldClsType);
4275 if (NewClsType.isNull())
4276 return QualType();
4277 }
Mike Stump11289f42009-09-09 15:08:12 +00004278
John McCall550e0c22009-10-21 00:40:46 +00004279 QualType Result = TL.getType();
4280 if (getDerived().AlwaysRebuild() ||
4281 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004282 NewClsType != OldClsType) {
4283 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004284 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004285 if (Result.isNull())
4286 return QualType();
4287 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004288
Reid Kleckner0503a872013-12-05 01:23:43 +00004289 // If we had to adjust the pointee type when building a member pointer, make
4290 // sure to push TypeLoc info for it.
4291 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4292 if (MPT && PointeeType != MPT->getPointeeType()) {
4293 assert(isa<AdjustedType>(MPT->getPointeeType()));
4294 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4295 }
4296
John McCall550e0c22009-10-21 00:40:46 +00004297 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4298 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004299 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004300
4301 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004302}
4303
Mike Stump11289f42009-09-09 15:08:12 +00004304template<typename Derived>
4305QualType
John McCall550e0c22009-10-21 00:40:46 +00004306TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004307 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004308 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004309 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004310 if (ElementType.isNull())
4311 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004312
John McCall550e0c22009-10-21 00:40:46 +00004313 QualType Result = TL.getType();
4314 if (getDerived().AlwaysRebuild() ||
4315 ElementType != T->getElementType()) {
4316 Result = getDerived().RebuildConstantArrayType(ElementType,
4317 T->getSizeModifier(),
4318 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004319 T->getIndexTypeCVRQualifiers(),
4320 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004321 if (Result.isNull())
4322 return QualType();
4323 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004324
4325 // We might have either a ConstantArrayType or a VariableArrayType now:
4326 // a ConstantArrayType is allowed to have an element type which is a
4327 // VariableArrayType if the type is dependent. Fortunately, all array
4328 // types have the same location layout.
4329 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004330 NewTL.setLBracketLoc(TL.getLBracketLoc());
4331 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004332
John McCall550e0c22009-10-21 00:40:46 +00004333 Expr *Size = TL.getSizeExpr();
4334 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004335 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4336 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004337 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4338 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004339 }
4340 NewTL.setSizeExpr(Size);
4341
4342 return Result;
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>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004346QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004347 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004348 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004349 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004350 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004351 if (ElementType.isNull())
4352 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004353
John McCall550e0c22009-10-21 00:40:46 +00004354 QualType Result = TL.getType();
4355 if (getDerived().AlwaysRebuild() ||
4356 ElementType != T->getElementType()) {
4357 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004358 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004359 T->getIndexTypeCVRQualifiers(),
4360 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004361 if (Result.isNull())
4362 return QualType();
4363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004364
John McCall550e0c22009-10-21 00:40:46 +00004365 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4366 NewTL.setLBracketLoc(TL.getLBracketLoc());
4367 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004368 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004369
4370 return Result;
4371}
4372
4373template<typename Derived>
4374QualType
4375TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004376 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004377 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004378 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4379 if (ElementType.isNull())
4380 return QualType();
4381
John McCalldadc5752010-08-24 06:29:42 +00004382 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004383 = getDerived().TransformExpr(T->getSizeExpr());
4384 if (SizeResult.isInvalid())
4385 return QualType();
4386
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004387 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004388
4389 QualType Result = TL.getType();
4390 if (getDerived().AlwaysRebuild() ||
4391 ElementType != T->getElementType() ||
4392 Size != T->getSizeExpr()) {
4393 Result = getDerived().RebuildVariableArrayType(ElementType,
4394 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004395 Size,
John McCall550e0c22009-10-21 00:40:46 +00004396 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004397 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004398 if (Result.isNull())
4399 return QualType();
4400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004401
Serge Pavlov774c6d02014-02-06 03:49:11 +00004402 // We might have constant size array now, but fortunately it has the same
4403 // location layout.
4404 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004405 NewTL.setLBracketLoc(TL.getLBracketLoc());
4406 NewTL.setRBracketLoc(TL.getRBracketLoc());
4407 NewTL.setSizeExpr(Size);
4408
4409 return Result;
4410}
4411
4412template<typename Derived>
4413QualType
4414TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004415 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004416 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004417 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4418 if (ElementType.isNull())
4419 return QualType();
4420
Richard Smith764d2fe2011-12-20 02:08:33 +00004421 // Array bounds are constant expressions.
4422 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4423 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004424
John McCall33ddac02011-01-19 10:06:00 +00004425 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4426 Expr *origSize = TL.getSizeExpr();
4427 if (!origSize) origSize = T->getSizeExpr();
4428
4429 ExprResult sizeResult
4430 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004431 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004432 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004433 return QualType();
4434
John McCall33ddac02011-01-19 10:06:00 +00004435 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004436
4437 QualType Result = TL.getType();
4438 if (getDerived().AlwaysRebuild() ||
4439 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004440 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004441 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4442 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004443 size,
John McCall550e0c22009-10-21 00:40:46 +00004444 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004445 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004446 if (Result.isNull())
4447 return QualType();
4448 }
John McCall550e0c22009-10-21 00:40:46 +00004449
4450 // We might have any sort of array type now, but fortunately they
4451 // all have the same location layout.
4452 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4453 NewTL.setLBracketLoc(TL.getLBracketLoc());
4454 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004455 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004456
4457 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004458}
Mike Stump11289f42009-09-09 15:08:12 +00004459
4460template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004461QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004462 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004463 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004464 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004465
4466 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004467 QualType ElementType = getDerived().TransformType(T->getElementType());
4468 if (ElementType.isNull())
4469 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004470
Richard Smith764d2fe2011-12-20 02:08:33 +00004471 // Vector sizes are constant expressions.
4472 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4473 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004474
John McCalldadc5752010-08-24 06:29:42 +00004475 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004476 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004477 if (Size.isInvalid())
4478 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004479
John McCall550e0c22009-10-21 00:40:46 +00004480 QualType Result = TL.getType();
4481 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004482 ElementType != T->getElementType() ||
4483 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004484 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004485 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004486 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004487 if (Result.isNull())
4488 return QualType();
4489 }
John McCall550e0c22009-10-21 00:40:46 +00004490
4491 // Result might be dependent or not.
4492 if (isa<DependentSizedExtVectorType>(Result)) {
4493 DependentSizedExtVectorTypeLoc NewTL
4494 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4495 NewTL.setNameLoc(TL.getNameLoc());
4496 } else {
4497 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4498 NewTL.setNameLoc(TL.getNameLoc());
4499 }
4500
4501 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004502}
Mike Stump11289f42009-09-09 15:08:12 +00004503
4504template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004505QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004506 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004507 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004508 QualType ElementType = getDerived().TransformType(T->getElementType());
4509 if (ElementType.isNull())
4510 return QualType();
4511
John McCall550e0c22009-10-21 00:40:46 +00004512 QualType Result = TL.getType();
4513 if (getDerived().AlwaysRebuild() ||
4514 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004515 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004516 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004517 if (Result.isNull())
4518 return QualType();
4519 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004520
John McCall550e0c22009-10-21 00:40:46 +00004521 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4522 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004523
John McCall550e0c22009-10-21 00:40:46 +00004524 return Result;
4525}
4526
4527template<typename Derived>
4528QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004529 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004530 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004531 QualType ElementType = getDerived().TransformType(T->getElementType());
4532 if (ElementType.isNull())
4533 return QualType();
4534
4535 QualType Result = TL.getType();
4536 if (getDerived().AlwaysRebuild() ||
4537 ElementType != T->getElementType()) {
4538 Result = getDerived().RebuildExtVectorType(ElementType,
4539 T->getNumElements(),
4540 /*FIXME*/ SourceLocation());
4541 if (Result.isNull())
4542 return QualType();
4543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004544
John McCall550e0c22009-10-21 00:40:46 +00004545 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4546 NewTL.setNameLoc(TL.getNameLoc());
4547
4548 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549}
Mike Stump11289f42009-09-09 15:08:12 +00004550
David Blaikie05785d12013-02-20 22:23:23 +00004551template <typename Derived>
4552ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4553 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4554 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004555 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004556 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004557
Douglas Gregor715e4612011-01-14 22:40:04 +00004558 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004559 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004560 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004561 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004562 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004563
Douglas Gregor715e4612011-01-14 22:40:04 +00004564 TypeLocBuilder TLB;
4565 TypeLoc NewTL = OldDI->getTypeLoc();
4566 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004567
4568 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004569 OldExpansionTL.getPatternLoc());
4570 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004571 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004572
4573 Result = RebuildPackExpansionType(Result,
4574 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004575 OldExpansionTL.getEllipsisLoc(),
4576 NumExpansions);
4577 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004578 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004579
Douglas Gregor715e4612011-01-14 22:40:04 +00004580 PackExpansionTypeLoc NewExpansionTL
4581 = TLB.push<PackExpansionTypeLoc>(Result);
4582 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4583 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4584 } else
4585 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004586 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004587 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004588
John McCall8fb0d9d2011-05-01 22:35:37 +00004589 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004590 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004591
4592 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4593 OldParm->getDeclContext(),
4594 OldParm->getInnerLocStart(),
4595 OldParm->getLocation(),
4596 OldParm->getIdentifier(),
4597 NewDI->getType(),
4598 NewDI,
4599 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004600 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004601 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4602 OldParm->getFunctionScopeIndex() + indexAdjustment);
4603 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004604}
4605
4606template<typename Derived>
4607bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004608 TransformFunctionTypeParams(SourceLocation Loc,
4609 ParmVarDecl **Params, unsigned NumParams,
4610 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004611 SmallVectorImpl<QualType> &OutParamTypes,
4612 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004613 int indexAdjustment = 0;
4614
Douglas Gregordd472162011-01-07 00:20:55 +00004615 for (unsigned i = 0; i != NumParams; ++i) {
4616 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004617 assert(OldParm->getFunctionScopeIndex() == i);
4618
David Blaikie05785d12013-02-20 22:23:23 +00004619 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004620 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004621 if (OldParm->isParameterPack()) {
4622 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004623 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004624
Douglas Gregor5499af42011-01-05 23:12:31 +00004625 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004626 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004627 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004628 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4629 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004630 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4631
Douglas Gregor5499af42011-01-05 23:12:31 +00004632 // Determine whether we should expand the parameter packs.
4633 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004634 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004635 Optional<unsigned> OrigNumExpansions =
4636 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004637 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004638 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4639 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004640 Unexpanded,
4641 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004642 RetainExpansion,
4643 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004644 return true;
4645 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004646
Douglas Gregor5499af42011-01-05 23:12:31 +00004647 if (ShouldExpand) {
4648 // Expand the function parameter pack into multiple, separate
4649 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004650 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004651 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004652 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004653 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004654 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004655 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004656 OrigNumExpansions,
4657 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004658 if (!NewParm)
4659 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004660
Douglas Gregordd472162011-01-07 00:20:55 +00004661 OutParamTypes.push_back(NewParm->getType());
4662 if (PVars)
4663 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004664 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004665
4666 // If we're supposed to retain a pack expansion, do so by temporarily
4667 // forgetting the partially-substituted parameter pack.
4668 if (RetainExpansion) {
4669 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004670 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004671 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004672 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004673 OrigNumExpansions,
4674 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004675 if (!NewParm)
4676 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004677
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004678 OutParamTypes.push_back(NewParm->getType());
4679 if (PVars)
4680 PVars->push_back(NewParm);
4681 }
4682
John McCall8fb0d9d2011-05-01 22:35:37 +00004683 // The next parameter should have the same adjustment as the
4684 // last thing we pushed, but we post-incremented indexAdjustment
4685 // on every push. Also, if we push nothing, the adjustment should
4686 // go down by one.
4687 indexAdjustment--;
4688
Douglas Gregor5499af42011-01-05 23:12:31 +00004689 // We're done with the pack expansion.
4690 continue;
4691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004692
4693 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004694 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004695 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4696 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004697 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004698 NumExpansions,
4699 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004700 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004701 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004702 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004703 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004704
John McCall58f10c32010-03-11 09:03:00 +00004705 if (!NewParm)
4706 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004707
Douglas Gregordd472162011-01-07 00:20:55 +00004708 OutParamTypes.push_back(NewParm->getType());
4709 if (PVars)
4710 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004711 continue;
4712 }
John McCall58f10c32010-03-11 09:03:00 +00004713
4714 // Deal with the possibility that we don't have a parameter
4715 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004716 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004717 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004718 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004719 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004720 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004721 = dyn_cast<PackExpansionType>(OldType)) {
4722 // We have a function parameter pack that may need to be expanded.
4723 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004724 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004725 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004726
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;
Douglas Gregordd472162011-01-07 00:20:55 +00004730 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004731 Unexpanded,
4732 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004733 RetainExpansion,
4734 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004735 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004737
Douglas Gregor5499af42011-01-05 23:12:31 +00004738 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004739 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004740 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004741 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004742 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4743 QualType NewType = getDerived().TransformType(Pattern);
4744 if (NewType.isNull())
4745 return true;
John McCall58f10c32010-03-11 09:03:00 +00004746
Douglas Gregordd472162011-01-07 00:20:55 +00004747 OutParamTypes.push_back(NewType);
4748 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004749 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004750 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004751
Douglas Gregor5499af42011-01-05 23:12:31 +00004752 // We're done with the pack expansion.
4753 continue;
4754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004755
Douglas Gregor48d24112011-01-10 20:53:55 +00004756 // If we're supposed to retain a pack expansion, do so by temporarily
4757 // forgetting the partially-substituted parameter pack.
4758 if (RetainExpansion) {
4759 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4760 QualType NewType = getDerived().TransformType(Pattern);
4761 if (NewType.isNull())
4762 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004763
Douglas Gregor48d24112011-01-10 20:53:55 +00004764 OutParamTypes.push_back(NewType);
4765 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004766 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004767 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004768
Chad Rosier1dcde962012-08-08 18:46:20 +00004769 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004770 // expansion.
4771 OldType = Expansion->getPattern();
4772 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004773 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4774 NewType = getDerived().TransformType(OldType);
4775 } else {
4776 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004777 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004778
Douglas Gregor5499af42011-01-05 23:12:31 +00004779 if (NewType.isNull())
4780 return true;
4781
4782 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004783 NewType = getSema().Context.getPackExpansionType(NewType,
4784 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004785
Douglas Gregordd472162011-01-07 00:20:55 +00004786 OutParamTypes.push_back(NewType);
4787 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004788 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004789 }
4790
John McCall8fb0d9d2011-05-01 22:35:37 +00004791#ifndef NDEBUG
4792 if (PVars) {
4793 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4794 if (ParmVarDecl *parm = (*PVars)[i])
4795 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004796 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004797#endif
4798
4799 return false;
4800}
John McCall58f10c32010-03-11 09:03:00 +00004801
4802template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004803QualType
John McCall550e0c22009-10-21 00:40:46 +00004804TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004805 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004806 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004807 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004808 return getDerived().TransformFunctionProtoType(
4809 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004810 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4811 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4812 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004813 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004814}
4815
Richard Smith2e321552014-11-12 02:00:47 +00004816template<typename Derived> template<typename Fn>
4817QualType TreeTransform<Derived>::TransformFunctionProtoType(
4818 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4819 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004820 // Transform the parameters and return type.
4821 //
Richard Smithf623c962012-04-17 00:58:00 +00004822 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004823 // When the function has a trailing return type, we instantiate the
4824 // parameters before the return type, since the return type can then refer
4825 // to the parameters themselves (via decltype, sizeof, etc.).
4826 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004827 SmallVector<QualType, 4> ParamTypes;
4828 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004829 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004830
Douglas Gregor7fb25412010-10-01 18:44:50 +00004831 QualType ResultType;
4832
Richard Smith1226c602012-08-14 22:51:13 +00004833 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004834 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004835 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004836 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004837 return QualType();
4838
Douglas Gregor3024f072012-04-16 07:05:22 +00004839 {
4840 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004841 // If a declaration declares a member function or member function
4842 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004843 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004844 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004845 // declarator.
4846 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004847
Alp Toker42a16a62014-01-25 23:51:36 +00004848 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004849 if (ResultType.isNull())
4850 return QualType();
4851 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004852 }
4853 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004854 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004855 if (ResultType.isNull())
4856 return QualType();
4857
Alp Toker9cacbab2014-01-20 20:26:09 +00004858 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004859 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004860 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004861 return QualType();
4862 }
4863
Richard Smith2e321552014-11-12 02:00:47 +00004864 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4865
4866 bool EPIChanged = false;
4867 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4868 return QualType();
4869
4870 // FIXME: Need to transform ConsumedParameters for variadic template
4871 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004872
John McCall550e0c22009-10-21 00:40:46 +00004873 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004874 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004875 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004876 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004877 if (Result.isNull())
4878 return QualType();
4879 }
Mike Stump11289f42009-09-09 15:08:12 +00004880
John McCall550e0c22009-10-21 00:40:46 +00004881 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004882 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004883 NewTL.setLParenLoc(TL.getLParenLoc());
4884 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004885 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004886 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4887 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004888
4889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004890}
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004893bool TreeTransform<Derived>::TransformExceptionSpec(
4894 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4895 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4896 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4897
4898 // Instantiate a dynamic noexcept expression, if any.
4899 if (ESI.Type == EST_ComputedNoexcept) {
4900 EnterExpressionEvaluationContext Unevaluated(getSema(),
4901 Sema::ConstantEvaluated);
4902 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4903 if (NoexceptExpr.isInvalid())
4904 return true;
4905
4906 NoexceptExpr = getSema().CheckBooleanCondition(
4907 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4908 if (NoexceptExpr.isInvalid())
4909 return true;
4910
4911 if (!NoexceptExpr.get()->isValueDependent()) {
4912 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4913 NoexceptExpr.get(), nullptr,
4914 diag::err_noexcept_needs_constant_expression,
4915 /*AllowFold*/false);
4916 if (NoexceptExpr.isInvalid())
4917 return true;
4918 }
4919
4920 if (ESI.NoexceptExpr != NoexceptExpr.get())
4921 Changed = true;
4922 ESI.NoexceptExpr = NoexceptExpr.get();
4923 }
4924
4925 if (ESI.Type != EST_Dynamic)
4926 return false;
4927
4928 // Instantiate a dynamic exception specification's type.
4929 for (QualType T : ESI.Exceptions) {
4930 if (const PackExpansionType *PackExpansion =
4931 T->getAs<PackExpansionType>()) {
4932 Changed = true;
4933
4934 // We have a pack expansion. Instantiate it.
4935 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4936 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4937 Unexpanded);
4938 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4939
4940 // Determine whether the set of unexpanded parameter packs can and
4941 // should
4942 // be expanded.
4943 bool Expand = false;
4944 bool RetainExpansion = false;
4945 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4946 // FIXME: Track the location of the ellipsis (and track source location
4947 // information for the types in the exception specification in general).
4948 if (getDerived().TryExpandParameterPacks(
4949 Loc, SourceRange(), Unexpanded, Expand,
4950 RetainExpansion, NumExpansions))
4951 return true;
4952
4953 if (!Expand) {
4954 // We can't expand this pack expansion into separate arguments yet;
4955 // just substitute into the pattern and create a new pack expansion
4956 // type.
4957 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4958 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4959 if (U.isNull())
4960 return true;
4961
4962 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4963 Exceptions.push_back(U);
4964 continue;
4965 }
4966
4967 // Substitute into the pack expansion pattern for each slice of the
4968 // pack.
4969 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4970 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4971
4972 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4973 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4974 return true;
4975
4976 Exceptions.push_back(U);
4977 }
4978 } else {
4979 QualType U = getDerived().TransformType(T);
4980 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4981 return true;
4982 if (T != U)
4983 Changed = true;
4984
4985 Exceptions.push_back(U);
4986 }
4987 }
4988
4989 ESI.Exceptions = Exceptions;
4990 return false;
4991}
4992
4993template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004994QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004995 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004996 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004997 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004998 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004999 if (ResultType.isNull())
5000 return QualType();
5001
5002 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005003 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005004 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5005
5006 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005007 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005008 NewTL.setLParenLoc(TL.getLParenLoc());
5009 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005010 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005011
5012 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005013}
Mike Stump11289f42009-09-09 15:08:12 +00005014
John McCallb96ec562009-12-04 22:46:56 +00005015template<typename Derived> QualType
5016TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005017 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005018 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005019 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005020 if (!D)
5021 return QualType();
5022
5023 QualType Result = TL.getType();
5024 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5025 Result = getDerived().RebuildUnresolvedUsingType(D);
5026 if (Result.isNull())
5027 return QualType();
5028 }
5029
5030 // We might get an arbitrary type spec type back. We should at
5031 // least always get a type spec type, though.
5032 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5033 NewTL.setNameLoc(TL.getNameLoc());
5034
5035 return Result;
5036}
5037
Douglas Gregord6ff3322009-08-04 16:50:30 +00005038template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005039QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005040 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005041 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005042 TypedefNameDecl *Typedef
5043 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5044 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005045 if (!Typedef)
5046 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005047
John McCall550e0c22009-10-21 00:40:46 +00005048 QualType Result = TL.getType();
5049 if (getDerived().AlwaysRebuild() ||
5050 Typedef != T->getDecl()) {
5051 Result = getDerived().RebuildTypedefType(Typedef);
5052 if (Result.isNull())
5053 return QualType();
5054 }
Mike Stump11289f42009-09-09 15:08:12 +00005055
John McCall550e0c22009-10-21 00:40:46 +00005056 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5057 NewTL.setNameLoc(TL.getNameLoc());
5058
5059 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060}
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregord6ff3322009-08-04 16:50:30 +00005062template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005063QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005064 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005065 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005066 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5067 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005068
John McCalldadc5752010-08-24 06:29:42 +00005069 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005070 if (E.isInvalid())
5071 return QualType();
5072
Eli Friedmane4f22df2012-02-29 04:03:55 +00005073 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5074 if (E.isInvalid())
5075 return QualType();
5076
John McCall550e0c22009-10-21 00:40:46 +00005077 QualType Result = TL.getType();
5078 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005079 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005080 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005081 if (Result.isNull())
5082 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005083 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005084 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005085
John McCall550e0c22009-10-21 00:40:46 +00005086 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005087 NewTL.setTypeofLoc(TL.getTypeofLoc());
5088 NewTL.setLParenLoc(TL.getLParenLoc());
5089 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005090
5091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005092}
Mike Stump11289f42009-09-09 15:08:12 +00005093
5094template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005095QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005096 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005097 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5098 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5099 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005101
John McCall550e0c22009-10-21 00:40:46 +00005102 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005103 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5104 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005105 if (Result.isNull())
5106 return QualType();
5107 }
Mike Stump11289f42009-09-09 15:08:12 +00005108
John McCall550e0c22009-10-21 00:40:46 +00005109 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005110 NewTL.setTypeofLoc(TL.getTypeofLoc());
5111 NewTL.setLParenLoc(TL.getLParenLoc());
5112 NewTL.setRParenLoc(TL.getRParenLoc());
5113 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005114
5115 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005116}
Mike Stump11289f42009-09-09 15:08:12 +00005117
5118template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005119QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005120 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005121 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005122
Douglas Gregore922c772009-08-04 22:27:00 +00005123 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005124 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5125 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005126
John McCalldadc5752010-08-24 06:29:42 +00005127 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005128 if (E.isInvalid())
5129 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005130
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005131 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005132 if (E.isInvalid())
5133 return QualType();
5134
John McCall550e0c22009-10-21 00:40:46 +00005135 QualType Result = TL.getType();
5136 if (getDerived().AlwaysRebuild() ||
5137 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005138 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005139 if (Result.isNull())
5140 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005141 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005142 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005143
John McCall550e0c22009-10-21 00:40:46 +00005144 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5145 NewTL.setNameLoc(TL.getNameLoc());
5146
5147 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005148}
5149
5150template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005151QualType TreeTransform<Derived>::TransformUnaryTransformType(
5152 TypeLocBuilder &TLB,
5153 UnaryTransformTypeLoc TL) {
5154 QualType Result = TL.getType();
5155 if (Result->isDependentType()) {
5156 const UnaryTransformType *T = TL.getTypePtr();
5157 QualType NewBase =
5158 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5159 Result = getDerived().RebuildUnaryTransformType(NewBase,
5160 T->getUTTKind(),
5161 TL.getKWLoc());
5162 if (Result.isNull())
5163 return QualType();
5164 }
5165
5166 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5167 NewTL.setKWLoc(TL.getKWLoc());
5168 NewTL.setParensRange(TL.getParensRange());
5169 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5170 return Result;
5171}
5172
5173template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005174QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5175 AutoTypeLoc TL) {
5176 const AutoType *T = TL.getTypePtr();
5177 QualType OldDeduced = T->getDeducedType();
5178 QualType NewDeduced;
5179 if (!OldDeduced.isNull()) {
5180 NewDeduced = getDerived().TransformType(OldDeduced);
5181 if (NewDeduced.isNull())
5182 return QualType();
5183 }
5184
5185 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005186 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5187 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005188 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005189 if (Result.isNull())
5190 return QualType();
5191 }
5192
5193 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5194 NewTL.setNameLoc(TL.getNameLoc());
5195
5196 return Result;
5197}
5198
5199template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005200QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005201 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005202 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005203 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005204 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5205 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005206 if (!Record)
5207 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005208
John McCall550e0c22009-10-21 00:40:46 +00005209 QualType Result = TL.getType();
5210 if (getDerived().AlwaysRebuild() ||
5211 Record != T->getDecl()) {
5212 Result = getDerived().RebuildRecordType(Record);
5213 if (Result.isNull())
5214 return QualType();
5215 }
Mike Stump11289f42009-09-09 15:08:12 +00005216
John McCall550e0c22009-10-21 00:40:46 +00005217 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5218 NewTL.setNameLoc(TL.getNameLoc());
5219
5220 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221}
Mike Stump11289f42009-09-09 15:08:12 +00005222
5223template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005224QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005225 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005226 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005227 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005228 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5229 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005230 if (!Enum)
5231 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005232
John McCall550e0c22009-10-21 00:40:46 +00005233 QualType Result = TL.getType();
5234 if (getDerived().AlwaysRebuild() ||
5235 Enum != T->getDecl()) {
5236 Result = getDerived().RebuildEnumType(Enum);
5237 if (Result.isNull())
5238 return QualType();
5239 }
Mike Stump11289f42009-09-09 15:08:12 +00005240
John McCall550e0c22009-10-21 00:40:46 +00005241 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5242 NewTL.setNameLoc(TL.getNameLoc());
5243
5244 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005245}
John McCallfcc33b02009-09-05 00:15:47 +00005246
John McCalle78aac42010-03-10 03:28:59 +00005247template<typename Derived>
5248QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5249 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005250 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005251 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5252 TL.getTypePtr()->getDecl());
5253 if (!D) return QualType();
5254
5255 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5256 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5257 return T;
5258}
5259
Douglas Gregord6ff3322009-08-04 16:50:30 +00005260template<typename Derived>
5261QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005262 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005263 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005264 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265}
5266
Mike Stump11289f42009-09-09 15:08:12 +00005267template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005268QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005269 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005270 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005271 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005272
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005273 // Substitute into the replacement type, which itself might involve something
5274 // that needs to be transformed. This only tends to occur with default
5275 // template arguments of template template parameters.
5276 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5277 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5278 if (Replacement.isNull())
5279 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005280
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005281 // Always canonicalize the replacement type.
5282 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5283 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005284 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005285 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005286
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005287 // Propagate type-source information.
5288 SubstTemplateTypeParmTypeLoc NewTL
5289 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5290 NewTL.setNameLoc(TL.getNameLoc());
5291 return Result;
5292
John McCallcebee162009-10-18 09:09:24 +00005293}
5294
5295template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005296QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5297 TypeLocBuilder &TLB,
5298 SubstTemplateTypeParmPackTypeLoc TL) {
5299 return TransformTypeSpecType(TLB, TL);
5300}
5301
5302template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005303QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005304 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005305 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005306 const TemplateSpecializationType *T = TL.getTypePtr();
5307
Douglas Gregordf846d12011-03-02 18:46:51 +00005308 // The nested-name-specifier never matters in a TemplateSpecializationType,
5309 // because we can't have a dependent nested-name-specifier anyway.
5310 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005311 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005312 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5313 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005314 if (Template.isNull())
5315 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005316
John McCall31f82722010-11-12 08:19:04 +00005317 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5318}
5319
Eli Friedman0dfb8892011-10-06 23:00:33 +00005320template<typename Derived>
5321QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5322 AtomicTypeLoc TL) {
5323 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5324 if (ValueType.isNull())
5325 return QualType();
5326
5327 QualType Result = TL.getType();
5328 if (getDerived().AlwaysRebuild() ||
5329 ValueType != TL.getValueLoc().getType()) {
5330 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5331 if (Result.isNull())
5332 return QualType();
5333 }
5334
5335 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5336 NewTL.setKWLoc(TL.getKWLoc());
5337 NewTL.setLParenLoc(TL.getLParenLoc());
5338 NewTL.setRParenLoc(TL.getRParenLoc());
5339
5340 return Result;
5341}
5342
Xiuli Pan9c14e282016-01-09 12:53:17 +00005343template <typename Derived>
5344QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5345 PipeTypeLoc TL) {
5346 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5347 if (ValueType.isNull())
5348 return QualType();
5349
5350 QualType Result = TL.getType();
5351 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5352 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5353 if (Result.isNull())
5354 return QualType();
5355 }
5356
5357 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5358 NewTL.setKWLoc(TL.getKWLoc());
5359
5360 return Result;
5361}
5362
Chad Rosier1dcde962012-08-08 18:46:20 +00005363 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005364 /// container that provides a \c getArgLoc() member function.
5365 ///
5366 /// This iterator is intended to be used with the iterator form of
5367 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5368 template<typename ArgLocContainer>
5369 class TemplateArgumentLocContainerIterator {
5370 ArgLocContainer *Container;
5371 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005372
Douglas Gregorfe921a72010-12-20 23:36:19 +00005373 public:
5374 typedef TemplateArgumentLoc value_type;
5375 typedef TemplateArgumentLoc reference;
5376 typedef int difference_type;
5377 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005378
Douglas Gregorfe921a72010-12-20 23:36:19 +00005379 class pointer {
5380 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005381
Douglas Gregorfe921a72010-12-20 23:36:19 +00005382 public:
5383 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005384
Douglas Gregorfe921a72010-12-20 23:36:19 +00005385 const TemplateArgumentLoc *operator->() const {
5386 return &Arg;
5387 }
5388 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005389
5390
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005391 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005392
Douglas Gregorfe921a72010-12-20 23:36:19 +00005393 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5394 unsigned Index)
5395 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005396
Douglas Gregorfe921a72010-12-20 23:36:19 +00005397 TemplateArgumentLocContainerIterator &operator++() {
5398 ++Index;
5399 return *this;
5400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005401
Douglas Gregorfe921a72010-12-20 23:36:19 +00005402 TemplateArgumentLocContainerIterator operator++(int) {
5403 TemplateArgumentLocContainerIterator Old(*this);
5404 ++(*this);
5405 return Old;
5406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005407
Douglas Gregorfe921a72010-12-20 23:36:19 +00005408 TemplateArgumentLoc operator*() const {
5409 return Container->getArgLoc(Index);
5410 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005411
Douglas Gregorfe921a72010-12-20 23:36:19 +00005412 pointer operator->() const {
5413 return pointer(Container->getArgLoc(Index));
5414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005415
Douglas Gregorfe921a72010-12-20 23:36:19 +00005416 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005417 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005418 return X.Container == Y.Container && X.Index == Y.Index;
5419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005420
Douglas Gregorfe921a72010-12-20 23:36:19 +00005421 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005422 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005423 return !(X == Y);
5424 }
5425 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005426
5427
John McCall31f82722010-11-12 08:19:04 +00005428template <typename Derived>
5429QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5430 TypeLocBuilder &TLB,
5431 TemplateSpecializationTypeLoc TL,
5432 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005433 TemplateArgumentListInfo NewTemplateArgs;
5434 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5435 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005436 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5437 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005438 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005439 ArgIterator(TL, TL.getNumArgs()),
5440 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005441 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005442
John McCall0ad16662009-10-29 08:12:44 +00005443 // FIXME: maybe don't rebuild if all the template arguments are the same.
5444
5445 QualType Result =
5446 getDerived().RebuildTemplateSpecializationType(Template,
5447 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005448 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005449
5450 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005451 // Specializations of template template parameters are represented as
5452 // TemplateSpecializationTypes, and substitution of type alias templates
5453 // within a dependent context can transform them into
5454 // DependentTemplateSpecializationTypes.
5455 if (isa<DependentTemplateSpecializationType>(Result)) {
5456 DependentTemplateSpecializationTypeLoc NewTL
5457 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005458 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005459 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005460 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005461 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005462 NewTL.setLAngleLoc(TL.getLAngleLoc());
5463 NewTL.setRAngleLoc(TL.getRAngleLoc());
5464 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5465 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5466 return Result;
5467 }
5468
John McCall0ad16662009-10-29 08:12:44 +00005469 TemplateSpecializationTypeLoc NewTL
5470 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005471 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005472 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5473 NewTL.setLAngleLoc(TL.getLAngleLoc());
5474 NewTL.setRAngleLoc(TL.getRAngleLoc());
5475 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5476 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005477 }
Mike Stump11289f42009-09-09 15:08:12 +00005478
John McCall0ad16662009-10-29 08:12:44 +00005479 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005480}
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregor5a064722011-02-28 17:23:35 +00005482template <typename Derived>
5483QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5484 TypeLocBuilder &TLB,
5485 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005486 TemplateName Template,
5487 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005488 TemplateArgumentListInfo NewTemplateArgs;
5489 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5490 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5491 typedef TemplateArgumentLocContainerIterator<
5492 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005493 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005494 ArgIterator(TL, TL.getNumArgs()),
5495 NewTemplateArgs))
5496 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005497
Douglas Gregor5a064722011-02-28 17:23:35 +00005498 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005499
Douglas Gregor5a064722011-02-28 17:23:35 +00005500 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5501 QualType Result
5502 = getSema().Context.getDependentTemplateSpecializationType(
5503 TL.getTypePtr()->getKeyword(),
5504 DTN->getQualifier(),
5505 DTN->getIdentifier(),
5506 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005507
Douglas Gregor5a064722011-02-28 17:23:35 +00005508 DependentTemplateSpecializationTypeLoc NewTL
5509 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005510 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005511 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005512 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005513 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005514 NewTL.setLAngleLoc(TL.getLAngleLoc());
5515 NewTL.setRAngleLoc(TL.getRAngleLoc());
5516 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5517 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5518 return Result;
5519 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005520
5521 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005522 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005523 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005524 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005525
Douglas Gregor5a064722011-02-28 17:23:35 +00005526 if (!Result.isNull()) {
5527 /// FIXME: Wrap this in an elaborated-type-specifier?
5528 TemplateSpecializationTypeLoc NewTL
5529 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005530 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005531 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005532 NewTL.setLAngleLoc(TL.getLAngleLoc());
5533 NewTL.setRAngleLoc(TL.getRAngleLoc());
5534 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5535 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5536 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005537
Douglas Gregor5a064722011-02-28 17:23:35 +00005538 return Result;
5539}
5540
Mike Stump11289f42009-09-09 15:08:12 +00005541template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005542QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005543TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005544 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005545 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005546
Douglas Gregor844cb502011-03-01 18:12:44 +00005547 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005548 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005549 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005550 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005551 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5552 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005553 return QualType();
5554 }
Mike Stump11289f42009-09-09 15:08:12 +00005555
John McCall31f82722010-11-12 08:19:04 +00005556 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5557 if (NamedT.isNull())
5558 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005559
Richard Smith3f1b5d02011-05-05 21:57:07 +00005560 // C++0x [dcl.type.elab]p2:
5561 // If the identifier resolves to a typedef-name or the simple-template-id
5562 // resolves to an alias template specialization, the
5563 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005564 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5565 if (const TemplateSpecializationType *TST =
5566 NamedT->getAs<TemplateSpecializationType>()) {
5567 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005568 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5569 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005570 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5571 diag::err_tag_reference_non_tag) << 4;
5572 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5573 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005574 }
5575 }
5576
John McCall550e0c22009-10-21 00:40:46 +00005577 QualType Result = TL.getType();
5578 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005579 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005580 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005581 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005582 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005583 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005584 if (Result.isNull())
5585 return QualType();
5586 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005587
Abramo Bagnara6150c882010-05-11 21:36:43 +00005588 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005589 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005590 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005591 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
5594template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005595QualType TreeTransform<Derived>::TransformAttributedType(
5596 TypeLocBuilder &TLB,
5597 AttributedTypeLoc TL) {
5598 const AttributedType *oldType = TL.getTypePtr();
5599 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5600 if (modifiedType.isNull())
5601 return QualType();
5602
5603 QualType result = TL.getType();
5604
5605 // FIXME: dependent operand expressions?
5606 if (getDerived().AlwaysRebuild() ||
5607 modifiedType != oldType->getModifiedType()) {
5608 // TODO: this is really lame; we should really be rebuilding the
5609 // equivalent type from first principles.
5610 QualType equivalentType
5611 = getDerived().TransformType(oldType->getEquivalentType());
5612 if (equivalentType.isNull())
5613 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005614
5615 // Check whether we can add nullability; it is only represented as
5616 // type sugar, and therefore cannot be diagnosed in any other way.
5617 if (auto nullability = oldType->getImmediateNullability()) {
5618 if (!modifiedType->canHaveNullability()) {
5619 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005620 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005621 return QualType();
5622 }
5623 }
5624
John McCall81904512011-01-06 01:58:22 +00005625 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5626 modifiedType,
5627 equivalentType);
5628 }
5629
5630 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5631 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5632 if (TL.hasAttrOperand())
5633 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5634 if (TL.hasAttrExprOperand())
5635 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5636 else if (TL.hasAttrEnumOperand())
5637 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5638
5639 return result;
5640}
5641
5642template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005643QualType
5644TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5645 ParenTypeLoc TL) {
5646 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5647 if (Inner.isNull())
5648 return QualType();
5649
5650 QualType Result = TL.getType();
5651 if (getDerived().AlwaysRebuild() ||
5652 Inner != TL.getInnerLoc().getType()) {
5653 Result = getDerived().RebuildParenType(Inner);
5654 if (Result.isNull())
5655 return QualType();
5656 }
5657
5658 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5659 NewTL.setLParenLoc(TL.getLParenLoc());
5660 NewTL.setRParenLoc(TL.getRParenLoc());
5661 return Result;
5662}
5663
5664template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005665QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005666 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005667 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005668
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005669 NestedNameSpecifierLoc QualifierLoc
5670 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5671 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005672 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005673
John McCallc392f372010-06-11 00:33:02 +00005674 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005675 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005676 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005677 QualifierLoc,
5678 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005679 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005680 if (Result.isNull())
5681 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005682
Abramo Bagnarad7548482010-05-19 21:37:53 +00005683 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5684 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005685 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5686
Abramo Bagnarad7548482010-05-19 21:37:53 +00005687 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005688 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005689 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005690 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005691 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005692 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005693 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005694 NewTL.setNameLoc(TL.getNameLoc());
5695 }
John McCall550e0c22009-10-21 00:40:46 +00005696 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005697}
Mike Stump11289f42009-09-09 15:08:12 +00005698
Douglas Gregord6ff3322009-08-04 16:50:30 +00005699template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005700QualType TreeTransform<Derived>::
5701 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005702 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005703 NestedNameSpecifierLoc QualifierLoc;
5704 if (TL.getQualifierLoc()) {
5705 QualifierLoc
5706 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5707 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005708 return QualType();
5709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005710
John McCall31f82722010-11-12 08:19:04 +00005711 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005712 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005713}
5714
5715template<typename Derived>
5716QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005717TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5718 DependentTemplateSpecializationTypeLoc TL,
5719 NestedNameSpecifierLoc QualifierLoc) {
5720 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005721
Douglas Gregora7a795b2011-03-01 20:11:18 +00005722 TemplateArgumentListInfo NewTemplateArgs;
5723 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5724 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005725
Douglas Gregora7a795b2011-03-01 20:11:18 +00005726 typedef TemplateArgumentLocContainerIterator<
5727 DependentTemplateSpecializationTypeLoc> ArgIterator;
5728 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5729 ArgIterator(TL, TL.getNumArgs()),
5730 NewTemplateArgs))
5731 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005732
Douglas Gregora7a795b2011-03-01 20:11:18 +00005733 QualType Result
5734 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5735 QualifierLoc,
5736 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005737 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005738 NewTemplateArgs);
5739 if (Result.isNull())
5740 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005741
Douglas Gregora7a795b2011-03-01 20:11:18 +00005742 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5743 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005744
Douglas Gregora7a795b2011-03-01 20:11:18 +00005745 // Copy information relevant to the template specialization.
5746 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005747 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005748 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005749 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005750 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5751 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005752 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005753 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005754
Douglas Gregora7a795b2011-03-01 20:11:18 +00005755 // Copy information relevant to the elaborated type.
5756 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005757 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005758 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005759 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5760 DependentTemplateSpecializationTypeLoc SpecTL
5761 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005762 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005763 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005764 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005765 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005766 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5767 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005768 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005769 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005770 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005771 TemplateSpecializationTypeLoc SpecTL
5772 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005773 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005774 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005775 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5776 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005777 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005778 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005779 }
5780 return Result;
5781}
5782
5783template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005784QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5785 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005786 QualType Pattern
5787 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005788 if (Pattern.isNull())
5789 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005790
5791 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005792 if (getDerived().AlwaysRebuild() ||
5793 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005794 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005795 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005796 TL.getEllipsisLoc(),
5797 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005798 if (Result.isNull())
5799 return QualType();
5800 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005801
Douglas Gregor822d0302011-01-12 17:07:58 +00005802 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5803 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5804 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005805}
5806
5807template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005808QualType
5809TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005810 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005811 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005812 TLB.pushFullCopy(TL);
5813 return TL.getType();
5814}
5815
5816template<typename Derived>
5817QualType
5818TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005819 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005820 // Transform base type.
5821 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5822 if (BaseType.isNull())
5823 return QualType();
5824
5825 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5826
5827 // Transform type arguments.
5828 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5829 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5830 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5831 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5832 QualType TypeArg = TypeArgInfo->getType();
5833 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5834 AnyChanged = true;
5835
5836 // We have a pack expansion. Instantiate it.
5837 const auto *PackExpansion = PackExpansionLoc.getType()
5838 ->castAs<PackExpansionType>();
5839 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5840 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5841 Unexpanded);
5842 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5843
5844 // Determine whether the set of unexpanded parameter packs can
5845 // and should be expanded.
5846 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5847 bool Expand = false;
5848 bool RetainExpansion = false;
5849 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5850 if (getDerived().TryExpandParameterPacks(
5851 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5852 Unexpanded, Expand, RetainExpansion, NumExpansions))
5853 return QualType();
5854
5855 if (!Expand) {
5856 // We can't expand this pack expansion into separate arguments yet;
5857 // just substitute into the pattern and create a new pack expansion
5858 // type.
5859 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5860
5861 TypeLocBuilder TypeArgBuilder;
5862 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5863 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5864 PatternLoc);
5865 if (NewPatternType.isNull())
5866 return QualType();
5867
5868 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5869 NewPatternType, NumExpansions);
5870 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5871 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5872 NewTypeArgInfos.push_back(
5873 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5874 continue;
5875 }
5876
5877 // Substitute into the pack expansion pattern for each slice of the
5878 // pack.
5879 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5880 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5881
5882 TypeLocBuilder TypeArgBuilder;
5883 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5884
5885 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5886 PatternLoc);
5887 if (NewTypeArg.isNull())
5888 return QualType();
5889
5890 NewTypeArgInfos.push_back(
5891 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5892 }
5893
5894 continue;
5895 }
5896
5897 TypeLocBuilder TypeArgBuilder;
5898 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5899 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5900 if (NewTypeArg.isNull())
5901 return QualType();
5902
5903 // If nothing changed, just keep the old TypeSourceInfo.
5904 if (NewTypeArg == TypeArg) {
5905 NewTypeArgInfos.push_back(TypeArgInfo);
5906 continue;
5907 }
5908
5909 NewTypeArgInfos.push_back(
5910 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5911 AnyChanged = true;
5912 }
5913
5914 QualType Result = TL.getType();
5915 if (getDerived().AlwaysRebuild() || AnyChanged) {
5916 // Rebuild the type.
5917 Result = getDerived().RebuildObjCObjectType(
5918 BaseType,
5919 TL.getLocStart(),
5920 TL.getTypeArgsLAngleLoc(),
5921 NewTypeArgInfos,
5922 TL.getTypeArgsRAngleLoc(),
5923 TL.getProtocolLAngleLoc(),
5924 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5925 TL.getNumProtocols()),
5926 TL.getProtocolLocs(),
5927 TL.getProtocolRAngleLoc());
5928
5929 if (Result.isNull())
5930 return QualType();
5931 }
5932
5933 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5934 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5935 NewT.setHasBaseTypeAsWritten(true);
5936 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5937 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5938 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5939 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5940 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5941 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5942 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5943 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5944 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005945}
Mike Stump11289f42009-09-09 15:08:12 +00005946
5947template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005948QualType
5949TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005950 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005951 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5952 if (PointeeType.isNull())
5953 return QualType();
5954
5955 QualType Result = TL.getType();
5956 if (getDerived().AlwaysRebuild() ||
5957 PointeeType != TL.getPointeeLoc().getType()) {
5958 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5959 TL.getStarLoc());
5960 if (Result.isNull())
5961 return QualType();
5962 }
5963
5964 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5965 NewT.setStarLoc(TL.getStarLoc());
5966 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005967}
5968
Douglas Gregord6ff3322009-08-04 16:50:30 +00005969//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005970// Statement transformation
5971//===----------------------------------------------------------------------===//
5972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005973StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005974TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005975 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005976}
5977
5978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005979StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005980TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5981 return getDerived().TransformCompoundStmt(S, false);
5982}
5983
5984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005985StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005986TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005987 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005988 Sema::CompoundScopeRAII CompoundScope(getSema());
5989
John McCall1ababa62010-08-27 19:56:05 +00005990 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005991 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005992 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005993 for (auto *B : S->body()) {
5994 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005995 if (Result.isInvalid()) {
5996 // Immediately fail if this was a DeclStmt, since it's very
5997 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005998 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005999 return StmtError();
6000
6001 // Otherwise, just keep processing substatements and fail later.
6002 SubStmtInvalid = true;
6003 continue;
6004 }
Mike Stump11289f42009-09-09 15:08:12 +00006005
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006006 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006007 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 }
Mike Stump11289f42009-09-09 15:08:12 +00006009
John McCall1ababa62010-08-27 19:56:05 +00006010 if (SubStmtInvalid)
6011 return StmtError();
6012
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 if (!getDerived().AlwaysRebuild() &&
6014 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006015 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006016
6017 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006018 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006019 S->getRBracLoc(),
6020 IsStmtExpr);
6021}
Mike Stump11289f42009-09-09 15:08:12 +00006022
Douglas Gregorebe10102009-08-20 07:17:43 +00006023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006024StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006025TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006026 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006027 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006028 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6029 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006030
Eli Friedman06577382009-11-19 03:14:00 +00006031 // Transform the left-hand case value.
6032 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006033 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006034 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006036
Eli Friedman06577382009-11-19 03:14:00 +00006037 // Transform the right-hand case value (for the GNU case-range extension).
6038 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006039 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006040 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006041 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006042 }
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregorebe10102009-08-20 07:17:43 +00006044 // Build the case statement.
6045 // Case statements are always rebuilt so that they will attached to their
6046 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006047 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006048 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006049 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006050 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006051 S->getColonLoc());
6052 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006053 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006054
Douglas Gregorebe10102009-08-20 07:17:43 +00006055 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006056 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006057 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006058 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006059
Douglas Gregorebe10102009-08-20 07:17:43 +00006060 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006061 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006062}
6063
6064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006065StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006066TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006067 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006068 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006069 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregorebe10102009-08-20 07:17:43 +00006072 // Default statements are always rebuilt
6073 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006074 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006075}
Mike Stump11289f42009-09-09 15:08:12 +00006076
Douglas Gregorebe10102009-08-20 07:17:43 +00006077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006078StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006079TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006080 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006081 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006082 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006083
Chris Lattnercab02a62011-02-17 20:34:02 +00006084 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6085 S->getDecl());
6086 if (!LD)
6087 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006088
6089
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006091 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006092 cast<LabelDecl>(LD), SourceLocation(),
6093 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006094}
Mike Stump11289f42009-09-09 15:08:12 +00006095
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006096template <typename Derived>
6097const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6098 if (!R)
6099 return R;
6100
6101 switch (R->getKind()) {
6102// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6103#define ATTR(X)
6104#define PRAGMA_SPELLING_ATTR(X) \
6105 case attr::X: \
6106 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6107#include "clang/Basic/AttrList.inc"
6108 default:
6109 return R;
6110 }
6111}
6112
6113template <typename Derived>
6114StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6115 bool AttrsChanged = false;
6116 SmallVector<const Attr *, 1> Attrs;
6117
6118 // Visit attributes and keep track if any are transformed.
6119 for (const auto *I : S->getAttrs()) {
6120 const Attr *R = getDerived().TransformAttr(I);
6121 AttrsChanged |= (I != R);
6122 Attrs.push_back(R);
6123 }
6124
Richard Smithc202b282012-04-14 00:33:13 +00006125 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6126 if (SubStmt.isInvalid())
6127 return StmtError();
6128
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006129 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006130 return S;
6131
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006132 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006133 SubStmt.get());
6134}
6135
6136template<typename Derived>
6137StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006138TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006140 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006141 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006142 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006143 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006144 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006145 getDerived().TransformDefinition(
6146 S->getConditionVariable()->getLocation(),
6147 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006148 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006149 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006150 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006151 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006152
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006153 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006154 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006155
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006156 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006157 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006158 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006159 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006160 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006161 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006162
John McCallb268a282010-08-23 23:25:46 +00006163 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006164 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006166
Richard Trieu43b4c822016-01-06 21:11:18 +00006167 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get(), S->getIfLoc()));
John McCallb268a282010-08-23 23:25:46 +00006168 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006169 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006170
Douglas Gregorebe10102009-08-20 07:17:43 +00006171 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006172 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006173 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006174 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006175
Douglas Gregorebe10102009-08-20 07:17:43 +00006176 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006177 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006180
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006182 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006183 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006184 Then.get() == S->getThen() &&
6185 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006186 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006187
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006188 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006189 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006190 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006191}
6192
6193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006194StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006195TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006196 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006197 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006198 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006199 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006200 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006201 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006202 getDerived().TransformDefinition(
6203 S->getConditionVariable()->getLocation(),
6204 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006205 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006207 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006208 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006209
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006210 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006211 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006212 }
Mike Stump11289f42009-09-09 15:08:12 +00006213
Douglas Gregorebe10102009-08-20 07:17:43 +00006214 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006215 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006216 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006217 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006218 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006220
Douglas Gregorebe10102009-08-20 07:17:43 +00006221 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006222 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006223 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006224 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006225
Douglas Gregorebe10102009-08-20 07:17:43 +00006226 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006227 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6228 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006229}
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregorebe10102009-08-20 07:17:43 +00006231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006232StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006233TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006234 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006235 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006236 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006237 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006238 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006239 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006240 getDerived().TransformDefinition(
6241 S->getConditionVariable()->getLocation(),
6242 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006243 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006244 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006245 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006246 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006247
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006248 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006249 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006250
6251 if (S->getCond()) {
6252 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006253 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6254 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006255 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006256 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006257 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006258 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006259 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006260 }
Mike Stump11289f42009-09-09 15:08:12 +00006261
Richard Trieu43b4c822016-01-06 21:11:18 +00006262 Sema::FullExprArg FullCond(
6263 getSema().MakeFullExpr(Cond.get(), S->getWhileLoc()));
John McCallb268a282010-08-23 23:25:46 +00006264 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006265 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006266
Douglas Gregorebe10102009-08-20 07:17:43 +00006267 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006268 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006269 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006270 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregorebe10102009-08-20 07:17:43 +00006272 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006273 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006274 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006275 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006276 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006278 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006279 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006280}
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregorebe10102009-08-20 07:17:43 +00006282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006283StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006284TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006285 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006286 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006287 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006288 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006290 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006291 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006292 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006293 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006294
Douglas Gregorebe10102009-08-20 07:17:43 +00006295 if (!getDerived().AlwaysRebuild() &&
6296 Cond.get() == S->getCond() &&
6297 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006298 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006299
John McCallb268a282010-08-23 23:25:46 +00006300 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6301 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006302 S->getRParenLoc());
6303}
Mike Stump11289f42009-09-09 15:08:12 +00006304
Douglas Gregorebe10102009-08-20 07:17:43 +00006305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006306StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006307TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006308 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006309 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006310 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006311 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006312
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006313 // In OpenMP loop region loop control variable must be captured and be
6314 // private. Perform analysis of first part (if any).
6315 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6316 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6317
Douglas Gregorebe10102009-08-20 07:17:43 +00006318 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006319 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006320 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006321 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006322 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006323 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006324 getDerived().TransformDefinition(
6325 S->getConditionVariable()->getLocation(),
6326 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006327 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006328 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006329 } else {
6330 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006331
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006332 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006333 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006334
6335 if (S->getCond()) {
6336 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006337 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6338 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006339 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006340 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006342
John McCallb268a282010-08-23 23:25:46 +00006343 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006344 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006345 }
Mike Stump11289f42009-09-09 15:08:12 +00006346
Richard Trieu43b4c822016-01-06 21:11:18 +00006347 Sema::FullExprArg FullCond(
6348 getSema().MakeFullExpr(Cond.get(), S->getForLoc()));
John McCallb268a282010-08-23 23:25:46 +00006349 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006350 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006351
Douglas Gregorebe10102009-08-20 07:17:43 +00006352 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006353 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006354 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006355 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006356
Richard Smith945f8d32013-01-14 22:39:08 +00006357 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006358 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006359 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006360
Douglas Gregorebe10102009-08-20 07:17:43 +00006361 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006362 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006363 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006364 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006365
Douglas Gregorebe10102009-08-20 07:17:43 +00006366 if (!getDerived().AlwaysRebuild() &&
6367 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006368 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006369 Inc.get() == S->getInc() &&
6370 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006371 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006372
Douglas Gregorebe10102009-08-20 07:17:43 +00006373 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006374 Init.get(), FullCond, ConditionVar,
6375 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006376}
6377
6378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006379StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006380TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006381 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6382 S->getLabel());
6383 if (!LD)
6384 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006385
Douglas Gregorebe10102009-08-20 07:17:43 +00006386 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006387 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006388 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006389}
6390
6391template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006392StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006393TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006394 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006395 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006396 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006397 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006398
Douglas Gregorebe10102009-08-20 07:17:43 +00006399 if (!getDerived().AlwaysRebuild() &&
6400 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006401 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006402
6403 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006404 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006405}
6406
6407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006408StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006409TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006410 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006411}
Mike Stump11289f42009-09-09 15:08:12 +00006412
Douglas Gregorebe10102009-08-20 07:17:43 +00006413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006414StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006415TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006416 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006417}
Mike Stump11289f42009-09-09 15:08:12 +00006418
Douglas Gregorebe10102009-08-20 07:17:43 +00006419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006420StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006421TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006422 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6423 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006424 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006425 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006426
Mike Stump11289f42009-09-09 15:08:12 +00006427 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006428 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006429 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006430}
Mike Stump11289f42009-09-09 15:08:12 +00006431
Douglas Gregorebe10102009-08-20 07:17:43 +00006432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006433StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006434TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006435 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006436 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006437 for (auto *D : S->decls()) {
6438 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006439 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006440 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006441
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006442 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006443 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregorebe10102009-08-20 07:17:43 +00006445 Decls.push_back(Transformed);
6446 }
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregorebe10102009-08-20 07:17:43 +00006448 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006449 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006450
Rafael Espindolaab417692013-07-09 12:05:01 +00006451 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006452}
Mike Stump11289f42009-09-09 15:08:12 +00006453
Douglas Gregorebe10102009-08-20 07:17:43 +00006454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006455StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006456TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006457
Benjamin Kramerf0623432012-08-23 22:51:59 +00006458 SmallVector<Expr*, 8> Constraints;
6459 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006460 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006461
John McCalldadc5752010-08-24 06:29:42 +00006462 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006463 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006464
6465 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006466
Anders Carlssonaaeef072010-01-24 05:50:09 +00006467 // Go through the outputs.
6468 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006469 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006470
Anders Carlssonaaeef072010-01-24 05:50:09 +00006471 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006472 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006473
Anders Carlssonaaeef072010-01-24 05:50:09 +00006474 // Transform the output expr.
6475 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006476 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006477 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006478 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006479
Anders Carlssonaaeef072010-01-24 05:50:09 +00006480 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006481
John McCallb268a282010-08-23 23:25:46 +00006482 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006483 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006484
Anders Carlssonaaeef072010-01-24 05:50:09 +00006485 // Go through the inputs.
6486 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006487 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006488
Anders Carlssonaaeef072010-01-24 05:50:09 +00006489 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006490 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006491
Anders Carlssonaaeef072010-01-24 05:50:09 +00006492 // Transform the input expr.
6493 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006494 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006495 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006496 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006497
Anders Carlssonaaeef072010-01-24 05:50:09 +00006498 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006499
John McCallb268a282010-08-23 23:25:46 +00006500 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006501 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006502
Anders Carlssonaaeef072010-01-24 05:50:09 +00006503 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006504 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006505
6506 // Go through the clobbers.
6507 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006508 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006509
6510 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006511 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006512 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6513 S->isVolatile(), S->getNumOutputs(),
6514 S->getNumInputs(), Names.data(),
6515 Constraints, Exprs, AsmString.get(),
6516 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006517}
6518
Chad Rosier32503022012-06-11 20:47:18 +00006519template<typename Derived>
6520StmtResult
6521TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006522 ArrayRef<Token> AsmToks =
6523 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006524
John McCallf413f5e2013-05-03 00:10:13 +00006525 bool HadError = false, HadChange = false;
6526
6527 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6528 SmallVector<Expr*, 8> TransformedExprs;
6529 TransformedExprs.reserve(SrcExprs.size());
6530 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6531 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6532 if (!Result.isUsable()) {
6533 HadError = true;
6534 } else {
6535 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006536 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006537 }
6538 }
6539
6540 if (HadError) return StmtError();
6541 if (!HadChange && !getDerived().AlwaysRebuild())
6542 return Owned(S);
6543
Chad Rosierb6f46c12012-08-15 16:53:30 +00006544 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006545 AsmToks, S->getAsmString(),
6546 S->getNumOutputs(), S->getNumInputs(),
6547 S->getAllConstraints(), S->getClobbers(),
6548 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006549}
Douglas Gregorebe10102009-08-20 07:17:43 +00006550
Richard Smith9f690bd2015-10-27 06:02:45 +00006551// C++ Coroutines TS
6552
6553template<typename Derived>
6554StmtResult
6555TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6556 // The coroutine body should be re-formed by the caller if necessary.
6557 return getDerived().TransformStmt(S->getBody());
6558}
6559
6560template<typename Derived>
6561StmtResult
6562TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6563 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6564 /*NotCopyInit*/false);
6565 if (Result.isInvalid())
6566 return StmtError();
6567
6568 // Always rebuild; we don't know if this needs to be injected into a new
6569 // context or if the promise type has changed.
6570 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6571}
6572
6573template<typename Derived>
6574ExprResult
6575TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6576 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6577 /*NotCopyInit*/false);
6578 if (Result.isInvalid())
6579 return ExprError();
6580
6581 // Always rebuild; we don't know if this needs to be injected into a new
6582 // context or if the promise type has changed.
6583 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6584}
6585
6586template<typename Derived>
6587ExprResult
6588TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6589 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6590 /*NotCopyInit*/false);
6591 if (Result.isInvalid())
6592 return ExprError();
6593
6594 // Always rebuild; we don't know if this needs to be injected into a new
6595 // context or if the promise type has changed.
6596 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6597}
6598
6599// Objective-C Statements.
6600
Douglas Gregorebe10102009-08-20 07:17:43 +00006601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006602StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006603TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006604 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006605 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006606 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006607 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006608
Douglas Gregor96c79492010-04-23 22:50:49 +00006609 // Transform the @catch statements (if present).
6610 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006611 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006612 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006613 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006614 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006615 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006616 if (Catch.get() != S->getCatchStmt(I))
6617 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006618 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006619 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006620
Douglas Gregor306de2f2010-04-22 23:59:56 +00006621 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006622 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006623 if (S->getFinallyStmt()) {
6624 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6625 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006626 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006627 }
6628
6629 // If nothing changed, just retain this statement.
6630 if (!getDerived().AlwaysRebuild() &&
6631 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006632 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006633 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006634 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006635
Douglas Gregor306de2f2010-04-22 23:59:56 +00006636 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006637 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006638 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006639}
Mike Stump11289f42009-09-09 15:08:12 +00006640
Douglas Gregorebe10102009-08-20 07:17:43 +00006641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006642StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006643TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006644 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006645 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006646 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006647 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006648 if (FromVar->getTypeSourceInfo()) {
6649 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6650 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006651 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006652 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006653
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006654 QualType T;
6655 if (TSInfo)
6656 T = TSInfo->getType();
6657 else {
6658 T = getDerived().TransformType(FromVar->getType());
6659 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006660 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006662
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006663 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6664 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006667
John McCalldadc5752010-08-24 06:29:42 +00006668 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006669 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006670 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006671
6672 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006673 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006674 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006675}
Mike Stump11289f42009-09-09 15:08:12 +00006676
Douglas Gregorebe10102009-08-20 07:17:43 +00006677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006678StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006679TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006680 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006681 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006682 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006683 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006684
Douglas Gregor306de2f2010-04-22 23:59:56 +00006685 // If nothing changed, just retain this statement.
6686 if (!getDerived().AlwaysRebuild() &&
6687 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006688 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006689
6690 // Build a new statement.
6691 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006692 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006693}
Mike Stump11289f42009-09-09 15:08:12 +00006694
Douglas Gregorebe10102009-08-20 07:17:43 +00006695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006696StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006697TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006698 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006699 if (S->getThrowExpr()) {
6700 Operand = getDerived().TransformExpr(S->getThrowExpr());
6701 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006702 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006703 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006704
Douglas Gregor2900c162010-04-22 21:44:01 +00006705 if (!getDerived().AlwaysRebuild() &&
6706 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006707 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006708
John McCallb268a282010-08-23 23:25:46 +00006709 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006710}
Mike Stump11289f42009-09-09 15:08:12 +00006711
Douglas Gregorebe10102009-08-20 07:17:43 +00006712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006713StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006714TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006715 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006716 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006717 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006718 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006719 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006720 Object =
6721 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6722 Object.get());
6723 if (Object.isInvalid())
6724 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006725
Douglas Gregor6148de72010-04-22 22:01:21 +00006726 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006727 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006728 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006729 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006730
Douglas Gregor6148de72010-04-22 22:01:21 +00006731 // If nothing change, just retain the current statement.
6732 if (!getDerived().AlwaysRebuild() &&
6733 Object.get() == S->getSynchExpr() &&
6734 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006735 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006736
6737 // Build a new statement.
6738 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006739 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006740}
6741
6742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006743StmtResult
John McCall31168b02011-06-15 23:02:42 +00006744TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6745 ObjCAutoreleasePoolStmt *S) {
6746 // Transform the body.
6747 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6748 if (Body.isInvalid())
6749 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006750
John McCall31168b02011-06-15 23:02:42 +00006751 // If nothing changed, just retain this statement.
6752 if (!getDerived().AlwaysRebuild() &&
6753 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006754 return S;
John McCall31168b02011-06-15 23:02:42 +00006755
6756 // Build a new statement.
6757 return getDerived().RebuildObjCAutoreleasePoolStmt(
6758 S->getAtLoc(), Body.get());
6759}
6760
6761template<typename Derived>
6762StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006763TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006764 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006765 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006766 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006767 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006768 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
Douglas Gregorf68a5082010-04-22 23:10:45 +00006770 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006771 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006772 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006773 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006774
Douglas Gregorf68a5082010-04-22 23:10:45 +00006775 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006776 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006777 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006779
Douglas Gregorf68a5082010-04-22 23:10:45 +00006780 // If nothing changed, just retain this statement.
6781 if (!getDerived().AlwaysRebuild() &&
6782 Element.get() == S->getElement() &&
6783 Collection.get() == S->getCollection() &&
6784 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006785 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006786
Douglas Gregorf68a5082010-04-22 23:10:45 +00006787 // Build a new statement.
6788 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006789 Element.get(),
6790 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006791 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006792 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006793}
6794
David Majnemer5f7efef2013-10-15 09:50:08 +00006795template <typename Derived>
6796StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006797 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006798 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006799 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6800 TypeSourceInfo *T =
6801 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006802 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006803 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006804
David Majnemer5f7efef2013-10-15 09:50:08 +00006805 Var = getDerived().RebuildExceptionDecl(
6806 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6807 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006808 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006809 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006810 }
Mike Stump11289f42009-09-09 15:08:12 +00006811
Douglas Gregorebe10102009-08-20 07:17:43 +00006812 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006813 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006814 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006815 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006816
David Majnemer5f7efef2013-10-15 09:50:08 +00006817 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006818 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006819 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006820
David Majnemer5f7efef2013-10-15 09:50:08 +00006821 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006822}
Mike Stump11289f42009-09-09 15:08:12 +00006823
David Majnemer5f7efef2013-10-15 09:50:08 +00006824template <typename Derived>
6825StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006826 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006827 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006828 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006829 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006830
Douglas Gregorebe10102009-08-20 07:17:43 +00006831 // Transform the handlers.
6832 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006833 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006834 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006835 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006836 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006837 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006838
Douglas Gregorebe10102009-08-20 07:17:43 +00006839 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006840 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006841 }
Mike Stump11289f42009-09-09 15:08:12 +00006842
David Majnemer5f7efef2013-10-15 09:50:08 +00006843 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006844 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006845 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006846
John McCallb268a282010-08-23 23:25:46 +00006847 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006848 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006849}
Mike Stump11289f42009-09-09 15:08:12 +00006850
Richard Smith02e85f32011-04-14 22:09:26 +00006851template<typename Derived>
6852StmtResult
6853TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6854 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6855 if (Range.isInvalid())
6856 return StmtError();
6857
6858 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6859 if (BeginEnd.isInvalid())
6860 return StmtError();
6861
6862 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6863 if (Cond.isInvalid())
6864 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006865 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006866 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006867 if (Cond.isInvalid())
6868 return StmtError();
6869 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006870 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006871
6872 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6873 if (Inc.isInvalid())
6874 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006875 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006876 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006877
6878 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6879 if (LoopVar.isInvalid())
6880 return StmtError();
6881
6882 StmtResult NewStmt = S;
6883 if (getDerived().AlwaysRebuild() ||
6884 Range.get() != S->getRangeStmt() ||
6885 BeginEnd.get() != S->getBeginEndStmt() ||
6886 Cond.get() != S->getCond() ||
6887 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006888 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006889 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006890 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006891 S->getColonLoc(), Range.get(),
6892 BeginEnd.get(), Cond.get(),
6893 Inc.get(), LoopVar.get(),
6894 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006895 if (NewStmt.isInvalid())
6896 return StmtError();
6897 }
Richard Smith02e85f32011-04-14 22:09:26 +00006898
6899 StmtResult Body = getDerived().TransformStmt(S->getBody());
6900 if (Body.isInvalid())
6901 return StmtError();
6902
6903 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6904 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006905 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006906 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006907 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006908 S->getColonLoc(), Range.get(),
6909 BeginEnd.get(), Cond.get(),
6910 Inc.get(), LoopVar.get(),
6911 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006912 if (NewStmt.isInvalid())
6913 return StmtError();
6914 }
Richard Smith02e85f32011-04-14 22:09:26 +00006915
6916 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006917 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006918
6919 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6920}
6921
John Wiegley1c0675e2011-04-28 01:08:34 +00006922template<typename Derived>
6923StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006924TreeTransform<Derived>::TransformMSDependentExistsStmt(
6925 MSDependentExistsStmt *S) {
6926 // Transform the nested-name-specifier, if any.
6927 NestedNameSpecifierLoc QualifierLoc;
6928 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006929 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006930 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6931 if (!QualifierLoc)
6932 return StmtError();
6933 }
6934
6935 // Transform the declaration name.
6936 DeclarationNameInfo NameInfo = S->getNameInfo();
6937 if (NameInfo.getName()) {
6938 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6939 if (!NameInfo.getName())
6940 return StmtError();
6941 }
6942
6943 // Check whether anything changed.
6944 if (!getDerived().AlwaysRebuild() &&
6945 QualifierLoc == S->getQualifierLoc() &&
6946 NameInfo.getName() == S->getNameInfo().getName())
6947 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006948
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006949 // Determine whether this name exists, if we can.
6950 CXXScopeSpec SS;
6951 SS.Adopt(QualifierLoc);
6952 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006953 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006954 case Sema::IER_Exists:
6955 if (S->isIfExists())
6956 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006957
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006958 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6959
6960 case Sema::IER_DoesNotExist:
6961 if (S->isIfNotExists())
6962 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006963
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006964 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006965
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006966 case Sema::IER_Dependent:
6967 Dependent = true;
6968 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006969
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006970 case Sema::IER_Error:
6971 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006972 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006973
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006974 // We need to continue with the instantiation, so do so now.
6975 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6976 if (SubStmt.isInvalid())
6977 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006978
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006979 // If we have resolved the name, just transform to the substatement.
6980 if (!Dependent)
6981 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006982
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006983 // The name is still dependent, so build a dependent expression again.
6984 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6985 S->isIfExists(),
6986 QualifierLoc,
6987 NameInfo,
6988 SubStmt.get());
6989}
6990
6991template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006992ExprResult
6993TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6994 NestedNameSpecifierLoc QualifierLoc;
6995 if (E->getQualifierLoc()) {
6996 QualifierLoc
6997 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6998 if (!QualifierLoc)
6999 return ExprError();
7000 }
7001
7002 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7003 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7004 if (!PD)
7005 return ExprError();
7006
7007 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7008 if (Base.isInvalid())
7009 return ExprError();
7010
7011 return new (SemaRef.getASTContext())
7012 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7013 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7014 QualifierLoc, E->getMemberLoc());
7015}
7016
David Majnemerfad8f482013-10-15 09:33:02 +00007017template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007018ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7019 MSPropertySubscriptExpr *E) {
7020 auto BaseRes = getDerived().TransformExpr(E->getBase());
7021 if (BaseRes.isInvalid())
7022 return ExprError();
7023 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7024 if (IdxRes.isInvalid())
7025 return ExprError();
7026
7027 if (!getDerived().AlwaysRebuild() &&
7028 BaseRes.get() == E->getBase() &&
7029 IdxRes.get() == E->getIdx())
7030 return E;
7031
7032 return getDerived().RebuildArraySubscriptExpr(
7033 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7034}
7035
7036template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007037StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007038 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007039 if (TryBlock.isInvalid())
7040 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007041
7042 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007043 if (Handler.isInvalid())
7044 return StmtError();
7045
David Majnemerfad8f482013-10-15 09:33:02 +00007046 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7047 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007048 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007049
Warren Huntf6be4cb2014-07-25 20:52:51 +00007050 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7051 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007052}
7053
David Majnemerfad8f482013-10-15 09:33:02 +00007054template <typename Derived>
7055StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007056 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007057 if (Block.isInvalid())
7058 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007059
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007060 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007061}
7062
David Majnemerfad8f482013-10-15 09:33:02 +00007063template <typename Derived>
7064StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007065 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007066 if (FilterExpr.isInvalid())
7067 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007068
David Majnemer7e755502013-10-15 09:30:14 +00007069 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007070 if (Block.isInvalid())
7071 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007072
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007073 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7074 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007075}
7076
David Majnemerfad8f482013-10-15 09:33:02 +00007077template <typename Derived>
7078StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7079 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007080 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7081 else
7082 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7083}
7084
Nico Weber9b982072014-07-07 00:12:30 +00007085template<typename Derived>
7086StmtResult
7087TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7088 return S;
7089}
7090
Alexander Musman64d33f12014-06-04 07:53:32 +00007091//===----------------------------------------------------------------------===//
7092// OpenMP directive transformation
7093//===----------------------------------------------------------------------===//
7094template <typename Derived>
7095StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7096 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007097
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007098 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007099 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007100 ArrayRef<OMPClause *> Clauses = D->clauses();
7101 TClauses.reserve(Clauses.size());
7102 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7103 I != E; ++I) {
7104 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007105 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007106 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007107 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007108 if (Clause)
7109 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007110 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007111 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007112 }
7113 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007114 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007115 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007116 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7117 /*CurScope=*/nullptr);
7118 StmtResult Body;
7119 {
7120 Sema::CompoundScopeRAII CompoundScope(getSema());
7121 Body = getDerived().TransformStmt(
7122 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7123 }
7124 AssociatedStmt =
7125 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007126 if (AssociatedStmt.isInvalid()) {
7127 return StmtError();
7128 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007129 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007130 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007131 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007132 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007133
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007134 // Transform directive name for 'omp critical' directive.
7135 DeclarationNameInfo DirName;
7136 if (D->getDirectiveKind() == OMPD_critical) {
7137 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7138 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7139 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007140 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7141 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7142 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007143 } else if (D->getDirectiveKind() == OMPD_cancel) {
7144 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007145 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007146
Alexander Musman64d33f12014-06-04 07:53:32 +00007147 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007148 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7149 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007150}
7151
Alexander Musman64d33f12014-06-04 07:53:32 +00007152template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007153StmtResult
7154TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7155 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007156 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7157 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007158 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7159 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7160 return Res;
7161}
7162
Alexander Musman64d33f12014-06-04 07:53:32 +00007163template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007164StmtResult
7165TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7166 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007167 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7168 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007169 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7170 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007171 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007172}
7173
Alexey Bataevf29276e2014-06-18 04:14:57 +00007174template <typename Derived>
7175StmtResult
7176TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7177 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007178 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7179 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007180 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7181 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7182 return Res;
7183}
7184
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007185template <typename Derived>
7186StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007187TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7188 DeclarationNameInfo DirName;
7189 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7190 D->getLocStart());
7191 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7192 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7193 return Res;
7194}
7195
7196template <typename Derived>
7197StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007198TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7199 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007200 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7201 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007202 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7203 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7204 return Res;
7205}
7206
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007207template <typename Derived>
7208StmtResult
7209TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7210 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007211 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7212 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007213 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7214 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7215 return Res;
7216}
7217
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007218template <typename Derived>
7219StmtResult
7220TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7221 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007222 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7223 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007224 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7225 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7226 return Res;
7227}
7228
Alexey Bataev4acb8592014-07-07 13:01:15 +00007229template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007230StmtResult
7231TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7232 DeclarationNameInfo DirName;
7233 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7234 D->getLocStart());
7235 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7236 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7237 return Res;
7238}
7239
7240template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007241StmtResult
7242TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7243 getDerived().getSema().StartOpenMPDSABlock(
7244 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7245 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7246 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7247 return Res;
7248}
7249
7250template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007251StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7252 OMPParallelForDirective *D) {
7253 DeclarationNameInfo DirName;
7254 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7255 nullptr, D->getLocStart());
7256 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7257 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7258 return Res;
7259}
7260
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007261template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007262StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7263 OMPParallelForSimdDirective *D) {
7264 DeclarationNameInfo DirName;
7265 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7266 nullptr, D->getLocStart());
7267 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7268 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7269 return Res;
7270}
7271
7272template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007273StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7274 OMPParallelSectionsDirective *D) {
7275 DeclarationNameInfo DirName;
7276 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7277 nullptr, D->getLocStart());
7278 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7279 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7280 return Res;
7281}
7282
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007283template <typename Derived>
7284StmtResult
7285TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7286 DeclarationNameInfo DirName;
7287 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7288 D->getLocStart());
7289 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7290 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7291 return Res;
7292}
7293
Alexey Bataev68446b72014-07-18 07:47:19 +00007294template <typename Derived>
7295StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7296 OMPTaskyieldDirective *D) {
7297 DeclarationNameInfo DirName;
7298 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7299 D->getLocStart());
7300 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7301 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7302 return Res;
7303}
7304
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007305template <typename Derived>
7306StmtResult
7307TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7308 DeclarationNameInfo DirName;
7309 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7310 D->getLocStart());
7311 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7312 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7313 return Res;
7314}
7315
Alexey Bataev2df347a2014-07-18 10:17:07 +00007316template <typename Derived>
7317StmtResult
7318TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7319 DeclarationNameInfo DirName;
7320 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7321 D->getLocStart());
7322 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7323 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7324 return Res;
7325}
7326
Alexey Bataev6125da92014-07-21 11:26:11 +00007327template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007328StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7329 OMPTaskgroupDirective *D) {
7330 DeclarationNameInfo DirName;
7331 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7332 D->getLocStart());
7333 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7334 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7335 return Res;
7336}
7337
7338template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007339StmtResult
7340TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7341 DeclarationNameInfo DirName;
7342 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7343 D->getLocStart());
7344 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7345 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7346 return Res;
7347}
7348
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007349template <typename Derived>
7350StmtResult
7351TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7352 DeclarationNameInfo DirName;
7353 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7354 D->getLocStart());
7355 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7356 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7357 return Res;
7358}
7359
Alexey Bataev0162e452014-07-22 10:10:35 +00007360template <typename Derived>
7361StmtResult
7362TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7363 DeclarationNameInfo DirName;
7364 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7365 D->getLocStart());
7366 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7367 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7368 return Res;
7369}
7370
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007371template <typename Derived>
7372StmtResult
7373TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7374 DeclarationNameInfo DirName;
7375 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7376 D->getLocStart());
7377 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7378 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7379 return Res;
7380}
7381
Alexey Bataev13314bf2014-10-09 04:18:56 +00007382template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007383StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7384 OMPTargetDataDirective *D) {
7385 DeclarationNameInfo DirName;
7386 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7387 D->getLocStart());
7388 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7389 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7390 return Res;
7391}
7392
7393template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007394StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7395 OMPTargetEnterDataDirective *D) {
7396 DeclarationNameInfo DirName;
7397 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7398 nullptr, D->getLocStart());
7399 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7400 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7401 return Res;
7402}
7403
7404template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007405StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7406 OMPTargetExitDataDirective *D) {
7407 DeclarationNameInfo DirName;
7408 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7409 nullptr, D->getLocStart());
7410 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7411 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7412 return Res;
7413}
7414
7415template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007416StmtResult
7417TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7418 DeclarationNameInfo DirName;
7419 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7420 D->getLocStart());
7421 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7422 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7423 return Res;
7424}
7425
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007426template <typename Derived>
7427StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7428 OMPCancellationPointDirective *D) {
7429 DeclarationNameInfo DirName;
7430 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7431 nullptr, D->getLocStart());
7432 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7433 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7434 return Res;
7435}
7436
Alexey Bataev80909872015-07-02 11:25:17 +00007437template <typename Derived>
7438StmtResult
7439TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7440 DeclarationNameInfo DirName;
7441 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7442 D->getLocStart());
7443 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7444 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7445 return Res;
7446}
7447
Alexey Bataev49f6e782015-12-01 04:18:41 +00007448template <typename Derived>
7449StmtResult
7450TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7451 DeclarationNameInfo DirName;
7452 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7453 D->getLocStart());
7454 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7455 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7456 return Res;
7457}
7458
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007459template <typename Derived>
7460StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7461 OMPTaskLoopSimdDirective *D) {
7462 DeclarationNameInfo DirName;
7463 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7464 nullptr, D->getLocStart());
7465 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7466 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7467 return Res;
7468}
7469
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007470template <typename Derived>
7471StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7472 OMPDistributeDirective *D) {
7473 DeclarationNameInfo DirName;
7474 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7475 D->getLocStart());
7476 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7477 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7478 return Res;
7479}
7480
Alexander Musman64d33f12014-06-04 07:53:32 +00007481//===----------------------------------------------------------------------===//
7482// OpenMP clause transformation
7483//===----------------------------------------------------------------------===//
7484template <typename Derived>
7485OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007486 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7487 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007488 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007489 return getDerived().RebuildOMPIfClause(
7490 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7491 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007492}
7493
Alexander Musman64d33f12014-06-04 07:53:32 +00007494template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007495OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7496 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7497 if (Cond.isInvalid())
7498 return nullptr;
7499 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7500 C->getLParenLoc(), C->getLocEnd());
7501}
7502
7503template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007504OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007505TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7506 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7507 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007508 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007509 return getDerived().RebuildOMPNumThreadsClause(
7510 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007511}
7512
Alexey Bataev62c87d22014-03-21 04:51:18 +00007513template <typename Derived>
7514OMPClause *
7515TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7516 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7517 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007518 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007519 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007520 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007521}
7522
Alexander Musman8bd31e62014-05-27 15:12:19 +00007523template <typename Derived>
7524OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007525TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7526 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7527 if (E.isInvalid())
7528 return nullptr;
7529 return getDerived().RebuildOMPSimdlenClause(
7530 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7531}
7532
7533template <typename Derived>
7534OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007535TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7536 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7537 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007538 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007539 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007540 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007541}
7542
Alexander Musman64d33f12014-06-04 07:53:32 +00007543template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007544OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007545TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007546 return getDerived().RebuildOMPDefaultClause(
7547 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7548 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007549}
7550
Alexander Musman64d33f12014-06-04 07:53:32 +00007551template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007552OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007553TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007554 return getDerived().RebuildOMPProcBindClause(
7555 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7556 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007557}
7558
Alexander Musman64d33f12014-06-04 07:53:32 +00007559template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007560OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007561TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7562 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7563 if (E.isInvalid())
7564 return nullptr;
7565 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007566 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007567 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007568 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007569 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7570}
7571
7572template <typename Derived>
7573OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007574TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007575 ExprResult E;
7576 if (auto *Num = C->getNumForLoops()) {
7577 E = getDerived().TransformExpr(Num);
7578 if (E.isInvalid())
7579 return nullptr;
7580 }
7581 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7582 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007583}
7584
7585template <typename Derived>
7586OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007587TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7588 // No need to rebuild this clause, no template-dependent parameters.
7589 return C;
7590}
7591
7592template <typename Derived>
7593OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007594TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7595 // No need to rebuild this clause, no template-dependent parameters.
7596 return C;
7597}
7598
7599template <typename Derived>
7600OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007601TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7602 // No need to rebuild this clause, no template-dependent parameters.
7603 return C;
7604}
7605
7606template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007607OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7608 // No need to rebuild this clause, no template-dependent parameters.
7609 return C;
7610}
7611
7612template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007613OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7614 // No need to rebuild this clause, no template-dependent parameters.
7615 return C;
7616}
7617
7618template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007619OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007620TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7621 // No need to rebuild this clause, no template-dependent parameters.
7622 return C;
7623}
7624
7625template <typename Derived>
7626OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007627TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7628 // No need to rebuild this clause, no template-dependent parameters.
7629 return C;
7630}
7631
7632template <typename Derived>
7633OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007634TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7635 // No need to rebuild this clause, no template-dependent parameters.
7636 return C;
7637}
7638
7639template <typename Derived>
7640OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007641TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7642 // No need to rebuild this clause, no template-dependent parameters.
7643 return C;
7644}
7645
7646template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007647OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7648 // No need to rebuild this clause, no template-dependent parameters.
7649 return C;
7650}
7651
7652template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007653OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007654TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7655 // No need to rebuild this clause, no template-dependent parameters.
7656 return C;
7657}
7658
7659template <typename Derived>
7660OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007661TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007662 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007663 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007664 for (auto *VE : C->varlists()) {
7665 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007666 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007667 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007668 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007669 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007670 return getDerived().RebuildOMPPrivateClause(
7671 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007672}
7673
Alexander Musman64d33f12014-06-04 07:53:32 +00007674template <typename Derived>
7675OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7676 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007677 llvm::SmallVector<Expr *, 16> Vars;
7678 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007679 for (auto *VE : C->varlists()) {
7680 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007681 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007682 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007683 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007684 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007685 return getDerived().RebuildOMPFirstprivateClause(
7686 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007687}
7688
Alexander Musman64d33f12014-06-04 07:53:32 +00007689template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007690OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007691TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7692 llvm::SmallVector<Expr *, 16> Vars;
7693 Vars.reserve(C->varlist_size());
7694 for (auto *VE : C->varlists()) {
7695 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7696 if (EVar.isInvalid())
7697 return nullptr;
7698 Vars.push_back(EVar.get());
7699 }
7700 return getDerived().RebuildOMPLastprivateClause(
7701 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7702}
7703
7704template <typename Derived>
7705OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007706TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7707 llvm::SmallVector<Expr *, 16> Vars;
7708 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007709 for (auto *VE : C->varlists()) {
7710 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007711 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007712 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007713 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007714 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007715 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7716 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007717}
7718
Alexander Musman64d33f12014-06-04 07:53:32 +00007719template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007720OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007721TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7722 llvm::SmallVector<Expr *, 16> Vars;
7723 Vars.reserve(C->varlist_size());
7724 for (auto *VE : C->varlists()) {
7725 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7726 if (EVar.isInvalid())
7727 return nullptr;
7728 Vars.push_back(EVar.get());
7729 }
7730 CXXScopeSpec ReductionIdScopeSpec;
7731 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7732
7733 DeclarationNameInfo NameInfo = C->getNameInfo();
7734 if (NameInfo.getName()) {
7735 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7736 if (!NameInfo.getName())
7737 return nullptr;
7738 }
7739 return getDerived().RebuildOMPReductionClause(
7740 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7741 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7742}
7743
7744template <typename Derived>
7745OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007746TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7747 llvm::SmallVector<Expr *, 16> Vars;
7748 Vars.reserve(C->varlist_size());
7749 for (auto *VE : C->varlists()) {
7750 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7751 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007752 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007753 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007754 }
7755 ExprResult Step = getDerived().TransformExpr(C->getStep());
7756 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007757 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007758 return getDerived().RebuildOMPLinearClause(
7759 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7760 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007761}
7762
Alexander Musman64d33f12014-06-04 07:53:32 +00007763template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007764OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007765TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7766 llvm::SmallVector<Expr *, 16> Vars;
7767 Vars.reserve(C->varlist_size());
7768 for (auto *VE : C->varlists()) {
7769 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7770 if (EVar.isInvalid())
7771 return nullptr;
7772 Vars.push_back(EVar.get());
7773 }
7774 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7775 if (Alignment.isInvalid())
7776 return nullptr;
7777 return getDerived().RebuildOMPAlignedClause(
7778 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7779 C->getColonLoc(), C->getLocEnd());
7780}
7781
Alexander Musman64d33f12014-06-04 07:53:32 +00007782template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007783OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007784TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7785 llvm::SmallVector<Expr *, 16> Vars;
7786 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007787 for (auto *VE : C->varlists()) {
7788 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007789 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007790 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007791 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007792 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007793 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7794 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007795}
7796
Alexey Bataevbae9a792014-06-27 10:37:06 +00007797template <typename Derived>
7798OMPClause *
7799TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7800 llvm::SmallVector<Expr *, 16> Vars;
7801 Vars.reserve(C->varlist_size());
7802 for (auto *VE : C->varlists()) {
7803 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7804 if (EVar.isInvalid())
7805 return nullptr;
7806 Vars.push_back(EVar.get());
7807 }
7808 return getDerived().RebuildOMPCopyprivateClause(
7809 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7810}
7811
Alexey Bataev6125da92014-07-21 11:26:11 +00007812template <typename Derived>
7813OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7814 llvm::SmallVector<Expr *, 16> Vars;
7815 Vars.reserve(C->varlist_size());
7816 for (auto *VE : C->varlists()) {
7817 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7818 if (EVar.isInvalid())
7819 return nullptr;
7820 Vars.push_back(EVar.get());
7821 }
7822 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7823 C->getLParenLoc(), C->getLocEnd());
7824}
7825
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007826template <typename Derived>
7827OMPClause *
7828TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7829 llvm::SmallVector<Expr *, 16> Vars;
7830 Vars.reserve(C->varlist_size());
7831 for (auto *VE : C->varlists()) {
7832 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7833 if (EVar.isInvalid())
7834 return nullptr;
7835 Vars.push_back(EVar.get());
7836 }
7837 return getDerived().RebuildOMPDependClause(
7838 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7839 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7840}
7841
Michael Wonge710d542015-08-07 16:16:36 +00007842template <typename Derived>
7843OMPClause *
7844TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7845 ExprResult E = getDerived().TransformExpr(C->getDevice());
7846 if (E.isInvalid())
7847 return nullptr;
7848 return getDerived().RebuildOMPDeviceClause(
7849 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7850}
7851
Kelvin Li0bff7af2015-11-23 05:32:03 +00007852template <typename Derived>
7853OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7854 llvm::SmallVector<Expr *, 16> Vars;
7855 Vars.reserve(C->varlist_size());
7856 for (auto *VE : C->varlists()) {
7857 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7858 if (EVar.isInvalid())
7859 return nullptr;
7860 Vars.push_back(EVar.get());
7861 }
7862 return getDerived().RebuildOMPMapClause(
7863 C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7864 C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7865 C->getLocEnd());
7866}
7867
Kelvin Li099bb8c2015-11-24 20:50:12 +00007868template <typename Derived>
7869OMPClause *
7870TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7871 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7872 if (E.isInvalid())
7873 return nullptr;
7874 return getDerived().RebuildOMPNumTeamsClause(
7875 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7876}
7877
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007878template <typename Derived>
7879OMPClause *
7880TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7881 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7882 if (E.isInvalid())
7883 return nullptr;
7884 return getDerived().RebuildOMPThreadLimitClause(
7885 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7886}
7887
Alexey Bataeva0569352015-12-01 10:17:31 +00007888template <typename Derived>
7889OMPClause *
7890TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7891 ExprResult E = getDerived().TransformExpr(C->getPriority());
7892 if (E.isInvalid())
7893 return nullptr;
7894 return getDerived().RebuildOMPPriorityClause(
7895 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7896}
7897
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007898template <typename Derived>
7899OMPClause *
7900TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7901 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7902 if (E.isInvalid())
7903 return nullptr;
7904 return getDerived().RebuildOMPGrainsizeClause(
7905 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7906}
7907
Alexey Bataev382967a2015-12-08 12:06:20 +00007908template <typename Derived>
7909OMPClause *
7910TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7911 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7912 if (E.isInvalid())
7913 return nullptr;
7914 return getDerived().RebuildOMPNumTasksClause(
7915 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7916}
7917
Alexey Bataev28c75412015-12-15 08:19:24 +00007918template <typename Derived>
7919OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
7920 ExprResult E = getDerived().TransformExpr(C->getHint());
7921 if (E.isInvalid())
7922 return nullptr;
7923 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
7924 C->getLParenLoc(), C->getLocEnd());
7925}
7926
Carlo Bertollib4adf552016-01-15 18:50:31 +00007927template <typename Derived>
7928OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
7929 OMPDistScheduleClause *C) {
7930 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7931 if (E.isInvalid())
7932 return nullptr;
7933 return getDerived().RebuildOMPDistScheduleClause(
7934 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7935 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7936}
7937
Douglas Gregorebe10102009-08-20 07:17:43 +00007938//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007939// Expression transformation
7940//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007942ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007943TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007944 if (!E->isTypeDependent())
7945 return E;
7946
7947 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7948 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007949}
Mike Stump11289f42009-09-09 15:08:12 +00007950
7951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007953TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007954 NestedNameSpecifierLoc QualifierLoc;
7955 if (E->getQualifierLoc()) {
7956 QualifierLoc
7957 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7958 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007959 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007960 }
John McCallce546572009-12-08 09:08:17 +00007961
7962 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007963 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7964 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007965 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007967
John McCall815039a2010-08-17 21:27:17 +00007968 DeclarationNameInfo NameInfo = E->getNameInfo();
7969 if (NameInfo.getName()) {
7970 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7971 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007972 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007973 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007974
7975 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007976 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007977 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007978 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007979 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007980
7981 // Mark it referenced in the new context regardless.
7982 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007983 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007984
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007985 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007986 }
John McCallce546572009-12-08 09:08:17 +00007987
Craig Topperc3ec1492014-05-26 06:22:03 +00007988 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007989 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007990 TemplateArgs = &TransArgs;
7991 TransArgs.setLAngleLoc(E->getLAngleLoc());
7992 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007993 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7994 E->getNumTemplateArgs(),
7995 TransArgs))
7996 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007997 }
7998
Chad Rosier1dcde962012-08-08 18:46:20 +00007999 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008000 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008001}
Mike Stump11289f42009-09-09 15:08:12 +00008002
Douglas Gregora16548e2009-08-11 05:31:07 +00008003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008005TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008006 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008007}
Mike Stump11289f42009-09-09 15:08:12 +00008008
Douglas Gregora16548e2009-08-11 05:31:07 +00008009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008011TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008012 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008013}
Mike Stump11289f42009-09-09 15:08:12 +00008014
Douglas Gregora16548e2009-08-11 05:31:07 +00008015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008017TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008018 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008019}
Mike Stump11289f42009-09-09 15:08:12 +00008020
Douglas Gregora16548e2009-08-11 05:31:07 +00008021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008023TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008024 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008025}
Mike Stump11289f42009-09-09 15:08:12 +00008026
Douglas Gregora16548e2009-08-11 05:31:07 +00008027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008028ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008029TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008030 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008031}
8032
8033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008034ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008035TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008036 if (FunctionDecl *FD = E->getDirectCallee())
8037 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008038 return SemaRef.MaybeBindToTemporary(E);
8039}
8040
8041template<typename Derived>
8042ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008043TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8044 ExprResult ControllingExpr =
8045 getDerived().TransformExpr(E->getControllingExpr());
8046 if (ControllingExpr.isInvalid())
8047 return ExprError();
8048
Chris Lattner01cf8db2011-07-20 06:58:45 +00008049 SmallVector<Expr *, 4> AssocExprs;
8050 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008051 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8052 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8053 if (TS) {
8054 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8055 if (!AssocType)
8056 return ExprError();
8057 AssocTypes.push_back(AssocType);
8058 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008059 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008060 }
8061
8062 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8063 if (AssocExpr.isInvalid())
8064 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008065 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008066 }
8067
8068 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8069 E->getDefaultLoc(),
8070 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008071 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008072 AssocTypes,
8073 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008074}
8075
8076template<typename Derived>
8077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008078TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008079 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008080 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008081 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008082
Douglas Gregora16548e2009-08-11 05:31:07 +00008083 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008084 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008085
John McCallb268a282010-08-23 23:25:46 +00008086 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008087 E->getRParen());
8088}
8089
Richard Smithdb2630f2012-10-21 03:28:35 +00008090/// \brief The operand of a unary address-of operator has special rules: it's
8091/// allowed to refer to a non-static member of a class even if there's no 'this'
8092/// object available.
8093template<typename Derived>
8094ExprResult
8095TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8096 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008097 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008098 else
8099 return getDerived().TransformExpr(E);
8100}
8101
Mike Stump11289f42009-09-09 15:08:12 +00008102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008103ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008104TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008105 ExprResult SubExpr;
8106 if (E->getOpcode() == UO_AddrOf)
8107 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8108 else
8109 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008110 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008112
Douglas Gregora16548e2009-08-11 05:31:07 +00008113 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008114 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008115
Douglas Gregora16548e2009-08-11 05:31:07 +00008116 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8117 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008118 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008119}
Mike Stump11289f42009-09-09 15:08:12 +00008120
Douglas Gregora16548e2009-08-11 05:31:07 +00008121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008122ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008123TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8124 // Transform the type.
8125 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8126 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008127 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008128
Douglas Gregor882211c2010-04-28 22:16:22 +00008129 // Transform all of the components into components similar to what the
8130 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008131 // FIXME: It would be slightly more efficient in the non-dependent case to
8132 // just map FieldDecls, rather than requiring the rebuilder to look for
8133 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008134 // template code that we don't care.
8135 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008136 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008137 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008138 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008139 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008140 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008141 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008142 Comp.LocStart = ON.getSourceRange().getBegin();
8143 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008144 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008145 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008146 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008147 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008148 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008149 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008150
Douglas Gregor882211c2010-04-28 22:16:22 +00008151 ExprChanged = ExprChanged || Index.get() != FromIndex;
8152 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008153 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008154 break;
8155 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008156
James Y Knight7281c352015-12-29 22:31:18 +00008157 case OffsetOfNode::Field:
8158 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008159 Comp.isBrackets = false;
8160 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008161 if (!Comp.U.IdentInfo)
8162 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008163
Douglas Gregor882211c2010-04-28 22:16:22 +00008164 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008165
James Y Knight7281c352015-12-29 22:31:18 +00008166 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008167 // Will be recomputed during the rebuild.
8168 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008169 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008170
Douglas Gregor882211c2010-04-28 22:16:22 +00008171 Components.push_back(Comp);
8172 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008173
Douglas Gregor882211c2010-04-28 22:16:22 +00008174 // If nothing changed, retain the existing expression.
8175 if (!getDerived().AlwaysRebuild() &&
8176 Type == E->getTypeSourceInfo() &&
8177 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008178 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008179
Douglas Gregor882211c2010-04-28 22:16:22 +00008180 // Build a new offsetof expression.
8181 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008182 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008183}
8184
8185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008186ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008187TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008188 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008189 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008190 return E;
John McCall8d69a212010-11-15 23:31:06 +00008191}
8192
8193template<typename Derived>
8194ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008195TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8196 return E;
8197}
8198
8199template<typename Derived>
8200ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008201TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008202 // Rebuild the syntactic form. The original syntactic form has
8203 // opaque-value expressions in it, so strip those away and rebuild
8204 // the result. This is a really awful way of doing this, but the
8205 // better solution (rebuilding the semantic expressions and
8206 // rebinding OVEs as necessary) doesn't work; we'd need
8207 // TreeTransform to not strip away implicit conversions.
8208 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8209 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008210 if (result.isInvalid()) return ExprError();
8211
8212 // If that gives us a pseudo-object result back, the pseudo-object
8213 // expression must have been an lvalue-to-rvalue conversion which we
8214 // should reapply.
8215 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008216 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008217
8218 return result;
8219}
8220
8221template<typename Derived>
8222ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008223TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8224 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008226 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008227
John McCallbcd03502009-12-07 02:54:59 +00008228 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008229 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008231
John McCall4c98fd82009-11-04 07:28:41 +00008232 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008233 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008234
Peter Collingbournee190dee2011-03-11 19:24:49 +00008235 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8236 E->getKind(),
8237 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008238 }
Mike Stump11289f42009-09-09 15:08:12 +00008239
Eli Friedmane4f22df2012-02-29 04:03:55 +00008240 // C++0x [expr.sizeof]p1:
8241 // The operand is either an expression, which is an unevaluated operand
8242 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008243 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8244 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008245
Reid Kleckner32506ed2014-06-12 23:03:48 +00008246 // Try to recover if we have something like sizeof(T::X) where X is a type.
8247 // Notably, there must be *exactly* one set of parens if X is a type.
8248 TypeSourceInfo *RecoveryTSI = nullptr;
8249 ExprResult SubExpr;
8250 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8251 if (auto *DRE =
8252 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8253 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8254 PE, DRE, false, &RecoveryTSI);
8255 else
8256 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8257
8258 if (RecoveryTSI) {
8259 return getDerived().RebuildUnaryExprOrTypeTrait(
8260 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8261 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008262 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008263
Eli Friedmane4f22df2012-02-29 04:03:55 +00008264 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008265 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008266
Peter Collingbournee190dee2011-03-11 19:24:49 +00008267 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8268 E->getOperatorLoc(),
8269 E->getKind(),
8270 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008271}
Mike Stump11289f42009-09-09 15:08:12 +00008272
Douglas Gregora16548e2009-08-11 05:31:07 +00008273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008275TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008276 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008277 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008278 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008279
John McCalldadc5752010-08-24 06:29:42 +00008280 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008281 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008283
8284
Douglas Gregora16548e2009-08-11 05:31:07 +00008285 if (!getDerived().AlwaysRebuild() &&
8286 LHS.get() == E->getLHS() &&
8287 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008288 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008289
John McCallb268a282010-08-23 23:25:46 +00008290 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008291 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008292 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008293 E->getRBracketLoc());
8294}
Mike Stump11289f42009-09-09 15:08:12 +00008295
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008296template <typename Derived>
8297ExprResult
8298TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8299 ExprResult Base = getDerived().TransformExpr(E->getBase());
8300 if (Base.isInvalid())
8301 return ExprError();
8302
8303 ExprResult LowerBound;
8304 if (E->getLowerBound()) {
8305 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8306 if (LowerBound.isInvalid())
8307 return ExprError();
8308 }
8309
8310 ExprResult Length;
8311 if (E->getLength()) {
8312 Length = getDerived().TransformExpr(E->getLength());
8313 if (Length.isInvalid())
8314 return ExprError();
8315 }
8316
8317 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8318 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8319 return E;
8320
8321 return getDerived().RebuildOMPArraySectionExpr(
8322 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8323 Length.get(), E->getRBracketLoc());
8324}
8325
Mike Stump11289f42009-09-09 15:08:12 +00008326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008328TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008329 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008330 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008332 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008333
8334 // Transform arguments.
8335 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008336 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008337 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008338 &ArgChanged))
8339 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008340
Douglas Gregora16548e2009-08-11 05:31:07 +00008341 if (!getDerived().AlwaysRebuild() &&
8342 Callee.get() == E->getCallee() &&
8343 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008344 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008345
Douglas Gregora16548e2009-08-11 05:31:07 +00008346 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008347 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008348 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008349 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008350 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008351 E->getRParenLoc());
8352}
Mike Stump11289f42009-09-09 15:08:12 +00008353
8354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008356TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008357 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008360
Douglas Gregorea972d32011-02-28 21:54:11 +00008361 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008362 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008363 QualifierLoc
8364 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008365
Douglas Gregorea972d32011-02-28 21:54:11 +00008366 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008367 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008368 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008369 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008370
Eli Friedman2cfcef62009-12-04 06:40:45 +00008371 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008372 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8373 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008374 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008376
John McCall16df1e52010-03-30 21:47:33 +00008377 NamedDecl *FoundDecl = E->getFoundDecl();
8378 if (FoundDecl == E->getMemberDecl()) {
8379 FoundDecl = Member;
8380 } else {
8381 FoundDecl = cast_or_null<NamedDecl>(
8382 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8383 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008384 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008385 }
8386
Douglas Gregora16548e2009-08-11 05:31:07 +00008387 if (!getDerived().AlwaysRebuild() &&
8388 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008389 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008390 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008391 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008392 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008393
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008394 // Mark it referenced in the new context regardless.
8395 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008396 SemaRef.MarkMemberReferenced(E);
8397
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008398 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008399 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008400
John McCall6b51f282009-11-23 01:53:49 +00008401 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008402 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008403 TransArgs.setLAngleLoc(E->getLAngleLoc());
8404 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008405 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8406 E->getNumTemplateArgs(),
8407 TransArgs))
8408 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008409 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008410
Douglas Gregora16548e2009-08-11 05:31:07 +00008411 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008412 SourceLocation FakeOperatorLoc =
8413 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008414
John McCall38836f02010-01-15 08:34:02 +00008415 // FIXME: to do this check properly, we will need to preserve the
8416 // first-qualifier-in-scope here, just in case we had a dependent
8417 // base (and therefore couldn't do the check) and a
8418 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008419 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008420
John McCallb268a282010-08-23 23:25:46 +00008421 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008422 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008423 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008424 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008425 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008426 Member,
John McCall16df1e52010-03-30 21:47:33 +00008427 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008428 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008429 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008430 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008431}
Mike Stump11289f42009-09-09 15:08:12 +00008432
Douglas Gregora16548e2009-08-11 05:31:07 +00008433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008434ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008435TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008436 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008437 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008438 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008439
John McCalldadc5752010-08-24 06:29:42 +00008440 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008441 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008443
Douglas Gregora16548e2009-08-11 05:31:07 +00008444 if (!getDerived().AlwaysRebuild() &&
8445 LHS.get() == E->getLHS() &&
8446 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008447 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008448
Lang Hames5de91cc2012-10-02 04:45:10 +00008449 Sema::FPContractStateRAII FPContractState(getSema());
8450 getSema().FPFeatures.fp_contract = E->isFPContractable();
8451
Douglas Gregora16548e2009-08-11 05:31:07 +00008452 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008453 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008454}
8455
Mike Stump11289f42009-09-09 15:08:12 +00008456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008457ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008458TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008459 CompoundAssignOperator *E) {
8460 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008461}
Mike Stump11289f42009-09-09 15:08:12 +00008462
Douglas Gregora16548e2009-08-11 05:31:07 +00008463template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008464ExprResult TreeTransform<Derived>::
8465TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8466 // Just rebuild the common and RHS expressions and see whether we
8467 // get any changes.
8468
8469 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8470 if (commonExpr.isInvalid())
8471 return ExprError();
8472
8473 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8474 if (rhs.isInvalid())
8475 return ExprError();
8476
8477 if (!getDerived().AlwaysRebuild() &&
8478 commonExpr.get() == e->getCommon() &&
8479 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008480 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008481
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008482 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008483 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008484 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008485 e->getColonLoc(),
8486 rhs.get());
8487}
8488
8489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008491TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008492 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008493 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008494 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008495
John McCalldadc5752010-08-24 06:29:42 +00008496 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008497 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008499
John McCalldadc5752010-08-24 06:29:42 +00008500 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008501 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008503
Douglas Gregora16548e2009-08-11 05:31:07 +00008504 if (!getDerived().AlwaysRebuild() &&
8505 Cond.get() == E->getCond() &&
8506 LHS.get() == E->getLHS() &&
8507 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008508 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008509
John McCallb268a282010-08-23 23:25:46 +00008510 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008511 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008512 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008513 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008514 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008515}
Mike Stump11289f42009-09-09 15:08:12 +00008516
8517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008518ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008519TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008520 // Implicit casts are eliminated during transformation, since they
8521 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008522 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008523}
Mike Stump11289f42009-09-09 15:08:12 +00008524
Douglas Gregora16548e2009-08-11 05:31:07 +00008525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008526ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008527TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008528 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8529 if (!Type)
8530 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008531
John McCalldadc5752010-08-24 06:29:42 +00008532 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008533 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008534 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008535 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008536
Douglas Gregora16548e2009-08-11 05:31:07 +00008537 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008538 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008539 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008540 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008541
John McCall97513962010-01-15 18:39:57 +00008542 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008543 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008544 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008545 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008546}
Mike Stump11289f42009-09-09 15:08:12 +00008547
Douglas Gregora16548e2009-08-11 05:31:07 +00008548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008550TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008551 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8552 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8553 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008554 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008555
John McCalldadc5752010-08-24 06:29:42 +00008556 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008557 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008559
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008561 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008562 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008563 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008564
John McCall5d7aa7f2010-01-19 22:33:45 +00008565 // Note: the expression type doesn't necessarily match the
8566 // type-as-written, but that's okay, because it should always be
8567 // derivable from the initializer.
8568
John McCalle15bbff2010-01-18 19:35:47 +00008569 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008570 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008571 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008572}
Mike Stump11289f42009-09-09 15:08:12 +00008573
Douglas Gregora16548e2009-08-11 05:31:07 +00008574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008575ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008576TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008577 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008580
Douglas Gregora16548e2009-08-11 05:31:07 +00008581 if (!getDerived().AlwaysRebuild() &&
8582 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008583 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008584
Douglas Gregora16548e2009-08-11 05:31:07 +00008585 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008586 SourceLocation FakeOperatorLoc =
8587 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008588 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008589 E->getAccessorLoc(),
8590 E->getAccessor());
8591}
Mike Stump11289f42009-09-09 15:08:12 +00008592
Douglas Gregora16548e2009-08-11 05:31:07 +00008593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008595TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008596 if (InitListExpr *Syntactic = E->getSyntacticForm())
8597 E = Syntactic;
8598
Douglas Gregora16548e2009-08-11 05:31:07 +00008599 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008600
Benjamin Kramerf0623432012-08-23 22:51:59 +00008601 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008602 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008603 Inits, &InitChanged))
8604 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008605
Richard Smith520449d2015-02-05 06:15:50 +00008606 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8607 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8608 // in some cases. We can't reuse it in general, because the syntactic and
8609 // semantic forms are linked, and we can't know that semantic form will
8610 // match even if the syntactic form does.
8611 }
Mike Stump11289f42009-09-09 15:08:12 +00008612
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008613 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008614 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008615}
Mike Stump11289f42009-09-09 15:08:12 +00008616
Douglas Gregora16548e2009-08-11 05:31:07 +00008617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008619TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008620 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008621
Douglas Gregorebe10102009-08-20 07:17:43 +00008622 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008623 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008624 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008626
Douglas Gregorebe10102009-08-20 07:17:43 +00008627 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008628 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 bool ExprChanged = false;
8630 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8631 DEnd = E->designators_end();
8632 D != DEnd; ++D) {
8633 if (D->isFieldDesignator()) {
8634 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8635 D->getDotLoc(),
8636 D->getFieldLoc()));
8637 continue;
8638 }
Mike Stump11289f42009-09-09 15:08:12 +00008639
Douglas Gregora16548e2009-08-11 05:31:07 +00008640 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008641 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008642 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008644
8645 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008647
Douglas Gregora16548e2009-08-11 05:31:07 +00008648 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008649 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 continue;
8651 }
Mike Stump11289f42009-09-09 15:08:12 +00008652
Douglas Gregora16548e2009-08-11 05:31:07 +00008653 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008654 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008655 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8656 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008658
John McCalldadc5752010-08-24 06:29:42 +00008659 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008660 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008662
8663 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008664 End.get(),
8665 D->getLBracketLoc(),
8666 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008667
Douglas Gregora16548e2009-08-11 05:31:07 +00008668 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8669 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008670
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008671 ArrayExprs.push_back(Start.get());
8672 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008673 }
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 if (!getDerived().AlwaysRebuild() &&
8676 Init.get() == E->getInit() &&
8677 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008678 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008679
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008680 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008681 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008682 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008683}
Mike Stump11289f42009-09-09 15:08:12 +00008684
Yunzhong Gaocb779302015-06-10 00:27:52 +00008685// Seems that if TransformInitListExpr() only works on the syntactic form of an
8686// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8687template<typename Derived>
8688ExprResult
8689TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8690 DesignatedInitUpdateExpr *E) {
8691 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8692 "initializer");
8693 return ExprError();
8694}
8695
8696template<typename Derived>
8697ExprResult
8698TreeTransform<Derived>::TransformNoInitExpr(
8699 NoInitExpr *E) {
8700 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8701 return ExprError();
8702}
8703
Douglas Gregora16548e2009-08-11 05:31:07 +00008704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008705ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008706TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008707 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008708 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008709
Douglas Gregor3da3c062009-10-28 00:29:27 +00008710 // FIXME: Will we ever have proper type location here? Will we actually
8711 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008712 QualType T = getDerived().TransformType(E->getType());
8713 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008715
Douglas Gregora16548e2009-08-11 05:31:07 +00008716 if (!getDerived().AlwaysRebuild() &&
8717 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008718 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008719
Douglas Gregora16548e2009-08-11 05:31:07 +00008720 return getDerived().RebuildImplicitValueInitExpr(T);
8721}
Mike Stump11289f42009-09-09 15:08:12 +00008722
Douglas Gregora16548e2009-08-11 05:31:07 +00008723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008725TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008726 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8727 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008729
John McCalldadc5752010-08-24 06:29:42 +00008730 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008731 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008733
Douglas Gregora16548e2009-08-11 05:31:07 +00008734 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008735 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008736 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008737 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008738
John McCallb268a282010-08-23 23:25:46 +00008739 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008740 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008741}
8742
8743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008745TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008746 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008747 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008748 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8749 &ArgumentChanged))
8750 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008751
Douglas Gregora16548e2009-08-11 05:31:07 +00008752 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008753 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008754 E->getRParenLoc());
8755}
Mike Stump11289f42009-09-09 15:08:12 +00008756
Douglas Gregora16548e2009-08-11 05:31:07 +00008757/// \brief Transform an address-of-label expression.
8758///
8759/// By default, the transformation of an address-of-label expression always
8760/// rebuilds the expression, so that the label identifier can be resolved to
8761/// the corresponding label statement by semantic analysis.
8762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008764TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008765 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8766 E->getLabel());
8767 if (!LD)
8768 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008769
Douglas Gregora16548e2009-08-11 05:31:07 +00008770 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008771 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008772}
Mike Stump11289f42009-09-09 15:08:12 +00008773
8774template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008775ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008776TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008777 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008778 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008779 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008780 if (SubStmt.isInvalid()) {
8781 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008782 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008783 }
Mike Stump11289f42009-09-09 15:08:12 +00008784
Douglas Gregora16548e2009-08-11 05:31:07 +00008785 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008786 SubStmt.get() == E->getSubStmt()) {
8787 // Calling this an 'error' is unintuitive, but it does the right thing.
8788 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008789 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008790 }
Mike Stump11289f42009-09-09 15:08:12 +00008791
8792 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008793 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008794 E->getRParenLoc());
8795}
Mike Stump11289f42009-09-09 15:08:12 +00008796
Douglas Gregora16548e2009-08-11 05:31:07 +00008797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008799TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008800 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008801 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008803
John McCalldadc5752010-08-24 06:29:42 +00008804 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008805 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008807
John McCalldadc5752010-08-24 06:29:42 +00008808 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008809 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008811
Douglas Gregora16548e2009-08-11 05:31:07 +00008812 if (!getDerived().AlwaysRebuild() &&
8813 Cond.get() == E->getCond() &&
8814 LHS.get() == E->getLHS() &&
8815 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008816 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008817
Douglas Gregora16548e2009-08-11 05:31:07 +00008818 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008819 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008820 E->getRParenLoc());
8821}
Mike Stump11289f42009-09-09 15:08:12 +00008822
Douglas Gregora16548e2009-08-11 05:31:07 +00008823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008825TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008826 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008827}
8828
8829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008830ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008831TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008832 switch (E->getOperator()) {
8833 case OO_New:
8834 case OO_Delete:
8835 case OO_Array_New:
8836 case OO_Array_Delete:
8837 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008838
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008839 case OO_Call: {
8840 // This is a call to an object's operator().
8841 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8842
8843 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008844 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008845 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008846 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008847
8848 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008849 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8850 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008851
8852 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008853 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008854 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008855 Args))
8856 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008857
John McCallb268a282010-08-23 23:25:46 +00008858 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008859 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008860 E->getLocEnd());
8861 }
8862
8863#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8864 case OO_##Name:
8865#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8866#include "clang/Basic/OperatorKinds.def"
8867 case OO_Subscript:
8868 // Handled below.
8869 break;
8870
8871 case OO_Conditional:
8872 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008873
8874 case OO_None:
8875 case NUM_OVERLOADED_OPERATORS:
8876 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008877 }
8878
John McCalldadc5752010-08-24 06:29:42 +00008879 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008880 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008882
Richard Smithdb2630f2012-10-21 03:28:35 +00008883 ExprResult First;
8884 if (E->getOperator() == OO_Amp)
8885 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8886 else
8887 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008888 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008889 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008890
John McCalldadc5752010-08-24 06:29:42 +00008891 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008892 if (E->getNumArgs() == 2) {
8893 Second = getDerived().TransformExpr(E->getArg(1));
8894 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008895 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008896 }
Mike Stump11289f42009-09-09 15:08:12 +00008897
Douglas Gregora16548e2009-08-11 05:31:07 +00008898 if (!getDerived().AlwaysRebuild() &&
8899 Callee.get() == E->getCallee() &&
8900 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008901 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008902 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008903
Lang Hames5de91cc2012-10-02 04:45:10 +00008904 Sema::FPContractStateRAII FPContractState(getSema());
8905 getSema().FPFeatures.fp_contract = E->isFPContractable();
8906
Douglas Gregora16548e2009-08-11 05:31:07 +00008907 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8908 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008909 Callee.get(),
8910 First.get(),
8911 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008912}
Mike Stump11289f42009-09-09 15:08:12 +00008913
Douglas Gregora16548e2009-08-11 05:31:07 +00008914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008916TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8917 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008918}
Mike Stump11289f42009-09-09 15:08:12 +00008919
Douglas Gregora16548e2009-08-11 05:31:07 +00008920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008921ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008922TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8923 // Transform the callee.
8924 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8925 if (Callee.isInvalid())
8926 return ExprError();
8927
8928 // Transform exec config.
8929 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8930 if (EC.isInvalid())
8931 return ExprError();
8932
8933 // Transform arguments.
8934 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008935 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008936 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008937 &ArgChanged))
8938 return ExprError();
8939
8940 if (!getDerived().AlwaysRebuild() &&
8941 Callee.get() == E->getCallee() &&
8942 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008943 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008944
8945 // FIXME: Wrong source location information for the '('.
8946 SourceLocation FakeLParenLoc
8947 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8948 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008949 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008950 E->getRParenLoc(), EC.get());
8951}
8952
8953template<typename Derived>
8954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008955TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008956 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8957 if (!Type)
8958 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008959
John McCalldadc5752010-08-24 06:29:42 +00008960 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008961 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008962 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008964
Douglas Gregora16548e2009-08-11 05:31:07 +00008965 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008966 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008967 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008968 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008969 return getDerived().RebuildCXXNamedCastExpr(
8970 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8971 Type, E->getAngleBrackets().getEnd(),
8972 // FIXME. this should be '(' location
8973 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008974}
Mike Stump11289f42009-09-09 15:08:12 +00008975
Douglas Gregora16548e2009-08-11 05:31:07 +00008976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008978TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8979 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008980}
Mike Stump11289f42009-09-09 15:08:12 +00008981
8982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008984TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8985 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008986}
8987
Douglas Gregora16548e2009-08-11 05:31:07 +00008988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008989ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008990TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008991 CXXReinterpretCastExpr *E) {
8992 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008993}
Mike Stump11289f42009-09-09 15:08:12 +00008994
Douglas Gregora16548e2009-08-11 05:31:07 +00008995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008997TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8998 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008999}
Mike Stump11289f42009-09-09 15:08:12 +00009000
Douglas Gregora16548e2009-08-11 05:31:07 +00009001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009002ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009003TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009004 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009005 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9006 if (!Type)
9007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009008
John McCalldadc5752010-08-24 06:29:42 +00009009 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009010 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009011 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009013
Douglas Gregora16548e2009-08-11 05:31:07 +00009014 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009015 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009016 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009017 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009018
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009019 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009020 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009021 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009022 E->getRParenLoc());
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>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009028 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009029 TypeSourceInfo *TInfo
9030 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9031 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009032 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009033
Douglas Gregora16548e2009-08-11 05:31:07 +00009034 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009035 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009036 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009037
Douglas Gregor9da64192010-04-26 22:37:10 +00009038 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9039 E->getLocStart(),
9040 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009041 E->getLocEnd());
9042 }
Mike Stump11289f42009-09-09 15:08:12 +00009043
Eli Friedman456f0182012-01-20 01:26:23 +00009044 // We don't know whether the subexpression is potentially evaluated until
9045 // after we perform semantic analysis. We speculatively assume it is
9046 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009047 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009048 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9049 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009050
John McCalldadc5752010-08-24 06:29:42 +00009051 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009052 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 if (!getDerived().AlwaysRebuild() &&
9056 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009057 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009058
Douglas Gregor9da64192010-04-26 22:37:10 +00009059 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9060 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009061 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009062 E->getLocEnd());
9063}
9064
9065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009066ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009067TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9068 if (E->isTypeOperand()) {
9069 TypeSourceInfo *TInfo
9070 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9071 if (!TInfo)
9072 return ExprError();
9073
9074 if (!getDerived().AlwaysRebuild() &&
9075 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009076 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009077
Douglas Gregor69735112011-03-06 17:40:41 +00009078 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009079 E->getLocStart(),
9080 TInfo,
9081 E->getLocEnd());
9082 }
9083
Francois Pichet9f4f2072010-09-08 12:20:18 +00009084 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9085
9086 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9087 if (SubExpr.isInvalid())
9088 return ExprError();
9089
9090 if (!getDerived().AlwaysRebuild() &&
9091 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009092 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009093
9094 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9095 E->getLocStart(),
9096 SubExpr.get(),
9097 E->getLocEnd());
9098}
9099
9100template<typename Derived>
9101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009102TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009103 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009104}
Mike Stump11289f42009-09-09 15:08:12 +00009105
Douglas Gregora16548e2009-08-11 05:31:07 +00009106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009107ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009108TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009109 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009110 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009111}
Mike Stump11289f42009-09-09 15:08:12 +00009112
Douglas Gregora16548e2009-08-11 05:31:07 +00009113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009115TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009116 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009117
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009118 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9119 // Make sure that we capture 'this'.
9120 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009121 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009123
Douglas Gregorb15af892010-01-07 23:12:05 +00009124 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009125}
Mike Stump11289f42009-09-09 15:08:12 +00009126
Douglas Gregora16548e2009-08-11 05:31:07 +00009127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009129TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009130 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009133
Douglas Gregora16548e2009-08-11 05:31:07 +00009134 if (!getDerived().AlwaysRebuild() &&
9135 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009136 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009137
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009138 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9139 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009140}
Mike Stump11289f42009-09-09 15:08:12 +00009141
Douglas Gregora16548e2009-08-11 05:31:07 +00009142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009144TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009145 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009146 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9147 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009148 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009150
Chandler Carruth794da4c2010-02-08 06:42:49 +00009151 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009152 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009153 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009154
Douglas Gregor033f6752009-12-23 23:03:06 +00009155 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009156}
Mike Stump11289f42009-09-09 15:08:12 +00009157
Douglas Gregora16548e2009-08-11 05:31:07 +00009158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009159ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009160TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9161 FieldDecl *Field
9162 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9163 E->getField()));
9164 if (!Field)
9165 return ExprError();
9166
9167 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009168 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009169
9170 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9171}
9172
9173template<typename Derived>
9174ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009175TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9176 CXXScalarValueInitExpr *E) {
9177 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9178 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009179 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009180
Douglas Gregora16548e2009-08-11 05:31:07 +00009181 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009182 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009183 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009184
Chad Rosier1dcde962012-08-08 18:46:20 +00009185 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009186 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009187 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009188}
Mike Stump11289f42009-09-09 15:08:12 +00009189
Douglas Gregora16548e2009-08-11 05:31:07 +00009190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009192TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009193 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009194 TypeSourceInfo *AllocTypeInfo
9195 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9196 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009198
Douglas Gregora16548e2009-08-11 05:31:07 +00009199 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009200 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009201 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009203
Douglas Gregora16548e2009-08-11 05:31:07 +00009204 // Transform the placement arguments (if any).
9205 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009206 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009207 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009208 E->getNumPlacementArgs(), true,
9209 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009211
Sebastian Redl6047f072012-02-16 12:22:20 +00009212 // Transform the initializer (if any).
9213 Expr *OldInit = E->getInitializer();
9214 ExprResult NewInit;
9215 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009216 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009217 if (NewInit.isInvalid())
9218 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009219
Sebastian Redl6047f072012-02-16 12:22:20 +00009220 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009221 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009222 if (E->getOperatorNew()) {
9223 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009224 getDerived().TransformDecl(E->getLocStart(),
9225 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009226 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009227 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009228 }
9229
Craig Topperc3ec1492014-05-26 06:22:03 +00009230 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009231 if (E->getOperatorDelete()) {
9232 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009233 getDerived().TransformDecl(E->getLocStart(),
9234 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009235 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009236 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009237 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009238
Douglas Gregora16548e2009-08-11 05:31:07 +00009239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009240 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009241 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009242 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009243 OperatorNew == E->getOperatorNew() &&
9244 OperatorDelete == E->getOperatorDelete() &&
9245 !ArgumentChanged) {
9246 // Mark any declarations we need as referenced.
9247 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009248 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009249 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009250 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009251 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009252
Sebastian Redl6047f072012-02-16 12:22:20 +00009253 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009254 QualType ElementType
9255 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9256 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9257 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9258 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009259 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009260 }
9261 }
9262 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009263
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009264 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009265 }
Mike Stump11289f42009-09-09 15:08:12 +00009266
Douglas Gregor0744ef62010-09-07 21:49:58 +00009267 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009268 if (!ArraySize.get()) {
9269 // If no array size was specified, but the new expression was
9270 // instantiated with an array type (e.g., "new T" where T is
9271 // instantiated with "int[4]"), extract the outer bound from the
9272 // array type as our array size. We do this with constant and
9273 // dependently-sized array types.
9274 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9275 if (!ArrayT) {
9276 // Do nothing
9277 } else if (const ConstantArrayType *ConsArrayT
9278 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009279 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9280 SemaRef.Context.getSizeType(),
9281 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009282 AllocType = ConsArrayT->getElementType();
9283 } else if (const DependentSizedArrayType *DepArrayT
9284 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9285 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009286 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009287 AllocType = DepArrayT->getElementType();
9288 }
9289 }
9290 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009291
Douglas Gregora16548e2009-08-11 05:31:07 +00009292 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9293 E->isGlobalNew(),
9294 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009295 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009296 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009297 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009298 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009299 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009300 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009301 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009302 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009303}
Mike Stump11289f42009-09-09 15:08:12 +00009304
Douglas Gregora16548e2009-08-11 05:31:07 +00009305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009307TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009308 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009309 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009310 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009311
Douglas Gregord2d9da02010-02-26 00:38:10 +00009312 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009313 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009314 if (E->getOperatorDelete()) {
9315 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009316 getDerived().TransformDecl(E->getLocStart(),
9317 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009318 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009319 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009320 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009321
Douglas Gregora16548e2009-08-11 05:31:07 +00009322 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009323 Operand.get() == E->getArgument() &&
9324 OperatorDelete == E->getOperatorDelete()) {
9325 // Mark any declarations we need as referenced.
9326 // FIXME: instantiation-specific.
9327 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009328 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009329
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009330 if (!E->getArgument()->isTypeDependent()) {
9331 QualType Destroyed = SemaRef.Context.getBaseElementType(
9332 E->getDestroyedType());
9333 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9334 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009335 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009336 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009337 }
9338 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009339
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009340 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009341 }
Mike Stump11289f42009-09-09 15:08:12 +00009342
Douglas Gregora16548e2009-08-11 05:31:07 +00009343 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9344 E->isGlobalDelete(),
9345 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009346 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009347}
Mike Stump11289f42009-09-09 15:08:12 +00009348
Douglas Gregora16548e2009-08-11 05:31:07 +00009349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009350ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009351TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009352 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009353 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009354 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009356
John McCallba7bf592010-08-24 05:47:05 +00009357 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009358 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009359 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009360 E->getOperatorLoc(),
9361 E->isArrow()? tok::arrow : tok::period,
9362 ObjectTypePtr,
9363 MayBePseudoDestructor);
9364 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009365 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009366
John McCallba7bf592010-08-24 05:47:05 +00009367 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009368 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9369 if (QualifierLoc) {
9370 QualifierLoc
9371 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9372 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009373 return ExprError();
9374 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009375 CXXScopeSpec SS;
9376 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009377
Douglas Gregor678f90d2010-02-25 01:56:36 +00009378 PseudoDestructorTypeStorage Destroyed;
9379 if (E->getDestroyedTypeInfo()) {
9380 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009381 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009382 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009383 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009384 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009385 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009386 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009387 // We aren't likely to be able to resolve the identifier down to a type
9388 // now anyway, so just retain the identifier.
9389 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9390 E->getDestroyedTypeLoc());
9391 } else {
9392 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009393 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009394 *E->getDestroyedTypeIdentifier(),
9395 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009396 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009397 SS, ObjectTypePtr,
9398 false);
9399 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009400 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009401
Douglas Gregor678f90d2010-02-25 01:56:36 +00009402 Destroyed
9403 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9404 E->getDestroyedTypeLoc());
9405 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009406
Craig Topperc3ec1492014-05-26 06:22:03 +00009407 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009408 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009409 CXXScopeSpec EmptySS;
9410 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009411 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009412 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009413 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009415
John McCallb268a282010-08-23 23:25:46 +00009416 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009417 E->getOperatorLoc(),
9418 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009419 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009420 ScopeTypeInfo,
9421 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009422 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009423 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009424}
Mike Stump11289f42009-09-09 15:08:12 +00009425
Douglas Gregorad8a3362009-09-04 17:36:40 +00009426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009427ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009428TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009429 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009430 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9431 Sema::LookupOrdinaryName);
9432
9433 // Transform all the decls.
9434 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9435 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009436 NamedDecl *InstD = static_cast<NamedDecl*>(
9437 getDerived().TransformDecl(Old->getNameLoc(),
9438 *I));
John McCall84d87672009-12-10 09:41:52 +00009439 if (!InstD) {
9440 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9441 // This can happen because of dependent hiding.
9442 if (isa<UsingShadowDecl>(*I))
9443 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009444 else {
9445 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009446 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009447 }
John McCall84d87672009-12-10 09:41:52 +00009448 }
John McCalle66edc12009-11-24 19:00:30 +00009449
9450 // Expand using declarations.
9451 if (isa<UsingDecl>(InstD)) {
9452 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009453 for (auto *I : UD->shadows())
9454 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009455 continue;
9456 }
9457
9458 R.addDecl(InstD);
9459 }
9460
9461 // Resolve a kind, but don't do any further analysis. If it's
9462 // ambiguous, the callee needs to deal with it.
9463 R.resolveKind();
9464
9465 // Rebuild the nested-name qualifier, if present.
9466 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009467 if (Old->getQualifierLoc()) {
9468 NestedNameSpecifierLoc QualifierLoc
9469 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9470 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009471 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009472
Douglas Gregor0da1d432011-02-28 20:01:57 +00009473 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009474 }
9475
Douglas Gregor9262f472010-04-27 18:19:34 +00009476 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009477 CXXRecordDecl *NamingClass
9478 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9479 Old->getNameLoc(),
9480 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009481 if (!NamingClass) {
9482 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009483 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009485
Douglas Gregorda7be082010-04-27 16:10:10 +00009486 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009487 }
9488
Abramo Bagnara7945c982012-01-27 09:46:47 +00009489 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9490
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009491 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009492 // it's a normal declaration name or member reference.
9493 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9494 NamedDecl *D = R.getAsSingle<NamedDecl>();
9495 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9496 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9497 // give a good diagnostic.
9498 if (D && D->isCXXInstanceMember()) {
9499 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9500 /*TemplateArgs=*/nullptr,
9501 /*Scope=*/nullptr);
9502 }
9503
John McCalle66edc12009-11-24 19:00:30 +00009504 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009505 }
John McCalle66edc12009-11-24 19:00:30 +00009506
9507 // If we have template arguments, rebuild them, then rebuild the
9508 // templateid expression.
9509 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009510 if (Old->hasExplicitTemplateArgs() &&
9511 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009512 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009513 TransArgs)) {
9514 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009515 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009516 }
John McCalle66edc12009-11-24 19:00:30 +00009517
Abramo Bagnara7945c982012-01-27 09:46:47 +00009518 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009519 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009520}
Mike Stump11289f42009-09-09 15:08:12 +00009521
Douglas Gregora16548e2009-08-11 05:31:07 +00009522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009523ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009524TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9525 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009526 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009527 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9528 TypeSourceInfo *From = E->getArg(I);
9529 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009530 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009531 TypeLocBuilder TLB;
9532 TLB.reserve(FromTL.getFullDataSize());
9533 QualType To = getDerived().TransformType(TLB, FromTL);
9534 if (To.isNull())
9535 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009536
Douglas Gregor29c42f22012-02-24 07:38:34 +00009537 if (To == From->getType())
9538 Args.push_back(From);
9539 else {
9540 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9541 ArgChanged = true;
9542 }
9543 continue;
9544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009545
Douglas Gregor29c42f22012-02-24 07:38:34 +00009546 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009547
Douglas Gregor29c42f22012-02-24 07:38:34 +00009548 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009549 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009550 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9551 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9552 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009553
Douglas Gregor29c42f22012-02-24 07:38:34 +00009554 // Determine whether the set of unexpanded parameter packs can and should
9555 // be expanded.
9556 bool Expand = true;
9557 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009558 Optional<unsigned> OrigNumExpansions =
9559 ExpansionTL.getTypePtr()->getNumExpansions();
9560 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009561 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9562 PatternTL.getSourceRange(),
9563 Unexpanded,
9564 Expand, RetainExpansion,
9565 NumExpansions))
9566 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009567
Douglas Gregor29c42f22012-02-24 07:38:34 +00009568 if (!Expand) {
9569 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009570 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009571 // expansion.
9572 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009573
Douglas Gregor29c42f22012-02-24 07:38:34 +00009574 TypeLocBuilder TLB;
9575 TLB.reserve(From->getTypeLoc().getFullDataSize());
9576
9577 QualType To = getDerived().TransformType(TLB, PatternTL);
9578 if (To.isNull())
9579 return ExprError();
9580
Chad Rosier1dcde962012-08-08 18:46:20 +00009581 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009582 PatternTL.getSourceRange(),
9583 ExpansionTL.getEllipsisLoc(),
9584 NumExpansions);
9585 if (To.isNull())
9586 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009587
Douglas Gregor29c42f22012-02-24 07:38:34 +00009588 PackExpansionTypeLoc ToExpansionTL
9589 = TLB.push<PackExpansionTypeLoc>(To);
9590 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9591 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9592 continue;
9593 }
9594
9595 // Expand the pack expansion by substituting for each argument in the
9596 // pack(s).
9597 for (unsigned I = 0; I != *NumExpansions; ++I) {
9598 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9599 TypeLocBuilder TLB;
9600 TLB.reserve(PatternTL.getFullDataSize());
9601 QualType To = getDerived().TransformType(TLB, PatternTL);
9602 if (To.isNull())
9603 return ExprError();
9604
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009605 if (To->containsUnexpandedParameterPack()) {
9606 To = getDerived().RebuildPackExpansionType(To,
9607 PatternTL.getSourceRange(),
9608 ExpansionTL.getEllipsisLoc(),
9609 NumExpansions);
9610 if (To.isNull())
9611 return ExprError();
9612
9613 PackExpansionTypeLoc ToExpansionTL
9614 = TLB.push<PackExpansionTypeLoc>(To);
9615 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9616 }
9617
Douglas Gregor29c42f22012-02-24 07:38:34 +00009618 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9619 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009620
Douglas Gregor29c42f22012-02-24 07:38:34 +00009621 if (!RetainExpansion)
9622 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009623
Douglas Gregor29c42f22012-02-24 07:38:34 +00009624 // If we're supposed to retain a pack expansion, do so by temporarily
9625 // forgetting the partially-substituted parameter pack.
9626 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9627
9628 TypeLocBuilder TLB;
9629 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009630
Douglas Gregor29c42f22012-02-24 07:38:34 +00009631 QualType To = getDerived().TransformType(TLB, PatternTL);
9632 if (To.isNull())
9633 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009634
9635 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009636 PatternTL.getSourceRange(),
9637 ExpansionTL.getEllipsisLoc(),
9638 NumExpansions);
9639 if (To.isNull())
9640 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009641
Douglas Gregor29c42f22012-02-24 07:38:34 +00009642 PackExpansionTypeLoc ToExpansionTL
9643 = TLB.push<PackExpansionTypeLoc>(To);
9644 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9645 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9646 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009647
Douglas Gregor29c42f22012-02-24 07:38:34 +00009648 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009649 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009650
9651 return getDerived().RebuildTypeTrait(E->getTrait(),
9652 E->getLocStart(),
9653 Args,
9654 E->getLocEnd());
9655}
9656
9657template<typename Derived>
9658ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009659TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9660 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9661 if (!T)
9662 return ExprError();
9663
9664 if (!getDerived().AlwaysRebuild() &&
9665 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009666 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009667
9668 ExprResult SubExpr;
9669 {
9670 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9671 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9672 if (SubExpr.isInvalid())
9673 return ExprError();
9674
9675 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009676 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009677 }
9678
9679 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9680 E->getLocStart(),
9681 T,
9682 SubExpr.get(),
9683 E->getLocEnd());
9684}
9685
9686template<typename Derived>
9687ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009688TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9689 ExprResult SubExpr;
9690 {
9691 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9692 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9693 if (SubExpr.isInvalid())
9694 return ExprError();
9695
9696 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009697 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009698 }
9699
9700 return getDerived().RebuildExpressionTrait(
9701 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9702}
9703
Reid Kleckner32506ed2014-06-12 23:03:48 +00009704template <typename Derived>
9705ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9706 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9707 TypeSourceInfo **RecoveryTSI) {
9708 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9709 DRE, AddrTaken, RecoveryTSI);
9710
9711 // Propagate both errors and recovered types, which return ExprEmpty.
9712 if (!NewDRE.isUsable())
9713 return NewDRE;
9714
9715 // We got an expr, wrap it up in parens.
9716 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9717 return PE;
9718 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9719 PE->getRParen());
9720}
9721
9722template <typename Derived>
9723ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9724 DependentScopeDeclRefExpr *E) {
9725 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9726 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009727}
9728
9729template<typename Derived>
9730ExprResult
9731TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9732 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009733 bool IsAddressOfOperand,
9734 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009735 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009736 NestedNameSpecifierLoc QualifierLoc
9737 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9738 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009739 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009740 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009741
John McCall31f82722010-11-12 08:19:04 +00009742 // TODO: If this is a conversion-function-id, verify that the
9743 // destination type name (if present) resolves the same way after
9744 // instantiation as it did in the local scope.
9745
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009746 DeclarationNameInfo NameInfo
9747 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9748 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009750
John McCalle66edc12009-11-24 19:00:30 +00009751 if (!E->hasExplicitTemplateArgs()) {
9752 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009753 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009754 // Note: it is sufficient to compare the Name component of NameInfo:
9755 // if name has not changed, DNLoc has not changed either.
9756 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009757 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009758
Reid Kleckner32506ed2014-06-12 23:03:48 +00009759 return getDerived().RebuildDependentScopeDeclRefExpr(
9760 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9761 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009762 }
John McCall6b51f282009-11-23 01:53:49 +00009763
9764 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009765 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9766 E->getNumTemplateArgs(),
9767 TransArgs))
9768 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009769
Reid Kleckner32506ed2014-06-12 23:03:48 +00009770 return getDerived().RebuildDependentScopeDeclRefExpr(
9771 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9772 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009773}
9774
9775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009777TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009778 // CXXConstructExprs other than for list-initialization and
9779 // CXXTemporaryObjectExpr are always implicit, so when we have
9780 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009781 if ((E->getNumArgs() == 1 ||
9782 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009783 (!getDerived().DropCallArgument(E->getArg(0))) &&
9784 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009785 return getDerived().TransformExpr(E->getArg(0));
9786
Douglas Gregora16548e2009-08-11 05:31:07 +00009787 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9788
9789 QualType T = getDerived().TransformType(E->getType());
9790 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009791 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009792
9793 CXXConstructorDecl *Constructor
9794 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009795 getDerived().TransformDecl(E->getLocStart(),
9796 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009797 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009799
Douglas Gregora16548e2009-08-11 05:31:07 +00009800 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009801 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009802 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009803 &ArgumentChanged))
9804 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009805
Douglas Gregora16548e2009-08-11 05:31:07 +00009806 if (!getDerived().AlwaysRebuild() &&
9807 T == E->getType() &&
9808 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009809 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009810 // Mark the constructor as referenced.
9811 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009812 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009813 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009814 }
Mike Stump11289f42009-09-09 15:08:12 +00009815
Douglas Gregordb121ba2009-12-14 16:27:04 +00009816 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9817 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009818 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009819 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009820 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009821 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009822 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009823 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009824 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009825}
Mike Stump11289f42009-09-09 15:08:12 +00009826
Douglas Gregora16548e2009-08-11 05:31:07 +00009827/// \brief Transform a C++ temporary-binding expression.
9828///
Douglas Gregor363b1512009-12-24 18:51:59 +00009829/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9830/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009832ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009833TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009834 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009835}
Mike Stump11289f42009-09-09 15:08:12 +00009836
John McCall5d413782010-12-06 08:20:24 +00009837/// \brief Transform a C++ expression that contains cleanups that should
9838/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009839///
John McCall5d413782010-12-06 08:20:24 +00009840/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009841/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009843ExprResult
John McCall5d413782010-12-06 08:20:24 +00009844TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009845 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009846}
Mike Stump11289f42009-09-09 15:08:12 +00009847
Douglas Gregora16548e2009-08-11 05:31:07 +00009848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009849ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009850TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009851 CXXTemporaryObjectExpr *E) {
9852 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9853 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009855
Douglas Gregora16548e2009-08-11 05:31:07 +00009856 CXXConstructorDecl *Constructor
9857 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009858 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009859 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009860 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009862
Douglas Gregora16548e2009-08-11 05:31:07 +00009863 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009864 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009865 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009866 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009867 &ArgumentChanged))
9868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009869
Douglas Gregora16548e2009-08-11 05:31:07 +00009870 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009871 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009872 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009873 !ArgumentChanged) {
9874 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009875 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009876 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009877 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009878
Richard Smithd59b8322012-12-19 01:39:02 +00009879 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009880 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9881 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009882 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009883 E->getLocEnd());
9884}
Mike Stump11289f42009-09-09 15:08:12 +00009885
Douglas Gregora16548e2009-08-11 05:31:07 +00009886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009887ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009888TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009889 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009890 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009891 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009892 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9893 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009894 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009895 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009896 CEnd = E->capture_end();
9897 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009898 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009899 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009900 EnterExpressionEvaluationContext EEEC(getSema(),
9901 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009902 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9903 C->getCapturedVar()->getInit(),
9904 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009905
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009906 if (NewExprInitResult.isInvalid())
9907 return ExprError();
9908 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009909
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009910 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009911 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +00009912 getSema().buildLambdaInitCaptureInitialization(
9913 C->getLocation(), OldVD->getType()->isReferenceType(),
9914 OldVD->getIdentifier(),
9915 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009916 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009917 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9918 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009919 }
9920
Faisal Vali2cba1332013-10-23 06:44:28 +00009921 // Transform the template parameters, and add them to the current
9922 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009923 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009924 E->getTemplateParameterList());
9925
Richard Smith01014ce2014-11-20 23:53:14 +00009926 // Transform the type of the original lambda's call operator.
9927 // The transformation MUST be done in the CurrentInstantiationScope since
9928 // it introduces a mapping of the original to the newly created
9929 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009930 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009931 {
9932 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9933 FunctionProtoTypeLoc OldCallOpFPTL =
9934 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009935
9936 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009937 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009938 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009939 QualType NewCallOpType = TransformFunctionProtoType(
9940 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009941 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9942 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9943 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009944 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009945 if (NewCallOpType.isNull())
9946 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009947 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9948 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009949 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009950
Richard Smithc38498f2015-04-27 21:27:54 +00009951 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9952 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9953 LSI->GLTemplateParameterList = TPL;
9954
Eli Friedmand564afb2012-09-19 01:18:11 +00009955 // Create the local class that will describe the lambda.
9956 CXXRecordDecl *Class
9957 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009958 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009959 /*KnownDependent=*/false,
9960 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009961 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9962
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009963 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009964 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9965 Class, E->getIntroducerRange(), NewCallOpTSI,
9966 E->getCallOperator()->getLocEnd(),
9967 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009968 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009969
Faisal Vali2cba1332013-10-23 06:44:28 +00009970 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009971 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009972
Douglas Gregorb4328232012-02-14 00:00:48 +00009973 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009974 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009975 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009976
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009977 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009978 getSema().buildLambdaScope(LSI, NewCallOperator,
9979 E->getIntroducerRange(),
9980 E->getCaptureDefault(),
9981 E->getCaptureDefaultLoc(),
9982 E->hasExplicitParameters(),
9983 E->hasExplicitResultType(),
9984 E->isMutable());
9985
9986 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009987
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009988 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009989 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009990 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009991 CEnd = E->capture_end();
9992 C != CEnd; ++C) {
9993 // When we hit the first implicit capture, tell Sema that we've finished
9994 // the list of explicit captures.
9995 if (!FinishedExplicitCaptures && C->isImplicit()) {
9996 getSema().finishLambdaExplicitCaptures(LSI);
9997 FinishedExplicitCaptures = true;
9998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009999
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010000 // Capturing 'this' is trivial.
10001 if (C->capturesThis()) {
10002 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
10003 continue;
10004 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010005 // Captured expression will be recaptured during captured variables
10006 // rebuilding.
10007 if (C->capturesVLAType())
10008 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010009
Richard Smithba71c082013-05-16 06:20:58 +000010010 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010011 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010012 InitCaptureInfoTy InitExprTypePair =
10013 InitCaptureExprsAndTypes[C - E->capture_begin()];
10014 ExprResult Init = InitExprTypePair.first;
10015 QualType InitQualType = InitExprTypePair.second;
10016 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010017 Invalid = true;
10018 continue;
10019 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010020 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010021 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010022 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10023 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010024 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010025 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010026 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010027 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010028 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010029 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010030 continue;
10031 }
10032
10033 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10034
Douglas Gregor3e308b12012-02-14 19:27:52 +000010035 // Determine the capture kind for Sema.
10036 Sema::TryCaptureKind Kind
10037 = C->isImplicit()? Sema::TryCapture_Implicit
10038 : C->getCaptureKind() == LCK_ByCopy
10039 ? Sema::TryCapture_ExplicitByVal
10040 : Sema::TryCapture_ExplicitByRef;
10041 SourceLocation EllipsisLoc;
10042 if (C->isPackExpansion()) {
10043 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10044 bool ShouldExpand = false;
10045 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010046 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010047 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10048 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010049 Unexpanded,
10050 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010051 NumExpansions)) {
10052 Invalid = true;
10053 continue;
10054 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010055
Douglas Gregor3e308b12012-02-14 19:27:52 +000010056 if (ShouldExpand) {
10057 // The transform has determined that we should perform an expansion;
10058 // transform and capture each of the arguments.
10059 // expansion of the pattern. Do so.
10060 VarDecl *Pack = C->getCapturedVar();
10061 for (unsigned I = 0; I != *NumExpansions; ++I) {
10062 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10063 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010064 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010065 Pack));
10066 if (!CapturedVar) {
10067 Invalid = true;
10068 continue;
10069 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010070
Douglas Gregor3e308b12012-02-14 19:27:52 +000010071 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010072 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10073 }
Richard Smith9467be42014-06-06 17:33:35 +000010074
10075 // FIXME: Retain a pack expansion if RetainExpansion is true.
10076
Douglas Gregor3e308b12012-02-14 19:27:52 +000010077 continue;
10078 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010079
Douglas Gregor3e308b12012-02-14 19:27:52 +000010080 EllipsisLoc = C->getEllipsisLoc();
10081 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010082
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010083 // Transform the captured variable.
10084 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010085 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010086 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010087 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010088 Invalid = true;
10089 continue;
10090 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010091
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010092 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010093 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10094 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010095 }
10096 if (!FinishedExplicitCaptures)
10097 getSema().finishLambdaExplicitCaptures(LSI);
10098
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010099 // Enter a new evaluation context to insulate the lambda from any
10100 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010101 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010102
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010103 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010104 StmtResult Body =
10105 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10106
10107 // ActOnLambda* will pop the function scope for us.
10108 FuncScopeCleanup.disable();
10109
Douglas Gregorb4328232012-02-14 00:00:48 +000010110 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010111 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010112 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010113 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010114 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010115 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010116
Richard Smithc38498f2015-04-27 21:27:54 +000010117 // Copy the LSI before ActOnFinishFunctionBody removes it.
10118 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10119 // the call operator.
10120 auto LSICopy = *LSI;
10121 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10122 /*IsInstantiation*/ true);
10123 SavedContext.pop();
10124
10125 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10126 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010127}
10128
10129template<typename Derived>
10130ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010131TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010132 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010133 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10134 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010135 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010136
Douglas Gregora16548e2009-08-11 05:31:07 +000010137 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010138 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010139 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010140 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010141 &ArgumentChanged))
10142 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010143
Douglas Gregora16548e2009-08-11 05:31:07 +000010144 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010145 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010146 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010147 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010148
Douglas Gregora16548e2009-08-11 05:31:07 +000010149 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010150 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010151 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010152 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010153 E->getRParenLoc());
10154}
Mike Stump11289f42009-09-09 15:08:12 +000010155
Douglas Gregora16548e2009-08-11 05:31:07 +000010156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010157ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010158TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010159 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010160 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010161 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010162 Expr *OldBase;
10163 QualType BaseType;
10164 QualType ObjectType;
10165 if (!E->isImplicitAccess()) {
10166 OldBase = E->getBase();
10167 Base = getDerived().TransformExpr(OldBase);
10168 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010170
John McCall2d74de92009-12-01 22:10:20 +000010171 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010172 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010173 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010174 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010175 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010176 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010177 ObjectTy,
10178 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010179 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010180 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010181
John McCallba7bf592010-08-24 05:47:05 +000010182 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010183 BaseType = ((Expr*) Base.get())->getType();
10184 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010185 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010186 BaseType = getDerived().TransformType(E->getBaseType());
10187 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10188 }
Mike Stump11289f42009-09-09 15:08:12 +000010189
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010190 // Transform the first part of the nested-name-specifier that qualifies
10191 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010192 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010193 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010194 E->getFirstQualifierFoundInScope(),
10195 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010196
Douglas Gregore16af532011-02-28 18:50:33 +000010197 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010198 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010199 QualifierLoc
10200 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10201 ObjectType,
10202 FirstQualifierInScope);
10203 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010204 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010205 }
Mike Stump11289f42009-09-09 15:08:12 +000010206
Abramo Bagnara7945c982012-01-27 09:46:47 +000010207 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10208
John McCall31f82722010-11-12 08:19:04 +000010209 // TODO: If this is a conversion-function-id, verify that the
10210 // destination type name (if present) resolves the same way after
10211 // instantiation as it did in the local scope.
10212
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010213 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010214 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010215 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010216 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010217
John McCall2d74de92009-12-01 22:10:20 +000010218 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010219 // This is a reference to a member without an explicitly-specified
10220 // template argument list. Optimize for this common case.
10221 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010222 Base.get() == OldBase &&
10223 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010224 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010225 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010226 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010227 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010228
John McCallb268a282010-08-23 23:25:46 +000010229 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010230 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010231 E->isArrow(),
10232 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010233 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010234 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010235 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010236 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010237 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010238 }
10239
John McCall6b51f282009-11-23 01:53:49 +000010240 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010241 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10242 E->getNumTemplateArgs(),
10243 TransArgs))
10244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010245
John McCallb268a282010-08-23 23:25:46 +000010246 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010247 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010248 E->isArrow(),
10249 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010250 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010251 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010252 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010253 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010254 &TransArgs);
10255}
10256
10257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010259TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010260 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010261 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010262 QualType BaseType;
10263 if (!Old->isImplicitAccess()) {
10264 Base = getDerived().TransformExpr(Old->getBase());
10265 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010266 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010267 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010268 Old->isArrow());
10269 if (Base.isInvalid())
10270 return ExprError();
10271 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010272 } else {
10273 BaseType = getDerived().TransformType(Old->getBaseType());
10274 }
John McCall10eae182009-11-30 22:42:35 +000010275
Douglas Gregor0da1d432011-02-28 20:01:57 +000010276 NestedNameSpecifierLoc QualifierLoc;
10277 if (Old->getQualifierLoc()) {
10278 QualifierLoc
10279 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10280 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010281 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010282 }
10283
Abramo Bagnara7945c982012-01-27 09:46:47 +000010284 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10285
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010286 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010287 Sema::LookupOrdinaryName);
10288
10289 // Transform all the decls.
10290 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10291 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010292 NamedDecl *InstD = static_cast<NamedDecl*>(
10293 getDerived().TransformDecl(Old->getMemberLoc(),
10294 *I));
John McCall84d87672009-12-10 09:41:52 +000010295 if (!InstD) {
10296 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10297 // This can happen because of dependent hiding.
10298 if (isa<UsingShadowDecl>(*I))
10299 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010300 else {
10301 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010302 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010303 }
John McCall84d87672009-12-10 09:41:52 +000010304 }
John McCall10eae182009-11-30 22:42:35 +000010305
10306 // Expand using declarations.
10307 if (isa<UsingDecl>(InstD)) {
10308 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010309 for (auto *I : UD->shadows())
10310 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010311 continue;
10312 }
10313
10314 R.addDecl(InstD);
10315 }
10316
10317 R.resolveKind();
10318
Douglas Gregor9262f472010-04-27 18:19:34 +000010319 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010320 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010321 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010322 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010323 Old->getMemberLoc(),
10324 Old->getNamingClass()));
10325 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010326 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010327
Douglas Gregorda7be082010-04-27 16:10:10 +000010328 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010329 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010330
John McCall10eae182009-11-30 22:42:35 +000010331 TemplateArgumentListInfo TransArgs;
10332 if (Old->hasExplicitTemplateArgs()) {
10333 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10334 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010335 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10336 Old->getNumTemplateArgs(),
10337 TransArgs))
10338 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010339 }
John McCall38836f02010-01-15 08:34:02 +000010340
10341 // FIXME: to do this check properly, we will need to preserve the
10342 // first-qualifier-in-scope here, just in case we had a dependent
10343 // base (and therefore couldn't do the check) and a
10344 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010345 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010346
John McCallb268a282010-08-23 23:25:46 +000010347 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010348 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010349 Old->getOperatorLoc(),
10350 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010351 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010352 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010353 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010354 R,
10355 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010356 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010357}
10358
10359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010360ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010361TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010362 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010363 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10364 if (SubExpr.isInvalid())
10365 return ExprError();
10366
10367 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010368 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010369
10370 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10371}
10372
10373template<typename Derived>
10374ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010375TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010376 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10377 if (Pattern.isInvalid())
10378 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010379
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010380 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010381 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010382
Douglas Gregorb8840002011-01-14 21:20:45 +000010383 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10384 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010385}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010386
10387template<typename Derived>
10388ExprResult
10389TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10390 // If E is not value-dependent, then nothing will change when we transform it.
10391 // Note: This is an instantiation-centric view.
10392 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010393 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010394
Richard Smithd784e682015-09-23 21:41:42 +000010395 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010396
Richard Smithd784e682015-09-23 21:41:42 +000010397 ArrayRef<TemplateArgument> PackArgs;
10398 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010399
Richard Smithd784e682015-09-23 21:41:42 +000010400 // Find the argument list to transform.
10401 if (E->isPartiallySubstituted()) {
10402 PackArgs = E->getPartialArguments();
10403 } else if (E->isValueDependent()) {
10404 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10405 bool ShouldExpand = false;
10406 bool RetainExpansion = false;
10407 Optional<unsigned> NumExpansions;
10408 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10409 Unexpanded,
10410 ShouldExpand, RetainExpansion,
10411 NumExpansions))
10412 return ExprError();
10413
10414 // If we need to expand the pack, build a template argument from it and
10415 // expand that.
10416 if (ShouldExpand) {
10417 auto *Pack = E->getPack();
10418 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10419 ArgStorage = getSema().Context.getPackExpansionType(
10420 getSema().Context.getTypeDeclType(TTPD), None);
10421 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10422 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10423 } else {
10424 auto *VD = cast<ValueDecl>(Pack);
10425 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10426 VK_RValue, E->getPackLoc());
10427 if (DRE.isInvalid())
10428 return ExprError();
10429 ArgStorage = new (getSema().Context) PackExpansionExpr(
10430 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10431 }
10432 PackArgs = ArgStorage;
10433 }
10434 }
10435
10436 // If we're not expanding the pack, just transform the decl.
10437 if (!PackArgs.size()) {
10438 auto *Pack = cast_or_null<NamedDecl>(
10439 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010440 if (!Pack)
10441 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010442 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10443 E->getPackLoc(),
10444 E->getRParenLoc(), None, None);
10445 }
10446
10447 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10448 E->getPackLoc());
10449 {
10450 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10451 typedef TemplateArgumentLocInventIterator<
10452 Derived, const TemplateArgument*> PackLocIterator;
10453 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10454 PackLocIterator(*this, PackArgs.end()),
10455 TransformedPackArgs, /*Uneval*/true))
10456 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010457 }
10458
Richard Smithd784e682015-09-23 21:41:42 +000010459 SmallVector<TemplateArgument, 8> Args;
10460 bool PartialSubstitution = false;
10461 for (auto &Loc : TransformedPackArgs.arguments()) {
10462 Args.push_back(Loc.getArgument());
10463 if (Loc.getArgument().isPackExpansion())
10464 PartialSubstitution = true;
10465 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010466
Richard Smithd784e682015-09-23 21:41:42 +000010467 if (PartialSubstitution)
10468 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10469 E->getPackLoc(),
10470 E->getRParenLoc(), None, Args);
10471
10472 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010473 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010474 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010475}
10476
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010477template<typename Derived>
10478ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010479TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10480 SubstNonTypeTemplateParmPackExpr *E) {
10481 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010482 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010483}
10484
10485template<typename Derived>
10486ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010487TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10488 SubstNonTypeTemplateParmExpr *E) {
10489 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010490 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010491}
10492
10493template<typename Derived>
10494ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010495TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10496 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010497 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010498}
10499
10500template<typename Derived>
10501ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010502TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10503 MaterializeTemporaryExpr *E) {
10504 return getDerived().TransformExpr(E->GetTemporaryExpr());
10505}
Chad Rosier1dcde962012-08-08 18:46:20 +000010506
Douglas Gregorfe314812011-06-21 17:03:29 +000010507template<typename Derived>
10508ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010509TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10510 Expr *Pattern = E->getPattern();
10511
10512 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10513 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10514 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10515
10516 // Determine whether the set of unexpanded parameter packs can and should
10517 // be expanded.
10518 bool Expand = true;
10519 bool RetainExpansion = false;
10520 Optional<unsigned> NumExpansions;
10521 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10522 Pattern->getSourceRange(),
10523 Unexpanded,
10524 Expand, RetainExpansion,
10525 NumExpansions))
10526 return true;
10527
10528 if (!Expand) {
10529 // Do not expand any packs here, just transform and rebuild a fold
10530 // expression.
10531 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10532
10533 ExprResult LHS =
10534 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10535 if (LHS.isInvalid())
10536 return true;
10537
10538 ExprResult RHS =
10539 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10540 if (RHS.isInvalid())
10541 return true;
10542
10543 if (!getDerived().AlwaysRebuild() &&
10544 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10545 return E;
10546
10547 return getDerived().RebuildCXXFoldExpr(
10548 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10549 RHS.get(), E->getLocEnd());
10550 }
10551
10552 // The transform has determined that we should perform an elementwise
10553 // expansion of the pattern. Do so.
10554 ExprResult Result = getDerived().TransformExpr(E->getInit());
10555 if (Result.isInvalid())
10556 return true;
10557 bool LeftFold = E->isLeftFold();
10558
10559 // If we're retaining an expansion for a right fold, it is the innermost
10560 // component and takes the init (if any).
10561 if (!LeftFold && RetainExpansion) {
10562 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10563
10564 ExprResult Out = getDerived().TransformExpr(Pattern);
10565 if (Out.isInvalid())
10566 return true;
10567
10568 Result = getDerived().RebuildCXXFoldExpr(
10569 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10570 Result.get(), E->getLocEnd());
10571 if (Result.isInvalid())
10572 return true;
10573 }
10574
10575 for (unsigned I = 0; I != *NumExpansions; ++I) {
10576 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10577 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10578 ExprResult Out = getDerived().TransformExpr(Pattern);
10579 if (Out.isInvalid())
10580 return true;
10581
10582 if (Out.get()->containsUnexpandedParameterPack()) {
10583 // We still have a pack; retain a pack expansion for this slice.
10584 Result = getDerived().RebuildCXXFoldExpr(
10585 E->getLocStart(),
10586 LeftFold ? Result.get() : Out.get(),
10587 E->getOperator(), E->getEllipsisLoc(),
10588 LeftFold ? Out.get() : Result.get(),
10589 E->getLocEnd());
10590 } else if (Result.isUsable()) {
10591 // We've got down to a single element; build a binary operator.
10592 Result = getDerived().RebuildBinaryOperator(
10593 E->getEllipsisLoc(), E->getOperator(),
10594 LeftFold ? Result.get() : Out.get(),
10595 LeftFold ? Out.get() : Result.get());
10596 } else
10597 Result = Out;
10598
10599 if (Result.isInvalid())
10600 return true;
10601 }
10602
10603 // If we're retaining an expansion for a left fold, it is the outermost
10604 // component and takes the complete expansion so far as its init (if any).
10605 if (LeftFold && RetainExpansion) {
10606 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10607
10608 ExprResult Out = getDerived().TransformExpr(Pattern);
10609 if (Out.isInvalid())
10610 return true;
10611
10612 Result = getDerived().RebuildCXXFoldExpr(
10613 E->getLocStart(), Result.get(),
10614 E->getOperator(), E->getEllipsisLoc(),
10615 Out.get(), E->getLocEnd());
10616 if (Result.isInvalid())
10617 return true;
10618 }
10619
10620 // If we had no init and an empty pack, and we're not retaining an expansion,
10621 // then produce a fallback value or error.
10622 if (Result.isUnset())
10623 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10624 E->getOperator());
10625
10626 return Result;
10627}
10628
10629template<typename Derived>
10630ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010631TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10632 CXXStdInitializerListExpr *E) {
10633 return getDerived().TransformExpr(E->getSubExpr());
10634}
10635
10636template<typename Derived>
10637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010638TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010639 return SemaRef.MaybeBindToTemporary(E);
10640}
10641
10642template<typename Derived>
10643ExprResult
10644TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010645 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010646}
10647
10648template<typename Derived>
10649ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010650TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10651 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10652 if (SubExpr.isInvalid())
10653 return ExprError();
10654
10655 if (!getDerived().AlwaysRebuild() &&
10656 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010657 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010658
10659 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010660}
10661
10662template<typename Derived>
10663ExprResult
10664TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10665 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010666 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010667 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010668 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010669 /*IsCall=*/false, Elements, &ArgChanged))
10670 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010671
Ted Kremeneke65b0862012-03-06 20:05:56 +000010672 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10673 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010674
Ted Kremeneke65b0862012-03-06 20:05:56 +000010675 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10676 Elements.data(),
10677 Elements.size());
10678}
10679
10680template<typename Derived>
10681ExprResult
10682TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010683 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010684 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010685 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010686 bool ArgChanged = false;
10687 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10688 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010689
Ted Kremeneke65b0862012-03-06 20:05:56 +000010690 if (OrigElement.isPackExpansion()) {
10691 // This key/value element is a pack expansion.
10692 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10693 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10694 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10695 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10696
10697 // Determine whether the set of unexpanded parameter packs can
10698 // and should be expanded.
10699 bool Expand = true;
10700 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010701 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10702 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010703 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10704 OrigElement.Value->getLocEnd());
10705 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10706 PatternRange,
10707 Unexpanded,
10708 Expand, RetainExpansion,
10709 NumExpansions))
10710 return ExprError();
10711
10712 if (!Expand) {
10713 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010714 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010715 // expansion.
10716 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10717 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10718 if (Key.isInvalid())
10719 return ExprError();
10720
10721 if (Key.get() != OrigElement.Key)
10722 ArgChanged = true;
10723
10724 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10725 if (Value.isInvalid())
10726 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010727
Ted Kremeneke65b0862012-03-06 20:05:56 +000010728 if (Value.get() != OrigElement.Value)
10729 ArgChanged = true;
10730
Chad Rosier1dcde962012-08-08 18:46:20 +000010731 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010732 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10733 };
10734 Elements.push_back(Expansion);
10735 continue;
10736 }
10737
10738 // Record right away that the argument was changed. This needs
10739 // to happen even if the array expands to nothing.
10740 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010741
Ted Kremeneke65b0862012-03-06 20:05:56 +000010742 // The transform has determined that we should perform an elementwise
10743 // expansion of the pattern. Do so.
10744 for (unsigned I = 0; I != *NumExpansions; ++I) {
10745 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10746 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10747 if (Key.isInvalid())
10748 return ExprError();
10749
10750 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10751 if (Value.isInvalid())
10752 return ExprError();
10753
Chad Rosier1dcde962012-08-08 18:46:20 +000010754 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010755 Key.get(), Value.get(), SourceLocation(), NumExpansions
10756 };
10757
10758 // If any unexpanded parameter packs remain, we still have a
10759 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010760 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010761 if (Key.get()->containsUnexpandedParameterPack() ||
10762 Value.get()->containsUnexpandedParameterPack())
10763 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010764
Ted Kremeneke65b0862012-03-06 20:05:56 +000010765 Elements.push_back(Element);
10766 }
10767
Richard Smith9467be42014-06-06 17:33:35 +000010768 // FIXME: Retain a pack expansion if RetainExpansion is true.
10769
Ted Kremeneke65b0862012-03-06 20:05:56 +000010770 // We've finished with this pack expansion.
10771 continue;
10772 }
10773
10774 // Transform and check key.
10775 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10776 if (Key.isInvalid())
10777 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010778
Ted Kremeneke65b0862012-03-06 20:05:56 +000010779 if (Key.get() != OrigElement.Key)
10780 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010781
Ted Kremeneke65b0862012-03-06 20:05:56 +000010782 // Transform and check value.
10783 ExprResult Value
10784 = getDerived().TransformExpr(OrigElement.Value);
10785 if (Value.isInvalid())
10786 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010787
Ted Kremeneke65b0862012-03-06 20:05:56 +000010788 if (Value.get() != OrigElement.Value)
10789 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010790
10791 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010792 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010793 };
10794 Elements.push_back(Element);
10795 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010796
Ted Kremeneke65b0862012-03-06 20:05:56 +000010797 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10798 return SemaRef.MaybeBindToTemporary(E);
10799
10800 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010801 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010802}
10803
Mike Stump11289f42009-09-09 15:08:12 +000010804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010805ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010806TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010807 TypeSourceInfo *EncodedTypeInfo
10808 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10809 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010811
Douglas Gregora16548e2009-08-11 05:31:07 +000010812 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010813 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010814 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010815
10816 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010817 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010818 E->getRParenLoc());
10819}
Mike Stump11289f42009-09-09 15:08:12 +000010820
Douglas Gregora16548e2009-08-11 05:31:07 +000010821template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010822ExprResult TreeTransform<Derived>::
10823TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010824 // This is a kind of implicit conversion, and it needs to get dropped
10825 // and recomputed for the same general reasons that ImplicitCastExprs
10826 // do, as well a more specific one: this expression is only valid when
10827 // it appears *immediately* as an argument expression.
10828 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010829}
10830
10831template<typename Derived>
10832ExprResult TreeTransform<Derived>::
10833TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010834 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010835 = getDerived().TransformType(E->getTypeInfoAsWritten());
10836 if (!TSInfo)
10837 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010838
John McCall31168b02011-06-15 23:02:42 +000010839 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010840 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010841 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010842
John McCall31168b02011-06-15 23:02:42 +000010843 if (!getDerived().AlwaysRebuild() &&
10844 TSInfo == E->getTypeInfoAsWritten() &&
10845 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010846 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010847
John McCall31168b02011-06-15 23:02:42 +000010848 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010849 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010850 Result.get());
10851}
10852
10853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010855TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010856 // Transform arguments.
10857 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010858 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010859 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010860 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010861 &ArgChanged))
10862 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010863
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010864 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10865 // Class message: transform the receiver type.
10866 TypeSourceInfo *ReceiverTypeInfo
10867 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10868 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010869 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010870
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010871 // If nothing changed, just retain the existing message send.
10872 if (!getDerived().AlwaysRebuild() &&
10873 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010874 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010875
10876 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010877 SmallVector<SourceLocation, 16> SelLocs;
10878 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010879 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10880 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010881 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010882 E->getMethodDecl(),
10883 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010884 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010885 E->getRightLoc());
10886 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010887 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10888 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10889 // Build a new class message send to 'super'.
10890 SmallVector<SourceLocation, 16> SelLocs;
10891 E->getSelectorLocs(SelLocs);
10892 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10893 E->getSelector(),
10894 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010895 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010896 E->getMethodDecl(),
10897 E->getLeftLoc(),
10898 Args,
10899 E->getRightLoc());
10900 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010901
10902 // Instance message: transform the receiver
10903 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10904 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010905 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010906 = getDerived().TransformExpr(E->getInstanceReceiver());
10907 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010908 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010909
10910 // If nothing changed, just retain the existing message send.
10911 if (!getDerived().AlwaysRebuild() &&
10912 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010913 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010914
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010915 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010916 SmallVector<SourceLocation, 16> SelLocs;
10917 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010918 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010919 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010920 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010921 E->getMethodDecl(),
10922 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010923 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010924 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010925}
10926
Mike Stump11289f42009-09-09 15:08:12 +000010927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010928ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010929TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010930 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010931}
10932
Mike Stump11289f42009-09-09 15:08:12 +000010933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010934ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010935TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010936 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010937}
10938
Mike Stump11289f42009-09-09 15:08:12 +000010939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010940ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010941TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010942 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010943 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010944 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010945 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010946
10947 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010948
Douglas Gregord51d90d2010-04-26 20:11:03 +000010949 // If nothing changed, just retain the existing expression.
10950 if (!getDerived().AlwaysRebuild() &&
10951 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010952 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010953
John McCallb268a282010-08-23 23:25:46 +000010954 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010955 E->getLocation(),
10956 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010957}
10958
Mike Stump11289f42009-09-09 15:08:12 +000010959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010961TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010962 // 'super' and types never change. Property never changes. Just
10963 // retain the existing expression.
10964 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010965 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010966
Douglas Gregor9faee212010-04-26 20:47:02 +000010967 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010968 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010969 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010970 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010971
Douglas Gregor9faee212010-04-26 20:47:02 +000010972 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010973
Douglas Gregor9faee212010-04-26 20:47:02 +000010974 // If nothing changed, just retain the existing expression.
10975 if (!getDerived().AlwaysRebuild() &&
10976 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010977 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010978
John McCallb7bd14f2010-12-02 01:19:52 +000010979 if (E->isExplicitProperty())
10980 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10981 E->getExplicitProperty(),
10982 E->getLocation());
10983
10984 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010985 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010986 E->getImplicitPropertyGetter(),
10987 E->getImplicitPropertySetter(),
10988 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010989}
10990
Mike Stump11289f42009-09-09 15:08:12 +000010991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010992ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010993TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10994 // Transform the base expression.
10995 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10996 if (Base.isInvalid())
10997 return ExprError();
10998
10999 // Transform the key expression.
11000 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11001 if (Key.isInvalid())
11002 return ExprError();
11003
11004 // If nothing changed, just retain the existing expression.
11005 if (!getDerived().AlwaysRebuild() &&
11006 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011007 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011008
Chad Rosier1dcde962012-08-08 18:46:20 +000011009 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011010 Base.get(), Key.get(),
11011 E->getAtIndexMethodDecl(),
11012 E->setAtIndexMethodDecl());
11013}
11014
11015template<typename Derived>
11016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011017TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011018 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011019 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011020 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011021 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011022
Douglas Gregord51d90d2010-04-26 20:11:03 +000011023 // If nothing changed, just retain the existing expression.
11024 if (!getDerived().AlwaysRebuild() &&
11025 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011026 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011027
John McCallb268a282010-08-23 23:25:46 +000011028 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011029 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011030 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011031}
11032
Mike Stump11289f42009-09-09 15:08:12 +000011033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011034ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011035TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011036 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011037 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011038 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011039 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011040 SubExprs, &ArgumentChanged))
11041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011042
Douglas Gregora16548e2009-08-11 05:31:07 +000011043 if (!getDerived().AlwaysRebuild() &&
11044 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011045 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011046
Douglas Gregora16548e2009-08-11 05:31:07 +000011047 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011048 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011049 E->getRParenLoc());
11050}
11051
Mike Stump11289f42009-09-09 15:08:12 +000011052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011053ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011054TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11055 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11056 if (SrcExpr.isInvalid())
11057 return ExprError();
11058
11059 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11060 if (!Type)
11061 return ExprError();
11062
11063 if (!getDerived().AlwaysRebuild() &&
11064 Type == E->getTypeSourceInfo() &&
11065 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011066 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011067
11068 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11069 SrcExpr.get(), Type,
11070 E->getRParenLoc());
11071}
11072
11073template<typename Derived>
11074ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011075TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011076 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011077
Craig Topperc3ec1492014-05-26 06:22:03 +000011078 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011079 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11080
11081 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011082 blockScope->TheDecl->setBlockMissingReturnType(
11083 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011084
Chris Lattner01cf8db2011-07-20 06:58:45 +000011085 SmallVector<ParmVarDecl*, 4> params;
11086 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011087
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011088 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000011089 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11090 oldBlock->param_begin(),
11091 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011092 nullptr, paramTypes, &params)) {
11093 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011094 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011095 }
John McCall490112f2011-02-04 18:33:18 +000011096
Jordan Rosea0a86be2013-03-08 22:25:36 +000011097 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000011098 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011099 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011100
Jordan Rose5c382722013-03-08 21:51:21 +000011101 QualType functionType =
11102 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011103 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000011104 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011105
11106 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011107 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011108 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011109
11110 if (!oldBlock->blockMissingReturnType()) {
11111 blockScope->HasImplicitReturnType = false;
11112 blockScope->ReturnType = exprResultType;
11113 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011114
John McCall3882ace2011-01-05 12:14:39 +000011115 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011116 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011117 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011118 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011119 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011120 }
John McCall3882ace2011-01-05 12:14:39 +000011121
John McCall490112f2011-02-04 18:33:18 +000011122#ifndef NDEBUG
11123 // In builds with assertions, make sure that we captured everything we
11124 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011125 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011126 for (const auto &I : oldBlock->captures()) {
11127 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011128
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011129 // Ignore parameter packs.
11130 if (isa<ParmVarDecl>(oldCapture) &&
11131 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11132 continue;
John McCall490112f2011-02-04 18:33:18 +000011133
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011134 VarDecl *newCapture =
11135 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11136 oldCapture));
11137 assert(blockScope->CaptureMap.count(newCapture));
11138 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011139 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011140 }
11141#endif
11142
11143 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011144 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011145}
11146
Mike Stump11289f42009-09-09 15:08:12 +000011147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011148ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011149TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011150 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011151}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011152
11153template<typename Derived>
11154ExprResult
11155TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011156 QualType RetTy = getDerived().TransformType(E->getType());
11157 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011158 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011159 SubExprs.reserve(E->getNumSubExprs());
11160 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11161 SubExprs, &ArgumentChanged))
11162 return ExprError();
11163
11164 if (!getDerived().AlwaysRebuild() &&
11165 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011166 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011167
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011168 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011169 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011170}
Chad Rosier1dcde962012-08-08 18:46:20 +000011171
Douglas Gregora16548e2009-08-11 05:31:07 +000011172//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011173// Type reconstruction
11174//===----------------------------------------------------------------------===//
11175
Mike Stump11289f42009-09-09 15:08:12 +000011176template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011177QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11178 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011179 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011180 getDerived().getBaseEntity());
11181}
11182
Mike Stump11289f42009-09-09 15:08:12 +000011183template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011184QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11185 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011186 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011187 getDerived().getBaseEntity());
11188}
11189
Mike Stump11289f42009-09-09 15:08:12 +000011190template<typename Derived>
11191QualType
John McCall70dd5f62009-10-30 00:06:24 +000011192TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11193 bool WrittenAsLValue,
11194 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011195 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011196 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011197}
11198
11199template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011200QualType
John McCall70dd5f62009-10-30 00:06:24 +000011201TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11202 QualType ClassType,
11203 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011204 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11205 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011206}
11207
11208template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011209QualType TreeTransform<Derived>::RebuildObjCObjectType(
11210 QualType BaseType,
11211 SourceLocation Loc,
11212 SourceLocation TypeArgsLAngleLoc,
11213 ArrayRef<TypeSourceInfo *> TypeArgs,
11214 SourceLocation TypeArgsRAngleLoc,
11215 SourceLocation ProtocolLAngleLoc,
11216 ArrayRef<ObjCProtocolDecl *> Protocols,
11217 ArrayRef<SourceLocation> ProtocolLocs,
11218 SourceLocation ProtocolRAngleLoc) {
11219 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11220 TypeArgs, TypeArgsRAngleLoc,
11221 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11222 ProtocolRAngleLoc,
11223 /*FailOnError=*/true);
11224}
11225
11226template<typename Derived>
11227QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11228 QualType PointeeType,
11229 SourceLocation Star) {
11230 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11231}
11232
11233template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011234QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011235TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11236 ArrayType::ArraySizeModifier SizeMod,
11237 const llvm::APInt *Size,
11238 Expr *SizeExpr,
11239 unsigned IndexTypeQuals,
11240 SourceRange BracketsRange) {
11241 if (SizeExpr || !Size)
11242 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11243 IndexTypeQuals, BracketsRange,
11244 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011245
11246 QualType Types[] = {
11247 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11248 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11249 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011250 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011251 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011252 QualType SizeType;
11253 for (unsigned I = 0; I != NumTypes; ++I)
11254 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11255 SizeType = Types[I];
11256 break;
11257 }
Mike Stump11289f42009-09-09 15:08:12 +000011258
Eli Friedman9562f392012-01-25 23:20:27 +000011259 // Note that we can return a VariableArrayType here in the case where
11260 // the element type was a dependent VariableArrayType.
11261 IntegerLiteral *ArraySize
11262 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11263 /*FIXME*/BracketsRange.getBegin());
11264 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011265 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011266 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011267}
Mike Stump11289f42009-09-09 15:08:12 +000011268
Douglas Gregord6ff3322009-08-04 16:50:30 +000011269template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011270QualType
11271TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011272 ArrayType::ArraySizeModifier SizeMod,
11273 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011274 unsigned IndexTypeQuals,
11275 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011276 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011277 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011278}
11279
11280template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011281QualType
Mike Stump11289f42009-09-09 15:08:12 +000011282TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011283 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011284 unsigned IndexTypeQuals,
11285 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011286 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011287 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011288}
Mike Stump11289f42009-09-09 15:08:12 +000011289
Douglas Gregord6ff3322009-08-04 16:50:30 +000011290template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011291QualType
11292TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011293 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011294 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011295 unsigned IndexTypeQuals,
11296 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011297 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011298 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011299 IndexTypeQuals, BracketsRange);
11300}
11301
11302template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011303QualType
11304TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011305 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011306 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011307 unsigned IndexTypeQuals,
11308 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011309 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011310 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011311 IndexTypeQuals, BracketsRange);
11312}
11313
11314template<typename Derived>
11315QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011316 unsigned NumElements,
11317 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011318 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011319 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011320}
Mike Stump11289f42009-09-09 15:08:12 +000011321
Douglas Gregord6ff3322009-08-04 16:50:30 +000011322template<typename Derived>
11323QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11324 unsigned NumElements,
11325 SourceLocation AttributeLoc) {
11326 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11327 NumElements, true);
11328 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011329 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11330 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011331 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011332}
Mike Stump11289f42009-09-09 15:08:12 +000011333
Douglas Gregord6ff3322009-08-04 16:50:30 +000011334template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011335QualType
11336TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011337 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011338 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011339 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011340}
Mike Stump11289f42009-09-09 15:08:12 +000011341
Douglas Gregord6ff3322009-08-04 16:50:30 +000011342template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011343QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11344 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011345 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011346 const FunctionProtoType::ExtProtoInfo &EPI) {
11347 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011348 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011349 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011350 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011351}
Mike Stump11289f42009-09-09 15:08:12 +000011352
Douglas Gregord6ff3322009-08-04 16:50:30 +000011353template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011354QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11355 return SemaRef.Context.getFunctionNoProtoType(T);
11356}
11357
11358template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011359QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11360 assert(D && "no decl found");
11361 if (D->isInvalidDecl()) return QualType();
11362
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011363 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011364 TypeDecl *Ty;
11365 if (isa<UsingDecl>(D)) {
11366 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011367 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011368 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11369
11370 // A valid resolved using typename decl points to exactly one type decl.
11371 assert(++Using->shadow_begin() == Using->shadow_end());
11372 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011373
John McCallb96ec562009-12-04 22:46:56 +000011374 } else {
11375 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11376 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11377 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11378 }
11379
11380 return SemaRef.Context.getTypeDeclType(Ty);
11381}
11382
11383template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011384QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11385 SourceLocation Loc) {
11386 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011387}
11388
11389template<typename Derived>
11390QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11391 return SemaRef.Context.getTypeOfType(Underlying);
11392}
11393
11394template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011395QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11396 SourceLocation Loc) {
11397 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011398}
11399
11400template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011401QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11402 UnaryTransformType::UTTKind UKind,
11403 SourceLocation Loc) {
11404 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11405}
11406
11407template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011408QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011409 TemplateName Template,
11410 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011411 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011412 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011413}
Mike Stump11289f42009-09-09 15:08:12 +000011414
Douglas Gregor1135c352009-08-06 05:28:30 +000011415template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011416QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11417 SourceLocation KWLoc) {
11418 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11419}
11420
11421template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011422QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11423 SourceLocation KWLoc) {
11424 return SemaRef.BuildPipeType(ValueType, KWLoc);
11425}
11426
11427template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011428TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011429TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011430 bool TemplateKW,
11431 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011432 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011433 Template);
11434}
11435
11436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011437TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011438TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11439 const IdentifierInfo &Name,
11440 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011441 QualType ObjectType,
11442 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011443 UnqualifiedId TemplateName;
11444 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011445 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011446 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011447 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011448 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011449 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011450 /*EnteringContext=*/false,
11451 Template);
John McCall31f82722010-11-12 08:19:04 +000011452 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011453}
Mike Stump11289f42009-09-09 15:08:12 +000011454
Douglas Gregora16548e2009-08-11 05:31:07 +000011455template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011456TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011457TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011458 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011459 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011460 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011461 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011462 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011463 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011464 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011465 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011466 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011467 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011468 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011469 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011470 /*EnteringContext=*/false,
11471 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011472 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011473}
Chad Rosier1dcde962012-08-08 18:46:20 +000011474
Douglas Gregor71395fa2009-11-04 00:56:37 +000011475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011476ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011477TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11478 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011479 Expr *OrigCallee,
11480 Expr *First,
11481 Expr *Second) {
11482 Expr *Callee = OrigCallee->IgnoreParenCasts();
11483 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011484
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011485 if (First->getObjectKind() == OK_ObjCProperty) {
11486 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11487 if (BinaryOperator::isAssignmentOp(Opc))
11488 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11489 First, Second);
11490 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11491 if (Result.isInvalid())
11492 return ExprError();
11493 First = Result.get();
11494 }
11495
11496 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11497 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11498 if (Result.isInvalid())
11499 return ExprError();
11500 Second = Result.get();
11501 }
11502
Douglas Gregora16548e2009-08-11 05:31:07 +000011503 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011504 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011505 if (!First->getType()->isOverloadableType() &&
11506 !Second->getType()->isOverloadableType())
11507 return getSema().CreateBuiltinArraySubscriptExpr(First,
11508 Callee->getLocStart(),
11509 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011510 } else if (Op == OO_Arrow) {
11511 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011512 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11513 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011514 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011515 // The argument is not of overloadable type, so try to create a
11516 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011517 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011518 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011519
John McCallb268a282010-08-23 23:25:46 +000011520 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011521 }
11522 } else {
John McCallb268a282010-08-23 23:25:46 +000011523 if (!First->getType()->isOverloadableType() &&
11524 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011525 // Neither of the arguments is an overloadable type, so try to
11526 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011527 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011528 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011529 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011530 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011532
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011533 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011534 }
11535 }
Mike Stump11289f42009-09-09 15:08:12 +000011536
11537 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011538 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011539 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011540
John McCallb268a282010-08-23 23:25:46 +000011541 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011542 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011543 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011544 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011545 // If we've resolved this to a particular non-member function, just call
11546 // that function. If we resolved it to a member function,
11547 // CreateOverloaded* will find that function for us.
11548 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11549 if (!isa<CXXMethodDecl>(ND))
11550 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011551 }
Mike Stump11289f42009-09-09 15:08:12 +000011552
Douglas Gregora16548e2009-08-11 05:31:07 +000011553 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011554 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011555 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011556
Douglas Gregora16548e2009-08-11 05:31:07 +000011557 // Create the overloaded operator invocation for unary operators.
11558 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011559 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011560 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011561 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011562 }
Mike Stump11289f42009-09-09 15:08:12 +000011563
Douglas Gregore9d62932011-07-15 16:25:15 +000011564 if (Op == OO_Subscript) {
11565 SourceLocation LBrace;
11566 SourceLocation RBrace;
11567
11568 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011569 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011570 LBrace = SourceLocation::getFromRawEncoding(
11571 NameLoc.CXXOperatorName.BeginOpNameLoc);
11572 RBrace = SourceLocation::getFromRawEncoding(
11573 NameLoc.CXXOperatorName.EndOpNameLoc);
11574 } else {
11575 LBrace = Callee->getLocStart();
11576 RBrace = OpLoc;
11577 }
11578
11579 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11580 First, Second);
11581 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011582
Douglas Gregora16548e2009-08-11 05:31:07 +000011583 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011584 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011585 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011586 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11587 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011589
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011590 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011591}
Mike Stump11289f42009-09-09 15:08:12 +000011592
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011593template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011594ExprResult
John McCallb268a282010-08-23 23:25:46 +000011595TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011596 SourceLocation OperatorLoc,
11597 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011598 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011599 TypeSourceInfo *ScopeType,
11600 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011601 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011602 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011603 QualType BaseType = Base->getType();
11604 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011605 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011606 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011607 !BaseType->getAs<PointerType>()->getPointeeType()
11608 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011609 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011610 return SemaRef.BuildPseudoDestructorExpr(
11611 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11612 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011613 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011614
Douglas Gregor678f90d2010-02-25 01:56:36 +000011615 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011616 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11617 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11618 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11619 NameInfo.setNamedTypeInfo(DestroyedType);
11620
Richard Smith8e4a3862012-05-15 06:15:11 +000011621 // The scope type is now known to be a valid nested name specifier
11622 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011623 if (ScopeType) {
11624 if (!ScopeType->getType()->getAs<TagType>()) {
11625 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11626 diag::err_expected_class_or_namespace)
11627 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11628 return ExprError();
11629 }
11630 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11631 CCLoc);
11632 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011633
Abramo Bagnara7945c982012-01-27 09:46:47 +000011634 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011635 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011636 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011637 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011638 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011639 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011640 /*TemplateArgs*/ nullptr,
11641 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011642}
11643
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011644template<typename Derived>
11645StmtResult
11646TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011647 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011648 CapturedDecl *CD = S->getCapturedDecl();
11649 unsigned NumParams = CD->getNumParams();
11650 unsigned ContextParamPos = CD->getContextParamPosition();
11651 SmallVector<Sema::CapturedParamNameType, 4> Params;
11652 for (unsigned I = 0; I < NumParams; ++I) {
11653 if (I != ContextParamPos) {
11654 Params.push_back(
11655 std::make_pair(
11656 CD->getParam(I)->getName(),
11657 getDerived().TransformType(CD->getParam(I)->getType())));
11658 } else {
11659 Params.push_back(std::make_pair(StringRef(), QualType()));
11660 }
11661 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011662 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011663 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011664 StmtResult Body;
11665 {
11666 Sema::CompoundScopeRAII CompoundScope(getSema());
11667 Body = getDerived().TransformStmt(S->getCapturedStmt());
11668 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011669
11670 if (Body.isInvalid()) {
11671 getSema().ActOnCapturedRegionError();
11672 return StmtError();
11673 }
11674
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011675 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011676}
11677
Douglas Gregord6ff3322009-08-04 16:50:30 +000011678} // end namespace clang
11679
Hans Wennborg59dbe862015-09-29 20:56:43 +000011680#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H