blob: 4b614d888c1a02b3cf8ef27b90ff476267e51c90 [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>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007405StmtResult
7406TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7407 DeclarationNameInfo DirName;
7408 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7409 D->getLocStart());
7410 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7411 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7412 return Res;
7413}
7414
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007415template <typename Derived>
7416StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7417 OMPCancellationPointDirective *D) {
7418 DeclarationNameInfo DirName;
7419 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7420 nullptr, D->getLocStart());
7421 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7422 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7423 return Res;
7424}
7425
Alexey Bataev80909872015-07-02 11:25:17 +00007426template <typename Derived>
7427StmtResult
7428TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7429 DeclarationNameInfo DirName;
7430 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7431 D->getLocStart());
7432 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7433 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7434 return Res;
7435}
7436
Alexey Bataev49f6e782015-12-01 04:18:41 +00007437template <typename Derived>
7438StmtResult
7439TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7440 DeclarationNameInfo DirName;
7441 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7442 D->getLocStart());
7443 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7444 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7445 return Res;
7446}
7447
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007448template <typename Derived>
7449StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7450 OMPTaskLoopSimdDirective *D) {
7451 DeclarationNameInfo DirName;
7452 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7453 nullptr, D->getLocStart());
7454 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7455 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7456 return Res;
7457}
7458
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007459template <typename Derived>
7460StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7461 OMPDistributeDirective *D) {
7462 DeclarationNameInfo DirName;
7463 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7464 D->getLocStart());
7465 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7466 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7467 return Res;
7468}
7469
Alexander Musman64d33f12014-06-04 07:53:32 +00007470//===----------------------------------------------------------------------===//
7471// OpenMP clause transformation
7472//===----------------------------------------------------------------------===//
7473template <typename Derived>
7474OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007475 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7476 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007477 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007478 return getDerived().RebuildOMPIfClause(
7479 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7480 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007481}
7482
Alexander Musman64d33f12014-06-04 07:53:32 +00007483template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007484OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7485 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7486 if (Cond.isInvalid())
7487 return nullptr;
7488 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7489 C->getLParenLoc(), C->getLocEnd());
7490}
7491
7492template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007493OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007494TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7495 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7496 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007497 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007498 return getDerived().RebuildOMPNumThreadsClause(
7499 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007500}
7501
Alexey Bataev62c87d22014-03-21 04:51:18 +00007502template <typename Derived>
7503OMPClause *
7504TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7505 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7506 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007507 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007508 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007509 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007510}
7511
Alexander Musman8bd31e62014-05-27 15:12:19 +00007512template <typename Derived>
7513OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007514TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7515 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7516 if (E.isInvalid())
7517 return nullptr;
7518 return getDerived().RebuildOMPSimdlenClause(
7519 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7520}
7521
7522template <typename Derived>
7523OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007524TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7525 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7526 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007527 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007528 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007529 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007530}
7531
Alexander Musman64d33f12014-06-04 07:53:32 +00007532template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007533OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007534TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007535 return getDerived().RebuildOMPDefaultClause(
7536 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7537 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007538}
7539
Alexander Musman64d33f12014-06-04 07:53:32 +00007540template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007541OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007542TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007543 return getDerived().RebuildOMPProcBindClause(
7544 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7545 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007546}
7547
Alexander Musman64d33f12014-06-04 07:53:32 +00007548template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007549OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007550TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7551 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7552 if (E.isInvalid())
7553 return nullptr;
7554 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007555 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007556 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007557 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007558 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7559}
7560
7561template <typename Derived>
7562OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007563TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007564 ExprResult E;
7565 if (auto *Num = C->getNumForLoops()) {
7566 E = getDerived().TransformExpr(Num);
7567 if (E.isInvalid())
7568 return nullptr;
7569 }
7570 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7571 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007572}
7573
7574template <typename Derived>
7575OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007576TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7577 // No need to rebuild this clause, no template-dependent parameters.
7578 return C;
7579}
7580
7581template <typename Derived>
7582OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007583TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7584 // No need to rebuild this clause, no template-dependent parameters.
7585 return C;
7586}
7587
7588template <typename Derived>
7589OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007590TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7591 // No need to rebuild this clause, no template-dependent parameters.
7592 return C;
7593}
7594
7595template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007596OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7597 // No need to rebuild this clause, no template-dependent parameters.
7598 return C;
7599}
7600
7601template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007602OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7603 // No need to rebuild this clause, no template-dependent parameters.
7604 return C;
7605}
7606
7607template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007608OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007609TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7610 // No need to rebuild this clause, no template-dependent parameters.
7611 return C;
7612}
7613
7614template <typename Derived>
7615OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007616TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7617 // No need to rebuild this clause, no template-dependent parameters.
7618 return C;
7619}
7620
7621template <typename Derived>
7622OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007623TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7624 // No need to rebuild this clause, no template-dependent parameters.
7625 return C;
7626}
7627
7628template <typename Derived>
7629OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007630TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7631 // No need to rebuild this clause, no template-dependent parameters.
7632 return C;
7633}
7634
7635template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007636OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7637 // No need to rebuild this clause, no template-dependent parameters.
7638 return C;
7639}
7640
7641template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007642OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007643TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7644 // No need to rebuild this clause, no template-dependent parameters.
7645 return C;
7646}
7647
7648template <typename Derived>
7649OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007650TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007651 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007652 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007653 for (auto *VE : C->varlists()) {
7654 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007655 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007656 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007657 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007658 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007659 return getDerived().RebuildOMPPrivateClause(
7660 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007661}
7662
Alexander Musman64d33f12014-06-04 07:53:32 +00007663template <typename Derived>
7664OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7665 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007666 llvm::SmallVector<Expr *, 16> Vars;
7667 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007668 for (auto *VE : C->varlists()) {
7669 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007670 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007671 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007672 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007673 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007674 return getDerived().RebuildOMPFirstprivateClause(
7675 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007676}
7677
Alexander Musman64d33f12014-06-04 07:53:32 +00007678template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007679OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007680TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7681 llvm::SmallVector<Expr *, 16> Vars;
7682 Vars.reserve(C->varlist_size());
7683 for (auto *VE : C->varlists()) {
7684 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7685 if (EVar.isInvalid())
7686 return nullptr;
7687 Vars.push_back(EVar.get());
7688 }
7689 return getDerived().RebuildOMPLastprivateClause(
7690 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7691}
7692
7693template <typename Derived>
7694OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007695TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7696 llvm::SmallVector<Expr *, 16> Vars;
7697 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007698 for (auto *VE : C->varlists()) {
7699 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007700 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007701 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007702 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007703 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007704 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7705 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007706}
7707
Alexander Musman64d33f12014-06-04 07:53:32 +00007708template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007709OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007710TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7711 llvm::SmallVector<Expr *, 16> Vars;
7712 Vars.reserve(C->varlist_size());
7713 for (auto *VE : C->varlists()) {
7714 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7715 if (EVar.isInvalid())
7716 return nullptr;
7717 Vars.push_back(EVar.get());
7718 }
7719 CXXScopeSpec ReductionIdScopeSpec;
7720 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7721
7722 DeclarationNameInfo NameInfo = C->getNameInfo();
7723 if (NameInfo.getName()) {
7724 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7725 if (!NameInfo.getName())
7726 return nullptr;
7727 }
7728 return getDerived().RebuildOMPReductionClause(
7729 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7730 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7731}
7732
7733template <typename Derived>
7734OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007735TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7736 llvm::SmallVector<Expr *, 16> Vars;
7737 Vars.reserve(C->varlist_size());
7738 for (auto *VE : C->varlists()) {
7739 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7740 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007741 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007742 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007743 }
7744 ExprResult Step = getDerived().TransformExpr(C->getStep());
7745 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007746 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007747 return getDerived().RebuildOMPLinearClause(
7748 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7749 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007750}
7751
Alexander Musman64d33f12014-06-04 07:53:32 +00007752template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007753OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007754TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7755 llvm::SmallVector<Expr *, 16> Vars;
7756 Vars.reserve(C->varlist_size());
7757 for (auto *VE : C->varlists()) {
7758 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7759 if (EVar.isInvalid())
7760 return nullptr;
7761 Vars.push_back(EVar.get());
7762 }
7763 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7764 if (Alignment.isInvalid())
7765 return nullptr;
7766 return getDerived().RebuildOMPAlignedClause(
7767 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7768 C->getColonLoc(), C->getLocEnd());
7769}
7770
Alexander Musman64d33f12014-06-04 07:53:32 +00007771template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007772OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007773TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7774 llvm::SmallVector<Expr *, 16> Vars;
7775 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007776 for (auto *VE : C->varlists()) {
7777 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007778 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007779 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007780 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007781 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007782 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7783 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007784}
7785
Alexey Bataevbae9a792014-06-27 10:37:06 +00007786template <typename Derived>
7787OMPClause *
7788TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7789 llvm::SmallVector<Expr *, 16> Vars;
7790 Vars.reserve(C->varlist_size());
7791 for (auto *VE : C->varlists()) {
7792 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7793 if (EVar.isInvalid())
7794 return nullptr;
7795 Vars.push_back(EVar.get());
7796 }
7797 return getDerived().RebuildOMPCopyprivateClause(
7798 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7799}
7800
Alexey Bataev6125da92014-07-21 11:26:11 +00007801template <typename Derived>
7802OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7803 llvm::SmallVector<Expr *, 16> Vars;
7804 Vars.reserve(C->varlist_size());
7805 for (auto *VE : C->varlists()) {
7806 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7807 if (EVar.isInvalid())
7808 return nullptr;
7809 Vars.push_back(EVar.get());
7810 }
7811 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7812 C->getLParenLoc(), C->getLocEnd());
7813}
7814
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007815template <typename Derived>
7816OMPClause *
7817TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7818 llvm::SmallVector<Expr *, 16> Vars;
7819 Vars.reserve(C->varlist_size());
7820 for (auto *VE : C->varlists()) {
7821 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7822 if (EVar.isInvalid())
7823 return nullptr;
7824 Vars.push_back(EVar.get());
7825 }
7826 return getDerived().RebuildOMPDependClause(
7827 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7828 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7829}
7830
Michael Wonge710d542015-08-07 16:16:36 +00007831template <typename Derived>
7832OMPClause *
7833TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7834 ExprResult E = getDerived().TransformExpr(C->getDevice());
7835 if (E.isInvalid())
7836 return nullptr;
7837 return getDerived().RebuildOMPDeviceClause(
7838 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7839}
7840
Kelvin Li0bff7af2015-11-23 05:32:03 +00007841template <typename Derived>
7842OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7843 llvm::SmallVector<Expr *, 16> Vars;
7844 Vars.reserve(C->varlist_size());
7845 for (auto *VE : C->varlists()) {
7846 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7847 if (EVar.isInvalid())
7848 return nullptr;
7849 Vars.push_back(EVar.get());
7850 }
7851 return getDerived().RebuildOMPMapClause(
7852 C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7853 C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7854 C->getLocEnd());
7855}
7856
Kelvin Li099bb8c2015-11-24 20:50:12 +00007857template <typename Derived>
7858OMPClause *
7859TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7860 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7861 if (E.isInvalid())
7862 return nullptr;
7863 return getDerived().RebuildOMPNumTeamsClause(
7864 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7865}
7866
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007867template <typename Derived>
7868OMPClause *
7869TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7870 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7871 if (E.isInvalid())
7872 return nullptr;
7873 return getDerived().RebuildOMPThreadLimitClause(
7874 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7875}
7876
Alexey Bataeva0569352015-12-01 10:17:31 +00007877template <typename Derived>
7878OMPClause *
7879TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7880 ExprResult E = getDerived().TransformExpr(C->getPriority());
7881 if (E.isInvalid())
7882 return nullptr;
7883 return getDerived().RebuildOMPPriorityClause(
7884 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7885}
7886
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007887template <typename Derived>
7888OMPClause *
7889TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7890 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7891 if (E.isInvalid())
7892 return nullptr;
7893 return getDerived().RebuildOMPGrainsizeClause(
7894 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7895}
7896
Alexey Bataev382967a2015-12-08 12:06:20 +00007897template <typename Derived>
7898OMPClause *
7899TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7900 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7901 if (E.isInvalid())
7902 return nullptr;
7903 return getDerived().RebuildOMPNumTasksClause(
7904 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7905}
7906
Alexey Bataev28c75412015-12-15 08:19:24 +00007907template <typename Derived>
7908OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
7909 ExprResult E = getDerived().TransformExpr(C->getHint());
7910 if (E.isInvalid())
7911 return nullptr;
7912 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
7913 C->getLParenLoc(), C->getLocEnd());
7914}
7915
Carlo Bertollib4adf552016-01-15 18:50:31 +00007916template <typename Derived>
7917OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
7918 OMPDistScheduleClause *C) {
7919 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7920 if (E.isInvalid())
7921 return nullptr;
7922 return getDerived().RebuildOMPDistScheduleClause(
7923 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7924 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7925}
7926
Douglas Gregorebe10102009-08-20 07:17:43 +00007927//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007928// Expression transformation
7929//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007932TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007933 if (!E->isTypeDependent())
7934 return E;
7935
7936 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7937 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007938}
Mike Stump11289f42009-09-09 15:08:12 +00007939
7940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007942TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007943 NestedNameSpecifierLoc QualifierLoc;
7944 if (E->getQualifierLoc()) {
7945 QualifierLoc
7946 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7947 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007948 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007949 }
John McCallce546572009-12-08 09:08:17 +00007950
7951 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007952 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7953 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007954 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007956
John McCall815039a2010-08-17 21:27:17 +00007957 DeclarationNameInfo NameInfo = E->getNameInfo();
7958 if (NameInfo.getName()) {
7959 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7960 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007961 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007962 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007963
7964 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007965 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007966 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007967 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007968 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007969
7970 // Mark it referenced in the new context regardless.
7971 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007972 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007973
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007974 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007975 }
John McCallce546572009-12-08 09:08:17 +00007976
Craig Topperc3ec1492014-05-26 06:22:03 +00007977 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007978 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007979 TemplateArgs = &TransArgs;
7980 TransArgs.setLAngleLoc(E->getLAngleLoc());
7981 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007982 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7983 E->getNumTemplateArgs(),
7984 TransArgs))
7985 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007986 }
7987
Chad Rosier1dcde962012-08-08 18:46:20 +00007988 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007989 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007990}
Mike Stump11289f42009-09-09 15:08:12 +00007991
Douglas Gregora16548e2009-08-11 05:31:07 +00007992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007993ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007994TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007995 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007996}
Mike Stump11289f42009-09-09 15:08:12 +00007997
Douglas Gregora16548e2009-08-11 05:31:07 +00007998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008000TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008001 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008002}
Mike Stump11289f42009-09-09 15:08:12 +00008003
Douglas Gregora16548e2009-08-11 05:31:07 +00008004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008006TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008007 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008008}
Mike Stump11289f42009-09-09 15:08:12 +00008009
Douglas Gregora16548e2009-08-11 05:31:07 +00008010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008012TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008013 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008014}
Mike Stump11289f42009-09-09 15:08:12 +00008015
Douglas Gregora16548e2009-08-11 05:31:07 +00008016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008017ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008018TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008019 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008020}
8021
8022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008023ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008024TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008025 if (FunctionDecl *FD = E->getDirectCallee())
8026 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008027 return SemaRef.MaybeBindToTemporary(E);
8028}
8029
8030template<typename Derived>
8031ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008032TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8033 ExprResult ControllingExpr =
8034 getDerived().TransformExpr(E->getControllingExpr());
8035 if (ControllingExpr.isInvalid())
8036 return ExprError();
8037
Chris Lattner01cf8db2011-07-20 06:58:45 +00008038 SmallVector<Expr *, 4> AssocExprs;
8039 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008040 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8041 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8042 if (TS) {
8043 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8044 if (!AssocType)
8045 return ExprError();
8046 AssocTypes.push_back(AssocType);
8047 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008048 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008049 }
8050
8051 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8052 if (AssocExpr.isInvalid())
8053 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008054 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008055 }
8056
8057 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8058 E->getDefaultLoc(),
8059 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008060 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008061 AssocTypes,
8062 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008063}
8064
8065template<typename Derived>
8066ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008067TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008068 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008069 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008071
Douglas Gregora16548e2009-08-11 05:31:07 +00008072 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008073 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008074
John McCallb268a282010-08-23 23:25:46 +00008075 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008076 E->getRParen());
8077}
8078
Richard Smithdb2630f2012-10-21 03:28:35 +00008079/// \brief The operand of a unary address-of operator has special rules: it's
8080/// allowed to refer to a non-static member of a class even if there's no 'this'
8081/// object available.
8082template<typename Derived>
8083ExprResult
8084TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8085 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008086 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008087 else
8088 return getDerived().TransformExpr(E);
8089}
8090
Mike Stump11289f42009-09-09 15:08:12 +00008091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008093TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008094 ExprResult SubExpr;
8095 if (E->getOpcode() == UO_AddrOf)
8096 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8097 else
8098 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008099 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008101
Douglas Gregora16548e2009-08-11 05:31:07 +00008102 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008103 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008104
Douglas Gregora16548e2009-08-11 05:31:07 +00008105 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8106 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008107 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008108}
Mike Stump11289f42009-09-09 15:08:12 +00008109
Douglas Gregora16548e2009-08-11 05:31:07 +00008110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008111ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008112TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8113 // Transform the type.
8114 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8115 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008116 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008117
Douglas Gregor882211c2010-04-28 22:16:22 +00008118 // Transform all of the components into components similar to what the
8119 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008120 // FIXME: It would be slightly more efficient in the non-dependent case to
8121 // just map FieldDecls, rather than requiring the rebuilder to look for
8122 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008123 // template code that we don't care.
8124 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008125 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008126 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008127 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008128 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008129 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008130 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008131 Comp.LocStart = ON.getSourceRange().getBegin();
8132 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008133 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008134 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008135 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008136 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008137 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008138 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008139
Douglas Gregor882211c2010-04-28 22:16:22 +00008140 ExprChanged = ExprChanged || Index.get() != FromIndex;
8141 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008142 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008143 break;
8144 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008145
James Y Knight7281c352015-12-29 22:31:18 +00008146 case OffsetOfNode::Field:
8147 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008148 Comp.isBrackets = false;
8149 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008150 if (!Comp.U.IdentInfo)
8151 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008152
Douglas Gregor882211c2010-04-28 22:16:22 +00008153 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008154
James Y Knight7281c352015-12-29 22:31:18 +00008155 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008156 // Will be recomputed during the rebuild.
8157 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008158 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008159
Douglas Gregor882211c2010-04-28 22:16:22 +00008160 Components.push_back(Comp);
8161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008162
Douglas Gregor882211c2010-04-28 22:16:22 +00008163 // If nothing changed, retain the existing expression.
8164 if (!getDerived().AlwaysRebuild() &&
8165 Type == E->getTypeSourceInfo() &&
8166 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008167 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008168
Douglas Gregor882211c2010-04-28 22:16:22 +00008169 // Build a new offsetof expression.
8170 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008171 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008172}
8173
8174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008175ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008176TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008177 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008178 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008179 return E;
John McCall8d69a212010-11-15 23:31:06 +00008180}
8181
8182template<typename Derived>
8183ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008184TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8185 return E;
8186}
8187
8188template<typename Derived>
8189ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008190TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008191 // Rebuild the syntactic form. The original syntactic form has
8192 // opaque-value expressions in it, so strip those away and rebuild
8193 // the result. This is a really awful way of doing this, but the
8194 // better solution (rebuilding the semantic expressions and
8195 // rebinding OVEs as necessary) doesn't work; we'd need
8196 // TreeTransform to not strip away implicit conversions.
8197 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8198 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008199 if (result.isInvalid()) return ExprError();
8200
8201 // If that gives us a pseudo-object result back, the pseudo-object
8202 // expression must have been an lvalue-to-rvalue conversion which we
8203 // should reapply.
8204 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008205 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008206
8207 return result;
8208}
8209
8210template<typename Derived>
8211ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008212TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8213 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008214 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008215 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008216
John McCallbcd03502009-12-07 02:54:59 +00008217 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008218 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008220
John McCall4c98fd82009-11-04 07:28:41 +00008221 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008222 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008223
Peter Collingbournee190dee2011-03-11 19:24:49 +00008224 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8225 E->getKind(),
8226 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 }
Mike Stump11289f42009-09-09 15:08:12 +00008228
Eli Friedmane4f22df2012-02-29 04:03:55 +00008229 // C++0x [expr.sizeof]p1:
8230 // The operand is either an expression, which is an unevaluated operand
8231 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008232 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8233 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008234
Reid Kleckner32506ed2014-06-12 23:03:48 +00008235 // Try to recover if we have something like sizeof(T::X) where X is a type.
8236 // Notably, there must be *exactly* one set of parens if X is a type.
8237 TypeSourceInfo *RecoveryTSI = nullptr;
8238 ExprResult SubExpr;
8239 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8240 if (auto *DRE =
8241 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8242 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8243 PE, DRE, false, &RecoveryTSI);
8244 else
8245 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8246
8247 if (RecoveryTSI) {
8248 return getDerived().RebuildUnaryExprOrTypeTrait(
8249 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8250 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008252
Eli Friedmane4f22df2012-02-29 04:03:55 +00008253 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008254 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008255
Peter Collingbournee190dee2011-03-11 19:24:49 +00008256 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8257 E->getOperatorLoc(),
8258 E->getKind(),
8259 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008260}
Mike Stump11289f42009-09-09 15:08:12 +00008261
Douglas Gregora16548e2009-08-11 05:31:07 +00008262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008263ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008264TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008265 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008266 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008268
John McCalldadc5752010-08-24 06:29:42 +00008269 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008270 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008272
8273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274 if (!getDerived().AlwaysRebuild() &&
8275 LHS.get() == E->getLHS() &&
8276 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008277 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008278
John McCallb268a282010-08-23 23:25:46 +00008279 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008280 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008281 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008282 E->getRBracketLoc());
8283}
Mike Stump11289f42009-09-09 15:08:12 +00008284
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008285template <typename Derived>
8286ExprResult
8287TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8288 ExprResult Base = getDerived().TransformExpr(E->getBase());
8289 if (Base.isInvalid())
8290 return ExprError();
8291
8292 ExprResult LowerBound;
8293 if (E->getLowerBound()) {
8294 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8295 if (LowerBound.isInvalid())
8296 return ExprError();
8297 }
8298
8299 ExprResult Length;
8300 if (E->getLength()) {
8301 Length = getDerived().TransformExpr(E->getLength());
8302 if (Length.isInvalid())
8303 return ExprError();
8304 }
8305
8306 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8307 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8308 return E;
8309
8310 return getDerived().RebuildOMPArraySectionExpr(
8311 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8312 Length.get(), E->getRBracketLoc());
8313}
8314
Mike Stump11289f42009-09-09 15:08:12 +00008315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008317TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008318 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008319 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008321 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008322
8323 // Transform arguments.
8324 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008325 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008326 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008327 &ArgChanged))
8328 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008329
Douglas Gregora16548e2009-08-11 05:31:07 +00008330 if (!getDerived().AlwaysRebuild() &&
8331 Callee.get() == E->getCallee() &&
8332 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008333 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008334
Douglas Gregora16548e2009-08-11 05:31:07 +00008335 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008336 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008337 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008338 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008339 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008340 E->getRParenLoc());
8341}
Mike Stump11289f42009-09-09 15:08:12 +00008342
8343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008345TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008346 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008347 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008349
Douglas Gregorea972d32011-02-28 21:54:11 +00008350 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008351 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008352 QualifierLoc
8353 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008354
Douglas Gregorea972d32011-02-28 21:54:11 +00008355 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008356 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008357 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008358 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008359
Eli Friedman2cfcef62009-12-04 06:40:45 +00008360 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008361 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8362 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008363 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008365
John McCall16df1e52010-03-30 21:47:33 +00008366 NamedDecl *FoundDecl = E->getFoundDecl();
8367 if (FoundDecl == E->getMemberDecl()) {
8368 FoundDecl = Member;
8369 } else {
8370 FoundDecl = cast_or_null<NamedDecl>(
8371 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8372 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008373 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008374 }
8375
Douglas Gregora16548e2009-08-11 05:31:07 +00008376 if (!getDerived().AlwaysRebuild() &&
8377 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008378 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008379 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008380 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008381 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008382
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008383 // Mark it referenced in the new context regardless.
8384 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008385 SemaRef.MarkMemberReferenced(E);
8386
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008387 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008388 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008389
John McCall6b51f282009-11-23 01:53:49 +00008390 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008391 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008392 TransArgs.setLAngleLoc(E->getLAngleLoc());
8393 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008394 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8395 E->getNumTemplateArgs(),
8396 TransArgs))
8397 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008398 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008399
Douglas Gregora16548e2009-08-11 05:31:07 +00008400 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008401 SourceLocation FakeOperatorLoc =
8402 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008403
John McCall38836f02010-01-15 08:34:02 +00008404 // FIXME: to do this check properly, we will need to preserve the
8405 // first-qualifier-in-scope here, just in case we had a dependent
8406 // base (and therefore couldn't do the check) and a
8407 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008408 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008409
John McCallb268a282010-08-23 23:25:46 +00008410 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008411 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008412 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008413 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008414 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008415 Member,
John McCall16df1e52010-03-30 21:47:33 +00008416 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008417 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008418 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008419 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008420}
Mike Stump11289f42009-09-09 15:08:12 +00008421
Douglas Gregora16548e2009-08-11 05:31:07 +00008422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008424TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008425 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008426 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008428
John McCalldadc5752010-08-24 06:29:42 +00008429 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008430 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008432
Douglas Gregora16548e2009-08-11 05:31:07 +00008433 if (!getDerived().AlwaysRebuild() &&
8434 LHS.get() == E->getLHS() &&
8435 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008436 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008437
Lang Hames5de91cc2012-10-02 04:45:10 +00008438 Sema::FPContractStateRAII FPContractState(getSema());
8439 getSema().FPFeatures.fp_contract = E->isFPContractable();
8440
Douglas Gregora16548e2009-08-11 05:31:07 +00008441 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008442 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008443}
8444
Mike Stump11289f42009-09-09 15:08:12 +00008445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008446ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008447TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008448 CompoundAssignOperator *E) {
8449 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008450}
Mike Stump11289f42009-09-09 15:08:12 +00008451
Douglas Gregora16548e2009-08-11 05:31:07 +00008452template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008453ExprResult TreeTransform<Derived>::
8454TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8455 // Just rebuild the common and RHS expressions and see whether we
8456 // get any changes.
8457
8458 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8459 if (commonExpr.isInvalid())
8460 return ExprError();
8461
8462 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8463 if (rhs.isInvalid())
8464 return ExprError();
8465
8466 if (!getDerived().AlwaysRebuild() &&
8467 commonExpr.get() == e->getCommon() &&
8468 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008469 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008470
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008471 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008472 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008473 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008474 e->getColonLoc(),
8475 rhs.get());
8476}
8477
8478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008479ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008480TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008481 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008482 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008483 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008484
John McCalldadc5752010-08-24 06:29:42 +00008485 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008486 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008488
John McCalldadc5752010-08-24 06:29:42 +00008489 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008491 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008492
Douglas Gregora16548e2009-08-11 05:31:07 +00008493 if (!getDerived().AlwaysRebuild() &&
8494 Cond.get() == E->getCond() &&
8495 LHS.get() == E->getLHS() &&
8496 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008497 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008498
John McCallb268a282010-08-23 23:25:46 +00008499 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008500 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008501 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008502 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008503 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008504}
Mike Stump11289f42009-09-09 15:08:12 +00008505
8506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008507ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008508TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008509 // Implicit casts are eliminated during transformation, since they
8510 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008511 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008512}
Mike Stump11289f42009-09-09 15:08:12 +00008513
Douglas Gregora16548e2009-08-11 05:31:07 +00008514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008516TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008517 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8518 if (!Type)
8519 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008520
John McCalldadc5752010-08-24 06:29:42 +00008521 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008522 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008523 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008525
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008527 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008528 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008529 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008530
John McCall97513962010-01-15 18:39:57 +00008531 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008532 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008533 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008534 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008535}
Mike Stump11289f42009-09-09 15:08:12 +00008536
Douglas Gregora16548e2009-08-11 05:31:07 +00008537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008539TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008540 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8541 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8542 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008543 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008544
John McCalldadc5752010-08-24 06:29:42 +00008545 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008546 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008547 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008548
Douglas Gregora16548e2009-08-11 05:31:07 +00008549 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008550 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008551 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008552 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008553
John McCall5d7aa7f2010-01-19 22:33:45 +00008554 // Note: the expression type doesn't necessarily match the
8555 // type-as-written, but that's okay, because it should always be
8556 // derivable from the initializer.
8557
John McCalle15bbff2010-01-18 19:35:47 +00008558 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008559 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008560 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008561}
Mike Stump11289f42009-09-09 15:08:12 +00008562
Douglas Gregora16548e2009-08-11 05:31:07 +00008563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008565TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008566 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008567 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008569
Douglas Gregora16548e2009-08-11 05:31:07 +00008570 if (!getDerived().AlwaysRebuild() &&
8571 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008572 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008573
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008575 SourceLocation FakeOperatorLoc =
8576 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008577 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 E->getAccessorLoc(),
8579 E->getAccessor());
8580}
Mike Stump11289f42009-09-09 15:08:12 +00008581
Douglas Gregora16548e2009-08-11 05:31:07 +00008582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008583ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008584TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008585 if (InitListExpr *Syntactic = E->getSyntacticForm())
8586 E = Syntactic;
8587
Douglas Gregora16548e2009-08-11 05:31:07 +00008588 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008589
Benjamin Kramerf0623432012-08-23 22:51:59 +00008590 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008591 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008592 Inits, &InitChanged))
8593 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008594
Richard Smith520449d2015-02-05 06:15:50 +00008595 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8596 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8597 // in some cases. We can't reuse it in general, because the syntactic and
8598 // semantic forms are linked, and we can't know that semantic form will
8599 // match even if the syntactic form does.
8600 }
Mike Stump11289f42009-09-09 15:08:12 +00008601
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008602 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008603 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008604}
Mike Stump11289f42009-09-09 15:08:12 +00008605
Douglas Gregora16548e2009-08-11 05:31:07 +00008606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008607ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008608TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008609 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008610
Douglas Gregorebe10102009-08-20 07:17:43 +00008611 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008612 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008613 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008615
Douglas Gregorebe10102009-08-20 07:17:43 +00008616 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008617 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008618 bool ExprChanged = false;
8619 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8620 DEnd = E->designators_end();
8621 D != DEnd; ++D) {
8622 if (D->isFieldDesignator()) {
8623 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8624 D->getDotLoc(),
8625 D->getFieldLoc()));
8626 continue;
8627 }
Mike Stump11289f42009-09-09 15:08:12 +00008628
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008630 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008631 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008632 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008633
8634 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008635 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008636
Douglas Gregora16548e2009-08-11 05:31:07 +00008637 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008638 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 continue;
8640 }
Mike Stump11289f42009-09-09 15:08:12 +00008641
Douglas Gregora16548e2009-08-11 05:31:07 +00008642 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008643 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008644 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8645 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008646 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008647
John McCalldadc5752010-08-24 06:29:42 +00008648 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008649 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008651
8652 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008653 End.get(),
8654 D->getLBracketLoc(),
8655 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008656
Douglas Gregora16548e2009-08-11 05:31:07 +00008657 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8658 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008659
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008660 ArrayExprs.push_back(Start.get());
8661 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008662 }
Mike Stump11289f42009-09-09 15:08:12 +00008663
Douglas Gregora16548e2009-08-11 05:31:07 +00008664 if (!getDerived().AlwaysRebuild() &&
8665 Init.get() == E->getInit() &&
8666 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008667 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008668
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008669 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008670 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008671 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008672}
Mike Stump11289f42009-09-09 15:08:12 +00008673
Yunzhong Gaocb779302015-06-10 00:27:52 +00008674// Seems that if TransformInitListExpr() only works on the syntactic form of an
8675// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8676template<typename Derived>
8677ExprResult
8678TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8679 DesignatedInitUpdateExpr *E) {
8680 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8681 "initializer");
8682 return ExprError();
8683}
8684
8685template<typename Derived>
8686ExprResult
8687TreeTransform<Derived>::TransformNoInitExpr(
8688 NoInitExpr *E) {
8689 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8690 return ExprError();
8691}
8692
Douglas Gregora16548e2009-08-11 05:31:07 +00008693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008694ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008695TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008696 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008697 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008698
Douglas Gregor3da3c062009-10-28 00:29:27 +00008699 // FIXME: Will we ever have proper type location here? Will we actually
8700 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008701 QualType T = getDerived().TransformType(E->getType());
8702 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008704
Douglas Gregora16548e2009-08-11 05:31:07 +00008705 if (!getDerived().AlwaysRebuild() &&
8706 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008707 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008708
Douglas Gregora16548e2009-08-11 05:31:07 +00008709 return getDerived().RebuildImplicitValueInitExpr(T);
8710}
Mike Stump11289f42009-09-09 15:08:12 +00008711
Douglas Gregora16548e2009-08-11 05:31:07 +00008712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008714TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008715 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8716 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008718
John McCalldadc5752010-08-24 06:29:42 +00008719 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008720 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008722
Douglas Gregora16548e2009-08-11 05:31:07 +00008723 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008724 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008725 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008726 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008727
John McCallb268a282010-08-23 23:25:46 +00008728 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008729 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008730}
8731
8732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008734TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008735 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008736 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008737 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8738 &ArgumentChanged))
8739 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008740
Douglas Gregora16548e2009-08-11 05:31:07 +00008741 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008742 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008743 E->getRParenLoc());
8744}
Mike Stump11289f42009-09-09 15:08:12 +00008745
Douglas Gregora16548e2009-08-11 05:31:07 +00008746/// \brief Transform an address-of-label expression.
8747///
8748/// By default, the transformation of an address-of-label expression always
8749/// rebuilds the expression, so that the label identifier can be resolved to
8750/// the corresponding label statement by semantic analysis.
8751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008753TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008754 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8755 E->getLabel());
8756 if (!LD)
8757 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008758
Douglas Gregora16548e2009-08-11 05:31:07 +00008759 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008760 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008761}
Mike Stump11289f42009-09-09 15:08:12 +00008762
8763template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008765TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008766 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008767 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008768 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008769 if (SubStmt.isInvalid()) {
8770 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008771 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008772 }
Mike Stump11289f42009-09-09 15:08:12 +00008773
Douglas Gregora16548e2009-08-11 05:31:07 +00008774 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008775 SubStmt.get() == E->getSubStmt()) {
8776 // Calling this an 'error' is unintuitive, but it does the right thing.
8777 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008778 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008779 }
Mike Stump11289f42009-09-09 15:08:12 +00008780
8781 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008782 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008783 E->getRParenLoc());
8784}
Mike Stump11289f42009-09-09 15:08:12 +00008785
Douglas Gregora16548e2009-08-11 05:31:07 +00008786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008788TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008789 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008790 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008792
John McCalldadc5752010-08-24 06:29:42 +00008793 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008794 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008796
John McCalldadc5752010-08-24 06:29:42 +00008797 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008798 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008800
Douglas Gregora16548e2009-08-11 05:31:07 +00008801 if (!getDerived().AlwaysRebuild() &&
8802 Cond.get() == E->getCond() &&
8803 LHS.get() == E->getLHS() &&
8804 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008805 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008806
Douglas Gregora16548e2009-08-11 05:31:07 +00008807 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008808 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008809 E->getRParenLoc());
8810}
Mike Stump11289f42009-09-09 15:08:12 +00008811
Douglas Gregora16548e2009-08-11 05:31:07 +00008812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008813ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008814TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008815 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008816}
8817
8818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008819ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008820TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008821 switch (E->getOperator()) {
8822 case OO_New:
8823 case OO_Delete:
8824 case OO_Array_New:
8825 case OO_Array_Delete:
8826 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008827
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008828 case OO_Call: {
8829 // This is a call to an object's operator().
8830 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8831
8832 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008833 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008834 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008835 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008836
8837 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008838 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8839 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008840
8841 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008842 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008843 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008844 Args))
8845 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008846
John McCallb268a282010-08-23 23:25:46 +00008847 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008848 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008849 E->getLocEnd());
8850 }
8851
8852#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8853 case OO_##Name:
8854#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8855#include "clang/Basic/OperatorKinds.def"
8856 case OO_Subscript:
8857 // Handled below.
8858 break;
8859
8860 case OO_Conditional:
8861 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008862
8863 case OO_None:
8864 case NUM_OVERLOADED_OPERATORS:
8865 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008866 }
8867
John McCalldadc5752010-08-24 06:29:42 +00008868 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008871
Richard Smithdb2630f2012-10-21 03:28:35 +00008872 ExprResult First;
8873 if (E->getOperator() == OO_Amp)
8874 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8875 else
8876 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008877 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008878 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008879
John McCalldadc5752010-08-24 06:29:42 +00008880 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008881 if (E->getNumArgs() == 2) {
8882 Second = getDerived().TransformExpr(E->getArg(1));
8883 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008884 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008885 }
Mike Stump11289f42009-09-09 15:08:12 +00008886
Douglas Gregora16548e2009-08-11 05:31:07 +00008887 if (!getDerived().AlwaysRebuild() &&
8888 Callee.get() == E->getCallee() &&
8889 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008890 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008891 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008892
Lang Hames5de91cc2012-10-02 04:45:10 +00008893 Sema::FPContractStateRAII FPContractState(getSema());
8894 getSema().FPFeatures.fp_contract = E->isFPContractable();
8895
Douglas Gregora16548e2009-08-11 05:31:07 +00008896 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8897 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008898 Callee.get(),
8899 First.get(),
8900 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008901}
Mike Stump11289f42009-09-09 15:08:12 +00008902
Douglas Gregora16548e2009-08-11 05:31:07 +00008903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008904ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008905TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8906 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008907}
Mike Stump11289f42009-09-09 15:08:12 +00008908
Douglas Gregora16548e2009-08-11 05:31:07 +00008909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008910ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008911TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8912 // Transform the callee.
8913 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8914 if (Callee.isInvalid())
8915 return ExprError();
8916
8917 // Transform exec config.
8918 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8919 if (EC.isInvalid())
8920 return ExprError();
8921
8922 // Transform arguments.
8923 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008924 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008925 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008926 &ArgChanged))
8927 return ExprError();
8928
8929 if (!getDerived().AlwaysRebuild() &&
8930 Callee.get() == E->getCallee() &&
8931 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008932 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008933
8934 // FIXME: Wrong source location information for the '('.
8935 SourceLocation FakeLParenLoc
8936 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8937 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008938 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008939 E->getRParenLoc(), EC.get());
8940}
8941
8942template<typename Derived>
8943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008944TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008945 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8946 if (!Type)
8947 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008948
John McCalldadc5752010-08-24 06:29:42 +00008949 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008950 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008951 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008953
Douglas Gregora16548e2009-08-11 05:31:07 +00008954 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008955 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008956 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008957 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008958 return getDerived().RebuildCXXNamedCastExpr(
8959 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8960 Type, E->getAngleBrackets().getEnd(),
8961 // FIXME. this should be '(' location
8962 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008963}
Mike Stump11289f42009-09-09 15:08:12 +00008964
Douglas Gregora16548e2009-08-11 05:31:07 +00008965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008967TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8968 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008969}
Mike Stump11289f42009-09-09 15:08:12 +00008970
8971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008972ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008973TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8974 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008975}
8976
Douglas Gregora16548e2009-08-11 05:31:07 +00008977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008978ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008979TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008980 CXXReinterpretCastExpr *E) {
8981 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008982}
Mike Stump11289f42009-09-09 15:08:12 +00008983
Douglas Gregora16548e2009-08-11 05:31:07 +00008984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008986TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8987 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008988}
Mike Stump11289f42009-09-09 15:08:12 +00008989
Douglas Gregora16548e2009-08-11 05:31:07 +00008990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008991ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008992TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008993 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008994 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8995 if (!Type)
8996 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008997
John McCalldadc5752010-08-24 06:29:42 +00008998 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008999 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009000 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009001 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009002
Douglas Gregora16548e2009-08-11 05:31:07 +00009003 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009004 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009005 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009006 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009007
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009008 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009009 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009010 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009011 E->getRParenLoc());
9012}
Mike Stump11289f42009-09-09 15:08:12 +00009013
Douglas Gregora16548e2009-08-11 05:31:07 +00009014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009015ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009016TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009017 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009018 TypeSourceInfo *TInfo
9019 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9020 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009021 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009022
Douglas Gregora16548e2009-08-11 05:31:07 +00009023 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009024 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009025 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009026
Douglas Gregor9da64192010-04-26 22:37:10 +00009027 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9028 E->getLocStart(),
9029 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009030 E->getLocEnd());
9031 }
Mike Stump11289f42009-09-09 15:08:12 +00009032
Eli Friedman456f0182012-01-20 01:26:23 +00009033 // We don't know whether the subexpression is potentially evaluated until
9034 // after we perform semantic analysis. We speculatively assume it is
9035 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009036 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009037 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9038 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009039
John McCalldadc5752010-08-24 06:29:42 +00009040 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009041 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009043
Douglas Gregora16548e2009-08-11 05:31:07 +00009044 if (!getDerived().AlwaysRebuild() &&
9045 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009046 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009047
Douglas Gregor9da64192010-04-26 22:37:10 +00009048 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9049 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009050 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009051 E->getLocEnd());
9052}
9053
9054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009055ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009056TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9057 if (E->isTypeOperand()) {
9058 TypeSourceInfo *TInfo
9059 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9060 if (!TInfo)
9061 return ExprError();
9062
9063 if (!getDerived().AlwaysRebuild() &&
9064 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009065 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009066
Douglas Gregor69735112011-03-06 17:40:41 +00009067 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009068 E->getLocStart(),
9069 TInfo,
9070 E->getLocEnd());
9071 }
9072
Francois Pichet9f4f2072010-09-08 12:20:18 +00009073 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9074
9075 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9076 if (SubExpr.isInvalid())
9077 return ExprError();
9078
9079 if (!getDerived().AlwaysRebuild() &&
9080 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009081 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009082
9083 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9084 E->getLocStart(),
9085 SubExpr.get(),
9086 E->getLocEnd());
9087}
9088
9089template<typename Derived>
9090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009091TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009092 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009093}
Mike Stump11289f42009-09-09 15:08:12 +00009094
Douglas Gregora16548e2009-08-11 05:31:07 +00009095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009096ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009097TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009098 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009099 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009100}
Mike Stump11289f42009-09-09 15:08:12 +00009101
Douglas Gregora16548e2009-08-11 05:31:07 +00009102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009103ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009104TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009105 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009106
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009107 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9108 // Make sure that we capture 'this'.
9109 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009110 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009111 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Douglas Gregorb15af892010-01-07 23:12:05 +00009113 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009114}
Mike Stump11289f42009-09-09 15:08:12 +00009115
Douglas Gregora16548e2009-08-11 05:31:07 +00009116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009118TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009119 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009120 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009122
Douglas Gregora16548e2009-08-11 05:31:07 +00009123 if (!getDerived().AlwaysRebuild() &&
9124 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009125 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009126
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009127 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9128 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009129}
Mike Stump11289f42009-09-09 15:08:12 +00009130
Douglas Gregora16548e2009-08-11 05:31:07 +00009131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009133TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009134 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009135 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9136 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009137 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009139
Chandler Carruth794da4c2010-02-08 06:42:49 +00009140 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009141 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009142 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009143
Douglas Gregor033f6752009-12-23 23:03:06 +00009144 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009145}
Mike Stump11289f42009-09-09 15:08:12 +00009146
Douglas Gregora16548e2009-08-11 05:31:07 +00009147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009148ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009149TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9150 FieldDecl *Field
9151 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9152 E->getField()));
9153 if (!Field)
9154 return ExprError();
9155
9156 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009157 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009158
9159 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9160}
9161
9162template<typename Derived>
9163ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009164TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9165 CXXScalarValueInitExpr *E) {
9166 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9167 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009168 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009169
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009171 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009172 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009173
Chad Rosier1dcde962012-08-08 18:46:20 +00009174 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009175 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009176 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009177}
Mike Stump11289f42009-09-09 15:08:12 +00009178
Douglas Gregora16548e2009-08-11 05:31:07 +00009179template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009180ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009181TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009182 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009183 TypeSourceInfo *AllocTypeInfo
9184 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9185 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009186 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009187
Douglas Gregora16548e2009-08-11 05:31:07 +00009188 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009189 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009190 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009192
Douglas Gregora16548e2009-08-11 05:31:07 +00009193 // Transform the placement arguments (if any).
9194 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009195 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009196 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009197 E->getNumPlacementArgs(), true,
9198 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009200
Sebastian Redl6047f072012-02-16 12:22:20 +00009201 // Transform the initializer (if any).
9202 Expr *OldInit = E->getInitializer();
9203 ExprResult NewInit;
9204 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009205 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009206 if (NewInit.isInvalid())
9207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009208
Sebastian Redl6047f072012-02-16 12:22:20 +00009209 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009210 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009211 if (E->getOperatorNew()) {
9212 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009213 getDerived().TransformDecl(E->getLocStart(),
9214 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009215 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009216 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009217 }
9218
Craig Topperc3ec1492014-05-26 06:22:03 +00009219 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009220 if (E->getOperatorDelete()) {
9221 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009222 getDerived().TransformDecl(E->getLocStart(),
9223 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009224 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009225 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009226 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009227
Douglas Gregora16548e2009-08-11 05:31:07 +00009228 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009229 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009230 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009231 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009232 OperatorNew == E->getOperatorNew() &&
9233 OperatorDelete == E->getOperatorDelete() &&
9234 !ArgumentChanged) {
9235 // Mark any declarations we need as referenced.
9236 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009237 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009238 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009239 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009240 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009241
Sebastian Redl6047f072012-02-16 12:22:20 +00009242 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009243 QualType ElementType
9244 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9245 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9246 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9247 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009248 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009249 }
9250 }
9251 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009252
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009253 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009254 }
Mike Stump11289f42009-09-09 15:08:12 +00009255
Douglas Gregor0744ef62010-09-07 21:49:58 +00009256 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009257 if (!ArraySize.get()) {
9258 // If no array size was specified, but the new expression was
9259 // instantiated with an array type (e.g., "new T" where T is
9260 // instantiated with "int[4]"), extract the outer bound from the
9261 // array type as our array size. We do this with constant and
9262 // dependently-sized array types.
9263 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9264 if (!ArrayT) {
9265 // Do nothing
9266 } else if (const ConstantArrayType *ConsArrayT
9267 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009268 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9269 SemaRef.Context.getSizeType(),
9270 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009271 AllocType = ConsArrayT->getElementType();
9272 } else if (const DependentSizedArrayType *DepArrayT
9273 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9274 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009275 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009276 AllocType = DepArrayT->getElementType();
9277 }
9278 }
9279 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009280
Douglas Gregora16548e2009-08-11 05:31:07 +00009281 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9282 E->isGlobalNew(),
9283 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009284 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009285 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009286 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009287 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009288 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009289 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009290 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009291 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009292}
Mike Stump11289f42009-09-09 15:08:12 +00009293
Douglas Gregora16548e2009-08-11 05:31:07 +00009294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009295ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009296TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009297 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009298 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009300
Douglas Gregord2d9da02010-02-26 00:38:10 +00009301 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009302 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009303 if (E->getOperatorDelete()) {
9304 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009305 getDerived().TransformDecl(E->getLocStart(),
9306 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009307 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009308 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009309 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009310
Douglas Gregora16548e2009-08-11 05:31:07 +00009311 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009312 Operand.get() == E->getArgument() &&
9313 OperatorDelete == E->getOperatorDelete()) {
9314 // Mark any declarations we need as referenced.
9315 // FIXME: instantiation-specific.
9316 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009317 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009318
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009319 if (!E->getArgument()->isTypeDependent()) {
9320 QualType Destroyed = SemaRef.Context.getBaseElementType(
9321 E->getDestroyedType());
9322 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9323 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009324 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009325 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009326 }
9327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009328
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009329 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009330 }
Mike Stump11289f42009-09-09 15:08:12 +00009331
Douglas Gregora16548e2009-08-11 05:31:07 +00009332 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9333 E->isGlobalDelete(),
9334 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009335 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009336}
Mike Stump11289f42009-09-09 15:08:12 +00009337
Douglas Gregora16548e2009-08-11 05:31:07 +00009338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009339ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009340TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009341 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009342 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009343 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009345
John McCallba7bf592010-08-24 05:47:05 +00009346 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009347 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009348 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009349 E->getOperatorLoc(),
9350 E->isArrow()? tok::arrow : tok::period,
9351 ObjectTypePtr,
9352 MayBePseudoDestructor);
9353 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009354 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009355
John McCallba7bf592010-08-24 05:47:05 +00009356 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009357 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9358 if (QualifierLoc) {
9359 QualifierLoc
9360 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9361 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009362 return ExprError();
9363 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009364 CXXScopeSpec SS;
9365 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009366
Douglas Gregor678f90d2010-02-25 01:56:36 +00009367 PseudoDestructorTypeStorage Destroyed;
9368 if (E->getDestroyedTypeInfo()) {
9369 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009370 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009371 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009372 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009373 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009374 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009375 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009376 // We aren't likely to be able to resolve the identifier down to a type
9377 // now anyway, so just retain the identifier.
9378 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9379 E->getDestroyedTypeLoc());
9380 } else {
9381 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009382 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009383 *E->getDestroyedTypeIdentifier(),
9384 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009385 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009386 SS, ObjectTypePtr,
9387 false);
9388 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009389 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009390
Douglas Gregor678f90d2010-02-25 01:56:36 +00009391 Destroyed
9392 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9393 E->getDestroyedTypeLoc());
9394 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009395
Craig Topperc3ec1492014-05-26 06:22:03 +00009396 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009397 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009398 CXXScopeSpec EmptySS;
9399 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009400 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009401 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009402 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009403 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009404
John McCallb268a282010-08-23 23:25:46 +00009405 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009406 E->getOperatorLoc(),
9407 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009408 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009409 ScopeTypeInfo,
9410 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009411 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009412 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009413}
Mike Stump11289f42009-09-09 15:08:12 +00009414
Douglas Gregorad8a3362009-09-04 17:36:40 +00009415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009416ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009417TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009418 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009419 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9420 Sema::LookupOrdinaryName);
9421
9422 // Transform all the decls.
9423 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9424 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009425 NamedDecl *InstD = static_cast<NamedDecl*>(
9426 getDerived().TransformDecl(Old->getNameLoc(),
9427 *I));
John McCall84d87672009-12-10 09:41:52 +00009428 if (!InstD) {
9429 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9430 // This can happen because of dependent hiding.
9431 if (isa<UsingShadowDecl>(*I))
9432 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009433 else {
9434 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009435 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009436 }
John McCall84d87672009-12-10 09:41:52 +00009437 }
John McCalle66edc12009-11-24 19:00:30 +00009438
9439 // Expand using declarations.
9440 if (isa<UsingDecl>(InstD)) {
9441 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009442 for (auto *I : UD->shadows())
9443 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009444 continue;
9445 }
9446
9447 R.addDecl(InstD);
9448 }
9449
9450 // Resolve a kind, but don't do any further analysis. If it's
9451 // ambiguous, the callee needs to deal with it.
9452 R.resolveKind();
9453
9454 // Rebuild the nested-name qualifier, if present.
9455 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009456 if (Old->getQualifierLoc()) {
9457 NestedNameSpecifierLoc QualifierLoc
9458 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9459 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009460 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009461
Douglas Gregor0da1d432011-02-28 20:01:57 +00009462 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009463 }
9464
Douglas Gregor9262f472010-04-27 18:19:34 +00009465 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009466 CXXRecordDecl *NamingClass
9467 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9468 Old->getNameLoc(),
9469 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009470 if (!NamingClass) {
9471 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009472 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009474
Douglas Gregorda7be082010-04-27 16:10:10 +00009475 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009476 }
9477
Abramo Bagnara7945c982012-01-27 09:46:47 +00009478 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9479
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009480 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009481 // it's a normal declaration name or member reference.
9482 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9483 NamedDecl *D = R.getAsSingle<NamedDecl>();
9484 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9485 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9486 // give a good diagnostic.
9487 if (D && D->isCXXInstanceMember()) {
9488 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9489 /*TemplateArgs=*/nullptr,
9490 /*Scope=*/nullptr);
9491 }
9492
John McCalle66edc12009-11-24 19:00:30 +00009493 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009494 }
John McCalle66edc12009-11-24 19:00:30 +00009495
9496 // If we have template arguments, rebuild them, then rebuild the
9497 // templateid expression.
9498 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009499 if (Old->hasExplicitTemplateArgs() &&
9500 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009501 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009502 TransArgs)) {
9503 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009504 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009505 }
John McCalle66edc12009-11-24 19:00:30 +00009506
Abramo Bagnara7945c982012-01-27 09:46:47 +00009507 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009508 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009509}
Mike Stump11289f42009-09-09 15:08:12 +00009510
Douglas Gregora16548e2009-08-11 05:31:07 +00009511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009512ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009513TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9514 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009515 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009516 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9517 TypeSourceInfo *From = E->getArg(I);
9518 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009519 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009520 TypeLocBuilder TLB;
9521 TLB.reserve(FromTL.getFullDataSize());
9522 QualType To = getDerived().TransformType(TLB, FromTL);
9523 if (To.isNull())
9524 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009525
Douglas Gregor29c42f22012-02-24 07:38:34 +00009526 if (To == From->getType())
9527 Args.push_back(From);
9528 else {
9529 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9530 ArgChanged = true;
9531 }
9532 continue;
9533 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009534
Douglas Gregor29c42f22012-02-24 07:38:34 +00009535 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009536
Douglas Gregor29c42f22012-02-24 07:38:34 +00009537 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009538 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009539 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9540 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9541 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009542
Douglas Gregor29c42f22012-02-24 07:38:34 +00009543 // Determine whether the set of unexpanded parameter packs can and should
9544 // be expanded.
9545 bool Expand = true;
9546 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009547 Optional<unsigned> OrigNumExpansions =
9548 ExpansionTL.getTypePtr()->getNumExpansions();
9549 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009550 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9551 PatternTL.getSourceRange(),
9552 Unexpanded,
9553 Expand, RetainExpansion,
9554 NumExpansions))
9555 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009556
Douglas Gregor29c42f22012-02-24 07:38:34 +00009557 if (!Expand) {
9558 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009559 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009560 // expansion.
9561 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009562
Douglas Gregor29c42f22012-02-24 07:38:34 +00009563 TypeLocBuilder TLB;
9564 TLB.reserve(From->getTypeLoc().getFullDataSize());
9565
9566 QualType To = getDerived().TransformType(TLB, PatternTL);
9567 if (To.isNull())
9568 return ExprError();
9569
Chad Rosier1dcde962012-08-08 18:46:20 +00009570 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009571 PatternTL.getSourceRange(),
9572 ExpansionTL.getEllipsisLoc(),
9573 NumExpansions);
9574 if (To.isNull())
9575 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009576
Douglas Gregor29c42f22012-02-24 07:38:34 +00009577 PackExpansionTypeLoc ToExpansionTL
9578 = TLB.push<PackExpansionTypeLoc>(To);
9579 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9580 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9581 continue;
9582 }
9583
9584 // Expand the pack expansion by substituting for each argument in the
9585 // pack(s).
9586 for (unsigned I = 0; I != *NumExpansions; ++I) {
9587 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9588 TypeLocBuilder TLB;
9589 TLB.reserve(PatternTL.getFullDataSize());
9590 QualType To = getDerived().TransformType(TLB, PatternTL);
9591 if (To.isNull())
9592 return ExprError();
9593
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009594 if (To->containsUnexpandedParameterPack()) {
9595 To = getDerived().RebuildPackExpansionType(To,
9596 PatternTL.getSourceRange(),
9597 ExpansionTL.getEllipsisLoc(),
9598 NumExpansions);
9599 if (To.isNull())
9600 return ExprError();
9601
9602 PackExpansionTypeLoc ToExpansionTL
9603 = TLB.push<PackExpansionTypeLoc>(To);
9604 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9605 }
9606
Douglas Gregor29c42f22012-02-24 07:38:34 +00009607 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9608 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009609
Douglas Gregor29c42f22012-02-24 07:38:34 +00009610 if (!RetainExpansion)
9611 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009612
Douglas Gregor29c42f22012-02-24 07:38:34 +00009613 // If we're supposed to retain a pack expansion, do so by temporarily
9614 // forgetting the partially-substituted parameter pack.
9615 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9616
9617 TypeLocBuilder TLB;
9618 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009619
Douglas Gregor29c42f22012-02-24 07:38:34 +00009620 QualType To = getDerived().TransformType(TLB, PatternTL);
9621 if (To.isNull())
9622 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009623
9624 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009625 PatternTL.getSourceRange(),
9626 ExpansionTL.getEllipsisLoc(),
9627 NumExpansions);
9628 if (To.isNull())
9629 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009630
Douglas Gregor29c42f22012-02-24 07:38:34 +00009631 PackExpansionTypeLoc ToExpansionTL
9632 = TLB.push<PackExpansionTypeLoc>(To);
9633 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9634 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009636
Douglas Gregor29c42f22012-02-24 07:38:34 +00009637 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009638 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009639
9640 return getDerived().RebuildTypeTrait(E->getTrait(),
9641 E->getLocStart(),
9642 Args,
9643 E->getLocEnd());
9644}
9645
9646template<typename Derived>
9647ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009648TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9649 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9650 if (!T)
9651 return ExprError();
9652
9653 if (!getDerived().AlwaysRebuild() &&
9654 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009655 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009656
9657 ExprResult SubExpr;
9658 {
9659 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9660 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9661 if (SubExpr.isInvalid())
9662 return ExprError();
9663
9664 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009665 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009666 }
9667
9668 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9669 E->getLocStart(),
9670 T,
9671 SubExpr.get(),
9672 E->getLocEnd());
9673}
9674
9675template<typename Derived>
9676ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009677TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9678 ExprResult SubExpr;
9679 {
9680 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9681 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9682 if (SubExpr.isInvalid())
9683 return ExprError();
9684
9685 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009686 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009687 }
9688
9689 return getDerived().RebuildExpressionTrait(
9690 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9691}
9692
Reid Kleckner32506ed2014-06-12 23:03:48 +00009693template <typename Derived>
9694ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9695 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9696 TypeSourceInfo **RecoveryTSI) {
9697 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9698 DRE, AddrTaken, RecoveryTSI);
9699
9700 // Propagate both errors and recovered types, which return ExprEmpty.
9701 if (!NewDRE.isUsable())
9702 return NewDRE;
9703
9704 // We got an expr, wrap it up in parens.
9705 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9706 return PE;
9707 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9708 PE->getRParen());
9709}
9710
9711template <typename Derived>
9712ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9713 DependentScopeDeclRefExpr *E) {
9714 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9715 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009716}
9717
9718template<typename Derived>
9719ExprResult
9720TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9721 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009722 bool IsAddressOfOperand,
9723 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009724 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009725 NestedNameSpecifierLoc QualifierLoc
9726 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9727 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009728 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009729 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009730
John McCall31f82722010-11-12 08:19:04 +00009731 // TODO: If this is a conversion-function-id, verify that the
9732 // destination type name (if present) resolves the same way after
9733 // instantiation as it did in the local scope.
9734
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009735 DeclarationNameInfo NameInfo
9736 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9737 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009738 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009739
John McCalle66edc12009-11-24 19:00:30 +00009740 if (!E->hasExplicitTemplateArgs()) {
9741 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009742 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009743 // Note: it is sufficient to compare the Name component of NameInfo:
9744 // if name has not changed, DNLoc has not changed either.
9745 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009746 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009747
Reid Kleckner32506ed2014-06-12 23:03:48 +00009748 return getDerived().RebuildDependentScopeDeclRefExpr(
9749 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9750 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009751 }
John McCall6b51f282009-11-23 01:53:49 +00009752
9753 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009754 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9755 E->getNumTemplateArgs(),
9756 TransArgs))
9757 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009758
Reid Kleckner32506ed2014-06-12 23:03:48 +00009759 return getDerived().RebuildDependentScopeDeclRefExpr(
9760 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9761 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009762}
9763
9764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009765ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009766TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009767 // CXXConstructExprs other than for list-initialization and
9768 // CXXTemporaryObjectExpr are always implicit, so when we have
9769 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009770 if ((E->getNumArgs() == 1 ||
9771 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009772 (!getDerived().DropCallArgument(E->getArg(0))) &&
9773 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009774 return getDerived().TransformExpr(E->getArg(0));
9775
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9777
9778 QualType T = getDerived().TransformType(E->getType());
9779 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009780 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009781
9782 CXXConstructorDecl *Constructor
9783 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009784 getDerived().TransformDecl(E->getLocStart(),
9785 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009786 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009788
Douglas Gregora16548e2009-08-11 05:31:07 +00009789 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009790 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009791 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009792 &ArgumentChanged))
9793 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009794
Douglas Gregora16548e2009-08-11 05:31:07 +00009795 if (!getDerived().AlwaysRebuild() &&
9796 T == E->getType() &&
9797 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009798 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009799 // Mark the constructor as referenced.
9800 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009801 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009803 }
Mike Stump11289f42009-09-09 15:08:12 +00009804
Douglas Gregordb121ba2009-12-14 16:27:04 +00009805 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9806 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009807 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009808 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009809 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009810 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009811 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009812 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009813 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009814}
Mike Stump11289f42009-09-09 15:08:12 +00009815
Douglas Gregora16548e2009-08-11 05:31:07 +00009816/// \brief Transform a C++ temporary-binding expression.
9817///
Douglas Gregor363b1512009-12-24 18:51:59 +00009818/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9819/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009822TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009823 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009824}
Mike Stump11289f42009-09-09 15:08:12 +00009825
John McCall5d413782010-12-06 08:20:24 +00009826/// \brief Transform a C++ expression that contains cleanups that should
9827/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009828///
John McCall5d413782010-12-06 08:20:24 +00009829/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009830/// just 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 McCall5d413782010-12-06 08:20:24 +00009833TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *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
Douglas Gregora16548e2009-08-11 05:31:07 +00009837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009838ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009839TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009840 CXXTemporaryObjectExpr *E) {
9841 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9842 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009844
Douglas Gregora16548e2009-08-11 05:31:07 +00009845 CXXConstructorDecl *Constructor
9846 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009847 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009848 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009849 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009851
Douglas Gregora16548e2009-08-11 05:31:07 +00009852 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009853 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009854 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009855 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009856 &ArgumentChanged))
9857 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009858
Douglas Gregora16548e2009-08-11 05:31:07 +00009859 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009860 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009861 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009862 !ArgumentChanged) {
9863 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009864 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009865 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009867
Richard Smithd59b8322012-12-19 01:39:02 +00009868 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009869 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9870 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009871 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009872 E->getLocEnd());
9873}
Mike Stump11289f42009-09-09 15:08:12 +00009874
Douglas Gregora16548e2009-08-11 05:31:07 +00009875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009876ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009877TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009878 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009879 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009880 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009881 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9882 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009883 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009884 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009885 CEnd = E->capture_end();
9886 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009887 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009888 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009889 EnterExpressionEvaluationContext EEEC(getSema(),
9890 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009891 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9892 C->getCapturedVar()->getInit(),
9893 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009894
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009895 if (NewExprInitResult.isInvalid())
9896 return ExprError();
9897 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009898
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009899 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009900 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +00009901 getSema().buildLambdaInitCaptureInitialization(
9902 C->getLocation(), OldVD->getType()->isReferenceType(),
9903 OldVD->getIdentifier(),
9904 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009905 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009906 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9907 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009908 }
9909
Faisal Vali2cba1332013-10-23 06:44:28 +00009910 // Transform the template parameters, and add them to the current
9911 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009912 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009913 E->getTemplateParameterList());
9914
Richard Smith01014ce2014-11-20 23:53:14 +00009915 // Transform the type of the original lambda's call operator.
9916 // The transformation MUST be done in the CurrentInstantiationScope since
9917 // it introduces a mapping of the original to the newly created
9918 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009919 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009920 {
9921 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9922 FunctionProtoTypeLoc OldCallOpFPTL =
9923 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009924
9925 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009926 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009927 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009928 QualType NewCallOpType = TransformFunctionProtoType(
9929 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009930 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9931 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9932 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009933 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009934 if (NewCallOpType.isNull())
9935 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009936 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9937 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009938 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009939
Richard Smithc38498f2015-04-27 21:27:54 +00009940 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9941 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9942 LSI->GLTemplateParameterList = TPL;
9943
Eli Friedmand564afb2012-09-19 01:18:11 +00009944 // Create the local class that will describe the lambda.
9945 CXXRecordDecl *Class
9946 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009947 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009948 /*KnownDependent=*/false,
9949 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009950 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9951
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009952 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009953 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9954 Class, E->getIntroducerRange(), NewCallOpTSI,
9955 E->getCallOperator()->getLocEnd(),
9956 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009957 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009958
Faisal Vali2cba1332013-10-23 06:44:28 +00009959 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009960 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009961
Douglas Gregorb4328232012-02-14 00:00:48 +00009962 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009963 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009964 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009965
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009966 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009967 getSema().buildLambdaScope(LSI, NewCallOperator,
9968 E->getIntroducerRange(),
9969 E->getCaptureDefault(),
9970 E->getCaptureDefaultLoc(),
9971 E->hasExplicitParameters(),
9972 E->hasExplicitResultType(),
9973 E->isMutable());
9974
9975 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009976
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009977 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009978 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009979 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009980 CEnd = E->capture_end();
9981 C != CEnd; ++C) {
9982 // When we hit the first implicit capture, tell Sema that we've finished
9983 // the list of explicit captures.
9984 if (!FinishedExplicitCaptures && C->isImplicit()) {
9985 getSema().finishLambdaExplicitCaptures(LSI);
9986 FinishedExplicitCaptures = true;
9987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009988
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009989 // Capturing 'this' is trivial.
9990 if (C->capturesThis()) {
9991 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9992 continue;
9993 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009994 // Captured expression will be recaptured during captured variables
9995 // rebuilding.
9996 if (C->capturesVLAType())
9997 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009998
Richard Smithba71c082013-05-16 06:20:58 +00009999 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010000 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010001 InitCaptureInfoTy InitExprTypePair =
10002 InitCaptureExprsAndTypes[C - E->capture_begin()];
10003 ExprResult Init = InitExprTypePair.first;
10004 QualType InitQualType = InitExprTypePair.second;
10005 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010006 Invalid = true;
10007 continue;
10008 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010009 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010010 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010011 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10012 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010013 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010014 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010015 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010016 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010017 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010018 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010019 continue;
10020 }
10021
10022 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10023
Douglas Gregor3e308b12012-02-14 19:27:52 +000010024 // Determine the capture kind for Sema.
10025 Sema::TryCaptureKind Kind
10026 = C->isImplicit()? Sema::TryCapture_Implicit
10027 : C->getCaptureKind() == LCK_ByCopy
10028 ? Sema::TryCapture_ExplicitByVal
10029 : Sema::TryCapture_ExplicitByRef;
10030 SourceLocation EllipsisLoc;
10031 if (C->isPackExpansion()) {
10032 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10033 bool ShouldExpand = false;
10034 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010035 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010036 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10037 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010038 Unexpanded,
10039 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010040 NumExpansions)) {
10041 Invalid = true;
10042 continue;
10043 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010044
Douglas Gregor3e308b12012-02-14 19:27:52 +000010045 if (ShouldExpand) {
10046 // The transform has determined that we should perform an expansion;
10047 // transform and capture each of the arguments.
10048 // expansion of the pattern. Do so.
10049 VarDecl *Pack = C->getCapturedVar();
10050 for (unsigned I = 0; I != *NumExpansions; ++I) {
10051 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10052 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010053 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010054 Pack));
10055 if (!CapturedVar) {
10056 Invalid = true;
10057 continue;
10058 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010059
Douglas Gregor3e308b12012-02-14 19:27:52 +000010060 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010061 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10062 }
Richard Smith9467be42014-06-06 17:33:35 +000010063
10064 // FIXME: Retain a pack expansion if RetainExpansion is true.
10065
Douglas Gregor3e308b12012-02-14 19:27:52 +000010066 continue;
10067 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010068
Douglas Gregor3e308b12012-02-14 19:27:52 +000010069 EllipsisLoc = C->getEllipsisLoc();
10070 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010071
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010072 // Transform the captured variable.
10073 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010074 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010075 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010076 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010077 Invalid = true;
10078 continue;
10079 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010080
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010081 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010082 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10083 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010084 }
10085 if (!FinishedExplicitCaptures)
10086 getSema().finishLambdaExplicitCaptures(LSI);
10087
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010088 // Enter a new evaluation context to insulate the lambda from any
10089 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010090 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010091
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010092 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010093 StmtResult Body =
10094 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10095
10096 // ActOnLambda* will pop the function scope for us.
10097 FuncScopeCleanup.disable();
10098
Douglas Gregorb4328232012-02-14 00:00:48 +000010099 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010100 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010101 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010102 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010103 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010104 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010105
Richard Smithc38498f2015-04-27 21:27:54 +000010106 // Copy the LSI before ActOnFinishFunctionBody removes it.
10107 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10108 // the call operator.
10109 auto LSICopy = *LSI;
10110 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10111 /*IsInstantiation*/ true);
10112 SavedContext.pop();
10113
10114 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10115 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010116}
10117
10118template<typename Derived>
10119ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010120TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010121 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010122 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10123 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010125
Douglas Gregora16548e2009-08-11 05:31:07 +000010126 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010127 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010128 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010129 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010130 &ArgumentChanged))
10131 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010132
Douglas Gregora16548e2009-08-11 05:31:07 +000010133 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010134 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010135 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010136 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010137
Douglas Gregora16548e2009-08-11 05:31:07 +000010138 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010139 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010140 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010141 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010142 E->getRParenLoc());
10143}
Mike Stump11289f42009-09-09 15:08:12 +000010144
Douglas Gregora16548e2009-08-11 05:31:07 +000010145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010146ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010147TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010148 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010149 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010150 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010151 Expr *OldBase;
10152 QualType BaseType;
10153 QualType ObjectType;
10154 if (!E->isImplicitAccess()) {
10155 OldBase = E->getBase();
10156 Base = getDerived().TransformExpr(OldBase);
10157 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010159
John McCall2d74de92009-12-01 22:10:20 +000010160 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010161 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010162 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010163 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010164 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010165 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010166 ObjectTy,
10167 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010168 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010169 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010170
John McCallba7bf592010-08-24 05:47:05 +000010171 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010172 BaseType = ((Expr*) Base.get())->getType();
10173 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010174 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010175 BaseType = getDerived().TransformType(E->getBaseType());
10176 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10177 }
Mike Stump11289f42009-09-09 15:08:12 +000010178
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010179 // Transform the first part of the nested-name-specifier that qualifies
10180 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010181 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010182 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010183 E->getFirstQualifierFoundInScope(),
10184 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010185
Douglas Gregore16af532011-02-28 18:50:33 +000010186 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010187 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010188 QualifierLoc
10189 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10190 ObjectType,
10191 FirstQualifierInScope);
10192 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010193 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010194 }
Mike Stump11289f42009-09-09 15:08:12 +000010195
Abramo Bagnara7945c982012-01-27 09:46:47 +000010196 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10197
John McCall31f82722010-11-12 08:19:04 +000010198 // TODO: If this is a conversion-function-id, verify that the
10199 // destination type name (if present) resolves the same way after
10200 // instantiation as it did in the local scope.
10201
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010202 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010203 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010204 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010206
John McCall2d74de92009-12-01 22:10:20 +000010207 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010208 // This is a reference to a member without an explicitly-specified
10209 // template argument list. Optimize for this common case.
10210 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010211 Base.get() == OldBase &&
10212 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010213 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010214 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010215 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010216 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010217
John McCallb268a282010-08-23 23:25:46 +000010218 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010219 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010220 E->isArrow(),
10221 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010222 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010223 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010224 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010225 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010226 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010227 }
10228
John McCall6b51f282009-11-23 01:53:49 +000010229 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010230 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10231 E->getNumTemplateArgs(),
10232 TransArgs))
10233 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010234
John McCallb268a282010-08-23 23:25:46 +000010235 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010236 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010237 E->isArrow(),
10238 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010239 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010240 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010241 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010242 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010243 &TransArgs);
10244}
10245
10246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010248TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010249 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010250 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010251 QualType BaseType;
10252 if (!Old->isImplicitAccess()) {
10253 Base = getDerived().TransformExpr(Old->getBase());
10254 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010255 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010256 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010257 Old->isArrow());
10258 if (Base.isInvalid())
10259 return ExprError();
10260 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010261 } else {
10262 BaseType = getDerived().TransformType(Old->getBaseType());
10263 }
John McCall10eae182009-11-30 22:42:35 +000010264
Douglas Gregor0da1d432011-02-28 20:01:57 +000010265 NestedNameSpecifierLoc QualifierLoc;
10266 if (Old->getQualifierLoc()) {
10267 QualifierLoc
10268 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10269 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010270 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010271 }
10272
Abramo Bagnara7945c982012-01-27 09:46:47 +000010273 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10274
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010275 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010276 Sema::LookupOrdinaryName);
10277
10278 // Transform all the decls.
10279 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10280 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010281 NamedDecl *InstD = static_cast<NamedDecl*>(
10282 getDerived().TransformDecl(Old->getMemberLoc(),
10283 *I));
John McCall84d87672009-12-10 09:41:52 +000010284 if (!InstD) {
10285 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10286 // This can happen because of dependent hiding.
10287 if (isa<UsingShadowDecl>(*I))
10288 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010289 else {
10290 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010291 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010292 }
John McCall84d87672009-12-10 09:41:52 +000010293 }
John McCall10eae182009-11-30 22:42:35 +000010294
10295 // Expand using declarations.
10296 if (isa<UsingDecl>(InstD)) {
10297 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010298 for (auto *I : UD->shadows())
10299 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010300 continue;
10301 }
10302
10303 R.addDecl(InstD);
10304 }
10305
10306 R.resolveKind();
10307
Douglas Gregor9262f472010-04-27 18:19:34 +000010308 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010309 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010310 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010311 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010312 Old->getMemberLoc(),
10313 Old->getNamingClass()));
10314 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010315 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010316
Douglas Gregorda7be082010-04-27 16:10:10 +000010317 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010318 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010319
John McCall10eae182009-11-30 22:42:35 +000010320 TemplateArgumentListInfo TransArgs;
10321 if (Old->hasExplicitTemplateArgs()) {
10322 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10323 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010324 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10325 Old->getNumTemplateArgs(),
10326 TransArgs))
10327 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010328 }
John McCall38836f02010-01-15 08:34:02 +000010329
10330 // FIXME: to do this check properly, we will need to preserve the
10331 // first-qualifier-in-scope here, just in case we had a dependent
10332 // base (and therefore couldn't do the check) and a
10333 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010334 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010335
John McCallb268a282010-08-23 23:25:46 +000010336 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010337 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010338 Old->getOperatorLoc(),
10339 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010340 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010341 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010342 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010343 R,
10344 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010345 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010346}
10347
10348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010349ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010350TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010351 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010352 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10353 if (SubExpr.isInvalid())
10354 return ExprError();
10355
10356 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010357 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010358
10359 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10360}
10361
10362template<typename Derived>
10363ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010364TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010365 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10366 if (Pattern.isInvalid())
10367 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010368
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010369 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010370 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010371
Douglas Gregorb8840002011-01-14 21:20:45 +000010372 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10373 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010374}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010375
10376template<typename Derived>
10377ExprResult
10378TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10379 // If E is not value-dependent, then nothing will change when we transform it.
10380 // Note: This is an instantiation-centric view.
10381 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010382 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010383
Richard Smithd784e682015-09-23 21:41:42 +000010384 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010385
Richard Smithd784e682015-09-23 21:41:42 +000010386 ArrayRef<TemplateArgument> PackArgs;
10387 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010388
Richard Smithd784e682015-09-23 21:41:42 +000010389 // Find the argument list to transform.
10390 if (E->isPartiallySubstituted()) {
10391 PackArgs = E->getPartialArguments();
10392 } else if (E->isValueDependent()) {
10393 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10394 bool ShouldExpand = false;
10395 bool RetainExpansion = false;
10396 Optional<unsigned> NumExpansions;
10397 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10398 Unexpanded,
10399 ShouldExpand, RetainExpansion,
10400 NumExpansions))
10401 return ExprError();
10402
10403 // If we need to expand the pack, build a template argument from it and
10404 // expand that.
10405 if (ShouldExpand) {
10406 auto *Pack = E->getPack();
10407 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10408 ArgStorage = getSema().Context.getPackExpansionType(
10409 getSema().Context.getTypeDeclType(TTPD), None);
10410 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10411 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10412 } else {
10413 auto *VD = cast<ValueDecl>(Pack);
10414 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10415 VK_RValue, E->getPackLoc());
10416 if (DRE.isInvalid())
10417 return ExprError();
10418 ArgStorage = new (getSema().Context) PackExpansionExpr(
10419 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10420 }
10421 PackArgs = ArgStorage;
10422 }
10423 }
10424
10425 // If we're not expanding the pack, just transform the decl.
10426 if (!PackArgs.size()) {
10427 auto *Pack = cast_or_null<NamedDecl>(
10428 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010429 if (!Pack)
10430 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010431 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10432 E->getPackLoc(),
10433 E->getRParenLoc(), None, None);
10434 }
10435
10436 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10437 E->getPackLoc());
10438 {
10439 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10440 typedef TemplateArgumentLocInventIterator<
10441 Derived, const TemplateArgument*> PackLocIterator;
10442 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10443 PackLocIterator(*this, PackArgs.end()),
10444 TransformedPackArgs, /*Uneval*/true))
10445 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010446 }
10447
Richard Smithd784e682015-09-23 21:41:42 +000010448 SmallVector<TemplateArgument, 8> Args;
10449 bool PartialSubstitution = false;
10450 for (auto &Loc : TransformedPackArgs.arguments()) {
10451 Args.push_back(Loc.getArgument());
10452 if (Loc.getArgument().isPackExpansion())
10453 PartialSubstitution = true;
10454 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010455
Richard Smithd784e682015-09-23 21:41:42 +000010456 if (PartialSubstitution)
10457 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10458 E->getPackLoc(),
10459 E->getRParenLoc(), None, Args);
10460
10461 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010462 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010463 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010464}
10465
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010466template<typename Derived>
10467ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010468TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10469 SubstNonTypeTemplateParmPackExpr *E) {
10470 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010471 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010472}
10473
10474template<typename Derived>
10475ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010476TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10477 SubstNonTypeTemplateParmExpr *E) {
10478 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010479 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010480}
10481
10482template<typename Derived>
10483ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010484TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10485 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010486 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010487}
10488
10489template<typename Derived>
10490ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010491TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10492 MaterializeTemporaryExpr *E) {
10493 return getDerived().TransformExpr(E->GetTemporaryExpr());
10494}
Chad Rosier1dcde962012-08-08 18:46:20 +000010495
Douglas Gregorfe314812011-06-21 17:03:29 +000010496template<typename Derived>
10497ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010498TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10499 Expr *Pattern = E->getPattern();
10500
10501 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10502 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10503 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10504
10505 // Determine whether the set of unexpanded parameter packs can and should
10506 // be expanded.
10507 bool Expand = true;
10508 bool RetainExpansion = false;
10509 Optional<unsigned> NumExpansions;
10510 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10511 Pattern->getSourceRange(),
10512 Unexpanded,
10513 Expand, RetainExpansion,
10514 NumExpansions))
10515 return true;
10516
10517 if (!Expand) {
10518 // Do not expand any packs here, just transform and rebuild a fold
10519 // expression.
10520 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10521
10522 ExprResult LHS =
10523 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10524 if (LHS.isInvalid())
10525 return true;
10526
10527 ExprResult RHS =
10528 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10529 if (RHS.isInvalid())
10530 return true;
10531
10532 if (!getDerived().AlwaysRebuild() &&
10533 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10534 return E;
10535
10536 return getDerived().RebuildCXXFoldExpr(
10537 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10538 RHS.get(), E->getLocEnd());
10539 }
10540
10541 // The transform has determined that we should perform an elementwise
10542 // expansion of the pattern. Do so.
10543 ExprResult Result = getDerived().TransformExpr(E->getInit());
10544 if (Result.isInvalid())
10545 return true;
10546 bool LeftFold = E->isLeftFold();
10547
10548 // If we're retaining an expansion for a right fold, it is the innermost
10549 // component and takes the init (if any).
10550 if (!LeftFold && RetainExpansion) {
10551 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10552
10553 ExprResult Out = getDerived().TransformExpr(Pattern);
10554 if (Out.isInvalid())
10555 return true;
10556
10557 Result = getDerived().RebuildCXXFoldExpr(
10558 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10559 Result.get(), E->getLocEnd());
10560 if (Result.isInvalid())
10561 return true;
10562 }
10563
10564 for (unsigned I = 0; I != *NumExpansions; ++I) {
10565 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10566 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10567 ExprResult Out = getDerived().TransformExpr(Pattern);
10568 if (Out.isInvalid())
10569 return true;
10570
10571 if (Out.get()->containsUnexpandedParameterPack()) {
10572 // We still have a pack; retain a pack expansion for this slice.
10573 Result = getDerived().RebuildCXXFoldExpr(
10574 E->getLocStart(),
10575 LeftFold ? Result.get() : Out.get(),
10576 E->getOperator(), E->getEllipsisLoc(),
10577 LeftFold ? Out.get() : Result.get(),
10578 E->getLocEnd());
10579 } else if (Result.isUsable()) {
10580 // We've got down to a single element; build a binary operator.
10581 Result = getDerived().RebuildBinaryOperator(
10582 E->getEllipsisLoc(), E->getOperator(),
10583 LeftFold ? Result.get() : Out.get(),
10584 LeftFold ? Out.get() : Result.get());
10585 } else
10586 Result = Out;
10587
10588 if (Result.isInvalid())
10589 return true;
10590 }
10591
10592 // If we're retaining an expansion for a left fold, it is the outermost
10593 // component and takes the complete expansion so far as its init (if any).
10594 if (LeftFold && RetainExpansion) {
10595 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10596
10597 ExprResult Out = getDerived().TransformExpr(Pattern);
10598 if (Out.isInvalid())
10599 return true;
10600
10601 Result = getDerived().RebuildCXXFoldExpr(
10602 E->getLocStart(), Result.get(),
10603 E->getOperator(), E->getEllipsisLoc(),
10604 Out.get(), E->getLocEnd());
10605 if (Result.isInvalid())
10606 return true;
10607 }
10608
10609 // If we had no init and an empty pack, and we're not retaining an expansion,
10610 // then produce a fallback value or error.
10611 if (Result.isUnset())
10612 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10613 E->getOperator());
10614
10615 return Result;
10616}
10617
10618template<typename Derived>
10619ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010620TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10621 CXXStdInitializerListExpr *E) {
10622 return getDerived().TransformExpr(E->getSubExpr());
10623}
10624
10625template<typename Derived>
10626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010627TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010628 return SemaRef.MaybeBindToTemporary(E);
10629}
10630
10631template<typename Derived>
10632ExprResult
10633TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010634 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010635}
10636
10637template<typename Derived>
10638ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010639TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10640 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10641 if (SubExpr.isInvalid())
10642 return ExprError();
10643
10644 if (!getDerived().AlwaysRebuild() &&
10645 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010646 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010647
10648 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010649}
10650
10651template<typename Derived>
10652ExprResult
10653TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10654 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010655 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010656 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010657 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010658 /*IsCall=*/false, Elements, &ArgChanged))
10659 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010660
Ted Kremeneke65b0862012-03-06 20:05:56 +000010661 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10662 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010663
Ted Kremeneke65b0862012-03-06 20:05:56 +000010664 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10665 Elements.data(),
10666 Elements.size());
10667}
10668
10669template<typename Derived>
10670ExprResult
10671TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010672 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010673 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010674 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010675 bool ArgChanged = false;
10676 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10677 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010678
Ted Kremeneke65b0862012-03-06 20:05:56 +000010679 if (OrigElement.isPackExpansion()) {
10680 // This key/value element is a pack expansion.
10681 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10682 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10683 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10684 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10685
10686 // Determine whether the set of unexpanded parameter packs can
10687 // and should be expanded.
10688 bool Expand = true;
10689 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010690 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10691 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010692 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10693 OrigElement.Value->getLocEnd());
10694 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10695 PatternRange,
10696 Unexpanded,
10697 Expand, RetainExpansion,
10698 NumExpansions))
10699 return ExprError();
10700
10701 if (!Expand) {
10702 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010703 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010704 // expansion.
10705 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10706 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10707 if (Key.isInvalid())
10708 return ExprError();
10709
10710 if (Key.get() != OrigElement.Key)
10711 ArgChanged = true;
10712
10713 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10714 if (Value.isInvalid())
10715 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010716
Ted Kremeneke65b0862012-03-06 20:05:56 +000010717 if (Value.get() != OrigElement.Value)
10718 ArgChanged = true;
10719
Chad Rosier1dcde962012-08-08 18:46:20 +000010720 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010721 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10722 };
10723 Elements.push_back(Expansion);
10724 continue;
10725 }
10726
10727 // Record right away that the argument was changed. This needs
10728 // to happen even if the array expands to nothing.
10729 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010730
Ted Kremeneke65b0862012-03-06 20:05:56 +000010731 // The transform has determined that we should perform an elementwise
10732 // expansion of the pattern. Do so.
10733 for (unsigned I = 0; I != *NumExpansions; ++I) {
10734 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10735 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10736 if (Key.isInvalid())
10737 return ExprError();
10738
10739 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10740 if (Value.isInvalid())
10741 return ExprError();
10742
Chad Rosier1dcde962012-08-08 18:46:20 +000010743 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010744 Key.get(), Value.get(), SourceLocation(), NumExpansions
10745 };
10746
10747 // If any unexpanded parameter packs remain, we still have a
10748 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010749 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010750 if (Key.get()->containsUnexpandedParameterPack() ||
10751 Value.get()->containsUnexpandedParameterPack())
10752 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010753
Ted Kremeneke65b0862012-03-06 20:05:56 +000010754 Elements.push_back(Element);
10755 }
10756
Richard Smith9467be42014-06-06 17:33:35 +000010757 // FIXME: Retain a pack expansion if RetainExpansion is true.
10758
Ted Kremeneke65b0862012-03-06 20:05:56 +000010759 // We've finished with this pack expansion.
10760 continue;
10761 }
10762
10763 // Transform and check key.
10764 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10765 if (Key.isInvalid())
10766 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010767
Ted Kremeneke65b0862012-03-06 20:05:56 +000010768 if (Key.get() != OrigElement.Key)
10769 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010770
Ted Kremeneke65b0862012-03-06 20:05:56 +000010771 // Transform and check value.
10772 ExprResult Value
10773 = getDerived().TransformExpr(OrigElement.Value);
10774 if (Value.isInvalid())
10775 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010776
Ted Kremeneke65b0862012-03-06 20:05:56 +000010777 if (Value.get() != OrigElement.Value)
10778 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010779
10780 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010781 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010782 };
10783 Elements.push_back(Element);
10784 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010785
Ted Kremeneke65b0862012-03-06 20:05:56 +000010786 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10787 return SemaRef.MaybeBindToTemporary(E);
10788
10789 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010790 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010791}
10792
Mike Stump11289f42009-09-09 15:08:12 +000010793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010795TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010796 TypeSourceInfo *EncodedTypeInfo
10797 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10798 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010800
Douglas Gregora16548e2009-08-11 05:31:07 +000010801 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010802 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010803 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010804
10805 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010806 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010807 E->getRParenLoc());
10808}
Mike Stump11289f42009-09-09 15:08:12 +000010809
Douglas Gregora16548e2009-08-11 05:31:07 +000010810template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010811ExprResult TreeTransform<Derived>::
10812TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010813 // This is a kind of implicit conversion, and it needs to get dropped
10814 // and recomputed for the same general reasons that ImplicitCastExprs
10815 // do, as well a more specific one: this expression is only valid when
10816 // it appears *immediately* as an argument expression.
10817 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010818}
10819
10820template<typename Derived>
10821ExprResult TreeTransform<Derived>::
10822TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010823 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010824 = getDerived().TransformType(E->getTypeInfoAsWritten());
10825 if (!TSInfo)
10826 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010827
John McCall31168b02011-06-15 23:02:42 +000010828 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010829 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010830 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010831
John McCall31168b02011-06-15 23:02:42 +000010832 if (!getDerived().AlwaysRebuild() &&
10833 TSInfo == E->getTypeInfoAsWritten() &&
10834 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010835 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010836
John McCall31168b02011-06-15 23:02:42 +000010837 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010838 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010839 Result.get());
10840}
10841
10842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010844TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010845 // Transform arguments.
10846 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010847 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010848 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010849 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010850 &ArgChanged))
10851 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010852
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010853 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10854 // Class message: transform the receiver type.
10855 TypeSourceInfo *ReceiverTypeInfo
10856 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10857 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010858 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010859
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010860 // If nothing changed, just retain the existing message send.
10861 if (!getDerived().AlwaysRebuild() &&
10862 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010863 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010864
10865 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010866 SmallVector<SourceLocation, 16> SelLocs;
10867 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010868 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10869 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010870 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010871 E->getMethodDecl(),
10872 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010873 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010874 E->getRightLoc());
10875 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010876 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10877 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10878 // Build a new class message send to 'super'.
10879 SmallVector<SourceLocation, 16> SelLocs;
10880 E->getSelectorLocs(SelLocs);
10881 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10882 E->getSelector(),
10883 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010884 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010885 E->getMethodDecl(),
10886 E->getLeftLoc(),
10887 Args,
10888 E->getRightLoc());
10889 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010890
10891 // Instance message: transform the receiver
10892 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10893 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010894 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010895 = getDerived().TransformExpr(E->getInstanceReceiver());
10896 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010897 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010898
10899 // If nothing changed, just retain the existing message send.
10900 if (!getDerived().AlwaysRebuild() &&
10901 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010902 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010903
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010904 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010905 SmallVector<SourceLocation, 16> SelLocs;
10906 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010907 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010908 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010909 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010910 E->getMethodDecl(),
10911 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010912 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010913 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010914}
10915
Mike Stump11289f42009-09-09 15:08:12 +000010916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010917ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010918TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010919 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010920}
10921
Mike Stump11289f42009-09-09 15:08:12 +000010922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010923ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010924TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010925 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010926}
10927
Mike Stump11289f42009-09-09 15:08:12 +000010928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010929ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010930TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010931 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010932 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010933 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010934 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010935
10936 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010937
Douglas Gregord51d90d2010-04-26 20:11:03 +000010938 // If nothing changed, just retain the existing expression.
10939 if (!getDerived().AlwaysRebuild() &&
10940 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010941 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010942
John McCallb268a282010-08-23 23:25:46 +000010943 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010944 E->getLocation(),
10945 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010946}
10947
Mike Stump11289f42009-09-09 15:08:12 +000010948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010950TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010951 // 'super' and types never change. Property never changes. Just
10952 // retain the existing expression.
10953 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010954 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010955
Douglas Gregor9faee212010-04-26 20:47:02 +000010956 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010957 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010958 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010959 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010960
Douglas Gregor9faee212010-04-26 20:47:02 +000010961 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010962
Douglas Gregor9faee212010-04-26 20:47:02 +000010963 // If nothing changed, just retain the existing expression.
10964 if (!getDerived().AlwaysRebuild() &&
10965 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010966 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010967
John McCallb7bd14f2010-12-02 01:19:52 +000010968 if (E->isExplicitProperty())
10969 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10970 E->getExplicitProperty(),
10971 E->getLocation());
10972
10973 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010974 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010975 E->getImplicitPropertyGetter(),
10976 E->getImplicitPropertySetter(),
10977 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010978}
10979
Mike Stump11289f42009-09-09 15:08:12 +000010980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010981ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010982TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10983 // Transform the base expression.
10984 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10985 if (Base.isInvalid())
10986 return ExprError();
10987
10988 // Transform the key expression.
10989 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10990 if (Key.isInvalid())
10991 return ExprError();
10992
10993 // If nothing changed, just retain the existing expression.
10994 if (!getDerived().AlwaysRebuild() &&
10995 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010996 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010997
Chad Rosier1dcde962012-08-08 18:46:20 +000010998 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010999 Base.get(), Key.get(),
11000 E->getAtIndexMethodDecl(),
11001 E->setAtIndexMethodDecl());
11002}
11003
11004template<typename Derived>
11005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011006TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011007 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011008 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011009 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011010 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011011
Douglas Gregord51d90d2010-04-26 20:11:03 +000011012 // If nothing changed, just retain the existing expression.
11013 if (!getDerived().AlwaysRebuild() &&
11014 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011015 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011016
John McCallb268a282010-08-23 23:25:46 +000011017 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011018 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011019 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011020}
11021
Mike Stump11289f42009-09-09 15:08:12 +000011022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011024TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011025 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011026 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011027 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011028 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011029 SubExprs, &ArgumentChanged))
11030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011031
Douglas Gregora16548e2009-08-11 05:31:07 +000011032 if (!getDerived().AlwaysRebuild() &&
11033 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011034 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011035
Douglas Gregora16548e2009-08-11 05:31:07 +000011036 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011037 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011038 E->getRParenLoc());
11039}
11040
Mike Stump11289f42009-09-09 15:08:12 +000011041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011042ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011043TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11044 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11045 if (SrcExpr.isInvalid())
11046 return ExprError();
11047
11048 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11049 if (!Type)
11050 return ExprError();
11051
11052 if (!getDerived().AlwaysRebuild() &&
11053 Type == E->getTypeSourceInfo() &&
11054 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011055 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011056
11057 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11058 SrcExpr.get(), Type,
11059 E->getRParenLoc());
11060}
11061
11062template<typename Derived>
11063ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011064TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011065 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011066
Craig Topperc3ec1492014-05-26 06:22:03 +000011067 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011068 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11069
11070 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011071 blockScope->TheDecl->setBlockMissingReturnType(
11072 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011073
Chris Lattner01cf8db2011-07-20 06:58:45 +000011074 SmallVector<ParmVarDecl*, 4> params;
11075 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011076
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011077 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000011078 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11079 oldBlock->param_begin(),
11080 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011081 nullptr, paramTypes, &params)) {
11082 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011083 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011084 }
John McCall490112f2011-02-04 18:33:18 +000011085
Jordan Rosea0a86be2013-03-08 22:25:36 +000011086 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000011087 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011088 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011089
Jordan Rose5c382722013-03-08 21:51:21 +000011090 QualType functionType =
11091 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011092 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000011093 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011094
11095 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011096 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011097 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011098
11099 if (!oldBlock->blockMissingReturnType()) {
11100 blockScope->HasImplicitReturnType = false;
11101 blockScope->ReturnType = exprResultType;
11102 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011103
John McCall3882ace2011-01-05 12:14:39 +000011104 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011105 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011106 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011107 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011108 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011109 }
John McCall3882ace2011-01-05 12:14:39 +000011110
John McCall490112f2011-02-04 18:33:18 +000011111#ifndef NDEBUG
11112 // In builds with assertions, make sure that we captured everything we
11113 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011114 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011115 for (const auto &I : oldBlock->captures()) {
11116 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011117
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011118 // Ignore parameter packs.
11119 if (isa<ParmVarDecl>(oldCapture) &&
11120 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11121 continue;
John McCall490112f2011-02-04 18:33:18 +000011122
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011123 VarDecl *newCapture =
11124 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11125 oldCapture));
11126 assert(blockScope->CaptureMap.count(newCapture));
11127 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011128 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011129 }
11130#endif
11131
11132 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011133 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011134}
11135
Mike Stump11289f42009-09-09 15:08:12 +000011136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011137ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011138TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011139 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011140}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011141
11142template<typename Derived>
11143ExprResult
11144TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011145 QualType RetTy = getDerived().TransformType(E->getType());
11146 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011147 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011148 SubExprs.reserve(E->getNumSubExprs());
11149 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11150 SubExprs, &ArgumentChanged))
11151 return ExprError();
11152
11153 if (!getDerived().AlwaysRebuild() &&
11154 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011155 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011156
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011157 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011158 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011159}
Chad Rosier1dcde962012-08-08 18:46:20 +000011160
Douglas Gregora16548e2009-08-11 05:31:07 +000011161//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011162// Type reconstruction
11163//===----------------------------------------------------------------------===//
11164
Mike Stump11289f42009-09-09 15:08:12 +000011165template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011166QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11167 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011168 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011169 getDerived().getBaseEntity());
11170}
11171
Mike Stump11289f42009-09-09 15:08:12 +000011172template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011173QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11174 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011175 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011176 getDerived().getBaseEntity());
11177}
11178
Mike Stump11289f42009-09-09 15:08:12 +000011179template<typename Derived>
11180QualType
John McCall70dd5f62009-10-30 00:06:24 +000011181TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11182 bool WrittenAsLValue,
11183 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011184 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011185 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011186}
11187
11188template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011189QualType
John McCall70dd5f62009-10-30 00:06:24 +000011190TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11191 QualType ClassType,
11192 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011193 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11194 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011195}
11196
11197template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011198QualType TreeTransform<Derived>::RebuildObjCObjectType(
11199 QualType BaseType,
11200 SourceLocation Loc,
11201 SourceLocation TypeArgsLAngleLoc,
11202 ArrayRef<TypeSourceInfo *> TypeArgs,
11203 SourceLocation TypeArgsRAngleLoc,
11204 SourceLocation ProtocolLAngleLoc,
11205 ArrayRef<ObjCProtocolDecl *> Protocols,
11206 ArrayRef<SourceLocation> ProtocolLocs,
11207 SourceLocation ProtocolRAngleLoc) {
11208 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11209 TypeArgs, TypeArgsRAngleLoc,
11210 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11211 ProtocolRAngleLoc,
11212 /*FailOnError=*/true);
11213}
11214
11215template<typename Derived>
11216QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11217 QualType PointeeType,
11218 SourceLocation Star) {
11219 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11220}
11221
11222template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011223QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011224TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11225 ArrayType::ArraySizeModifier SizeMod,
11226 const llvm::APInt *Size,
11227 Expr *SizeExpr,
11228 unsigned IndexTypeQuals,
11229 SourceRange BracketsRange) {
11230 if (SizeExpr || !Size)
11231 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11232 IndexTypeQuals, BracketsRange,
11233 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011234
11235 QualType Types[] = {
11236 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11237 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11238 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011239 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011240 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011241 QualType SizeType;
11242 for (unsigned I = 0; I != NumTypes; ++I)
11243 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11244 SizeType = Types[I];
11245 break;
11246 }
Mike Stump11289f42009-09-09 15:08:12 +000011247
Eli Friedman9562f392012-01-25 23:20:27 +000011248 // Note that we can return a VariableArrayType here in the case where
11249 // the element type was a dependent VariableArrayType.
11250 IntegerLiteral *ArraySize
11251 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11252 /*FIXME*/BracketsRange.getBegin());
11253 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011254 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011255 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011256}
Mike Stump11289f42009-09-09 15:08:12 +000011257
Douglas Gregord6ff3322009-08-04 16:50:30 +000011258template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011259QualType
11260TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011261 ArrayType::ArraySizeModifier SizeMod,
11262 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011263 unsigned IndexTypeQuals,
11264 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011265 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011266 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011267}
11268
11269template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011270QualType
Mike Stump11289f42009-09-09 15:08:12 +000011271TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011272 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011273 unsigned IndexTypeQuals,
11274 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011275 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011276 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011277}
Mike Stump11289f42009-09-09 15:08:12 +000011278
Douglas Gregord6ff3322009-08-04 16:50:30 +000011279template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011280QualType
11281TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011282 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011283 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011284 unsigned IndexTypeQuals,
11285 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011286 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011287 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011288 IndexTypeQuals, BracketsRange);
11289}
11290
11291template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011292QualType
11293TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011294 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011295 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011296 unsigned IndexTypeQuals,
11297 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011298 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011299 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011300 IndexTypeQuals, BracketsRange);
11301}
11302
11303template<typename Derived>
11304QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011305 unsigned NumElements,
11306 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011307 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011308 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011309}
Mike Stump11289f42009-09-09 15:08:12 +000011310
Douglas Gregord6ff3322009-08-04 16:50:30 +000011311template<typename Derived>
11312QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11313 unsigned NumElements,
11314 SourceLocation AttributeLoc) {
11315 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11316 NumElements, true);
11317 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011318 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11319 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011320 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011321}
Mike Stump11289f42009-09-09 15:08:12 +000011322
Douglas Gregord6ff3322009-08-04 16:50:30 +000011323template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011324QualType
11325TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011326 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011327 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011328 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011329}
Mike Stump11289f42009-09-09 15:08:12 +000011330
Douglas Gregord6ff3322009-08-04 16:50:30 +000011331template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011332QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11333 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011334 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011335 const FunctionProtoType::ExtProtoInfo &EPI) {
11336 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011337 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011338 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011339 EPI);
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>
John McCall550e0c22009-10-21 00:40:46 +000011343QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11344 return SemaRef.Context.getFunctionNoProtoType(T);
11345}
11346
11347template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011348QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11349 assert(D && "no decl found");
11350 if (D->isInvalidDecl()) return QualType();
11351
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011352 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011353 TypeDecl *Ty;
11354 if (isa<UsingDecl>(D)) {
11355 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011356 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011357 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11358
11359 // A valid resolved using typename decl points to exactly one type decl.
11360 assert(++Using->shadow_begin() == Using->shadow_end());
11361 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011362
John McCallb96ec562009-12-04 22:46:56 +000011363 } else {
11364 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11365 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11366 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11367 }
11368
11369 return SemaRef.Context.getTypeDeclType(Ty);
11370}
11371
11372template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011373QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11374 SourceLocation Loc) {
11375 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011376}
11377
11378template<typename Derived>
11379QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11380 return SemaRef.Context.getTypeOfType(Underlying);
11381}
11382
11383template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011384QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11385 SourceLocation Loc) {
11386 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011387}
11388
11389template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011390QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11391 UnaryTransformType::UTTKind UKind,
11392 SourceLocation Loc) {
11393 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11394}
11395
11396template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011397QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011398 TemplateName Template,
11399 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011400 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011401 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011402}
Mike Stump11289f42009-09-09 15:08:12 +000011403
Douglas Gregor1135c352009-08-06 05:28:30 +000011404template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011405QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11406 SourceLocation KWLoc) {
11407 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11408}
11409
11410template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011411QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11412 SourceLocation KWLoc) {
11413 return SemaRef.BuildPipeType(ValueType, KWLoc);
11414}
11415
11416template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011417TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011418TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011419 bool TemplateKW,
11420 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011421 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011422 Template);
11423}
11424
11425template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011426TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011427TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11428 const IdentifierInfo &Name,
11429 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011430 QualType ObjectType,
11431 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011432 UnqualifiedId TemplateName;
11433 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011434 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011435 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011436 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011437 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011438 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011439 /*EnteringContext=*/false,
11440 Template);
John McCall31f82722010-11-12 08:19:04 +000011441 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011442}
Mike Stump11289f42009-09-09 15:08:12 +000011443
Douglas Gregora16548e2009-08-11 05:31:07 +000011444template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011445TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011446TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011447 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011448 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011449 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011450 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011451 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011452 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011453 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011454 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011455 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011456 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011457 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011458 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011459 /*EnteringContext=*/false,
11460 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011461 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011462}
Chad Rosier1dcde962012-08-08 18:46:20 +000011463
Douglas Gregor71395fa2009-11-04 00:56:37 +000011464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011465ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011466TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11467 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011468 Expr *OrigCallee,
11469 Expr *First,
11470 Expr *Second) {
11471 Expr *Callee = OrigCallee->IgnoreParenCasts();
11472 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011473
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011474 if (First->getObjectKind() == OK_ObjCProperty) {
11475 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11476 if (BinaryOperator::isAssignmentOp(Opc))
11477 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11478 First, Second);
11479 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11480 if (Result.isInvalid())
11481 return ExprError();
11482 First = Result.get();
11483 }
11484
11485 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11486 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11487 if (Result.isInvalid())
11488 return ExprError();
11489 Second = Result.get();
11490 }
11491
Douglas Gregora16548e2009-08-11 05:31:07 +000011492 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011493 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011494 if (!First->getType()->isOverloadableType() &&
11495 !Second->getType()->isOverloadableType())
11496 return getSema().CreateBuiltinArraySubscriptExpr(First,
11497 Callee->getLocStart(),
11498 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011499 } else if (Op == OO_Arrow) {
11500 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011501 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11502 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011503 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011504 // The argument is not of overloadable type, so try to create a
11505 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011506 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011507 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011508
John McCallb268a282010-08-23 23:25:46 +000011509 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011510 }
11511 } else {
John McCallb268a282010-08-23 23:25:46 +000011512 if (!First->getType()->isOverloadableType() &&
11513 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011514 // Neither of the arguments is an overloadable type, so try to
11515 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011516 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011517 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011518 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011519 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011521
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011522 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011523 }
11524 }
Mike Stump11289f42009-09-09 15:08:12 +000011525
11526 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011527 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011528 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011529
John McCallb268a282010-08-23 23:25:46 +000011530 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011531 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011532 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011533 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011534 // If we've resolved this to a particular non-member function, just call
11535 // that function. If we resolved it to a member function,
11536 // CreateOverloaded* will find that function for us.
11537 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11538 if (!isa<CXXMethodDecl>(ND))
11539 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011540 }
Mike Stump11289f42009-09-09 15:08:12 +000011541
Douglas Gregora16548e2009-08-11 05:31:07 +000011542 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011543 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011544 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011545
Douglas Gregora16548e2009-08-11 05:31:07 +000011546 // Create the overloaded operator invocation for unary operators.
11547 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011548 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011549 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011550 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011551 }
Mike Stump11289f42009-09-09 15:08:12 +000011552
Douglas Gregore9d62932011-07-15 16:25:15 +000011553 if (Op == OO_Subscript) {
11554 SourceLocation LBrace;
11555 SourceLocation RBrace;
11556
11557 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011558 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011559 LBrace = SourceLocation::getFromRawEncoding(
11560 NameLoc.CXXOperatorName.BeginOpNameLoc);
11561 RBrace = SourceLocation::getFromRawEncoding(
11562 NameLoc.CXXOperatorName.EndOpNameLoc);
11563 } else {
11564 LBrace = Callee->getLocStart();
11565 RBrace = OpLoc;
11566 }
11567
11568 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11569 First, Second);
11570 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011571
Douglas Gregora16548e2009-08-11 05:31:07 +000011572 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011573 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011574 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011575 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11576 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011578
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011579 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011580}
Mike Stump11289f42009-09-09 15:08:12 +000011581
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011582template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011583ExprResult
John McCallb268a282010-08-23 23:25:46 +000011584TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011585 SourceLocation OperatorLoc,
11586 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011587 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011588 TypeSourceInfo *ScopeType,
11589 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011590 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011591 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011592 QualType BaseType = Base->getType();
11593 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011594 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011595 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011596 !BaseType->getAs<PointerType>()->getPointeeType()
11597 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011598 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011599 return SemaRef.BuildPseudoDestructorExpr(
11600 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11601 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011602 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011603
Douglas Gregor678f90d2010-02-25 01:56:36 +000011604 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011605 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11606 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11607 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11608 NameInfo.setNamedTypeInfo(DestroyedType);
11609
Richard Smith8e4a3862012-05-15 06:15:11 +000011610 // The scope type is now known to be a valid nested name specifier
11611 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011612 if (ScopeType) {
11613 if (!ScopeType->getType()->getAs<TagType>()) {
11614 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11615 diag::err_expected_class_or_namespace)
11616 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11617 return ExprError();
11618 }
11619 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11620 CCLoc);
11621 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011622
Abramo Bagnara7945c982012-01-27 09:46:47 +000011623 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011624 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011625 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011626 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011627 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011628 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011629 /*TemplateArgs*/ nullptr,
11630 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011631}
11632
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011633template<typename Derived>
11634StmtResult
11635TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011636 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011637 CapturedDecl *CD = S->getCapturedDecl();
11638 unsigned NumParams = CD->getNumParams();
11639 unsigned ContextParamPos = CD->getContextParamPosition();
11640 SmallVector<Sema::CapturedParamNameType, 4> Params;
11641 for (unsigned I = 0; I < NumParams; ++I) {
11642 if (I != ContextParamPos) {
11643 Params.push_back(
11644 std::make_pair(
11645 CD->getParam(I)->getName(),
11646 getDerived().TransformType(CD->getParam(I)->getType())));
11647 } else {
11648 Params.push_back(std::make_pair(StringRef(), QualType()));
11649 }
11650 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011651 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011652 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011653 StmtResult Body;
11654 {
11655 Sema::CompoundScopeRAII CompoundScope(getSema());
11656 Body = getDerived().TransformStmt(S->getCapturedStmt());
11657 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011658
11659 if (Body.isInvalid()) {
11660 getSema().ActOnCapturedRegionError();
11661 return StmtError();
11662 }
11663
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011664 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011665}
11666
Douglas Gregord6ff3322009-08-04 16:50:30 +000011667} // end namespace clang
11668
Hans Wennborg59dbe862015-09-29 20:56:43 +000011669#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H