blob: f5249fdeb017fd117dfb35705ba0797ad0a692b4 [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"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000330 /// \brief Transform the given attribute.
331 ///
332 /// By default, this routine transforms a statement by delegating to the
333 /// appropriate TransformXXXAttr function to transform a specific kind
334 /// of attribute. Subclasses may override this function to transform
335 /// attributed statements using some other mechanism.
336 ///
337 /// \returns the transformed attribute
338 const Attr *TransformAttr(const Attr *S);
339
340/// \brief Transform the specified attribute.
341///
342/// Subclasses should override the transformation of attributes with a pragma
343/// spelling to transform expressions stored within the attribute.
344///
345/// \returns the transformed attribute.
346#define ATTR(X)
347#define PRAGMA_SPELLING_ATTR(X) \
348 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
349#include "clang/Basic/AttrList.inc"
350
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000351 /// \brief Transform the given expression.
352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000353 /// By default, this routine transforms an expression by delegating to the
354 /// appropriate TransformXXXExpr function to build a new expression.
355 /// Subclasses may override this function to transform expressions using some
356 /// other mechanism.
357 ///
358 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000359 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Richard Smithd59b8322012-12-19 01:39:02 +0000361 /// \brief Transform the given initializer.
362 ///
363 /// By default, this routine transforms an initializer by stripping off the
364 /// semantic nodes added by initialization, then passing the result to
365 /// TransformExpr or TransformExprs.
366 ///
367 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000368 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000369
Douglas Gregora3efea12011-01-03 19:04:46 +0000370 /// \brief Transform the given list of expressions.
371 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000372 /// This routine transforms a list of expressions by invoking
373 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 /// support for variadic templates by expanding any pack expansions (if the
375 /// derived class permits such expansion) along the way. When pack expansions
376 /// are present, the number of outputs may not equal the number of inputs.
377 ///
378 /// \param Inputs The set of expressions to be transformed.
379 ///
380 /// \param NumInputs The number of expressions in \c Inputs.
381 ///
382 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 /// be.
385 ///
386 /// \param Outputs The transformed input expressions will be added to this
387 /// vector.
388 ///
389 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
390 /// due to transformation.
391 ///
392 /// \returns true if an error occurred, false otherwise.
393 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000394 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000395 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given declaration, which is referenced from a type
398 /// or expression.
399 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000400 /// By default, acts as the identity function on declarations, unless the
401 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000402 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000403 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000404 llvm::DenseMap<Decl *, Decl *>::iterator Known
405 = TransformedLocalDecls.find(D);
406 if (Known != TransformedLocalDecls.end())
407 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
409 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000410 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000411
Chad Rosier1dcde962012-08-08 18:46:20 +0000412 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// place them on the new declaration.
414 ///
415 /// By default, this operation does nothing. Subclasses may override this
416 /// behavior to transform attributes.
417 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000418
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// \brief Note that a local declaration has been transformed by this
420 /// transformer.
421 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
424 /// the transformer itself has to transform the declarations. This routine
425 /// can be overridden by a subclass that keeps track of such mappings.
426 void transformedLocalDecl(Decl *Old, Decl *New) {
427 TransformedLocalDecls[Old] = New;
428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregorebe10102009-08-20 07:17:43 +0000430 /// \brief Transform the definition of the given declaration.
431 ///
Mike Stump11289f42009-09-09 15:08:12 +0000432 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000433 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000434 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
435 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000438 /// \brief Transform the given declaration, which was the first part of a
439 /// nested-name-specifier in a member access expression.
440 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000441 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000442 /// identifier in a nested-name-specifier of a member access expression, e.g.,
443 /// the \c T in \c x->T::member
444 ///
445 /// By default, invokes TransformDecl() to transform the declaration.
446 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000447 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
448 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregor14454802011-02-25 02:25:35 +0000451 /// \brief Transform the given nested-name-specifier with source-location
452 /// information.
453 ///
454 /// By default, transforms all of the types and declarations within the
455 /// nested-name-specifier. Subclasses may override this function to provide
456 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000457 NestedNameSpecifierLoc
458 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000461
Douglas Gregorf816bd72009-09-03 22:13:48 +0000462 /// \brief Transform the given declaration name.
463 ///
464 /// By default, transforms the types of conversion function, constructor,
465 /// and destructor names and then (if needed) rebuilds the declaration name.
466 /// Identifiers and selectors are returned unmodified. Sublcasses may
467 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000468 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000469 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000470
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000472 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 /// \param SS The nested-name-specifier that qualifies the template
474 /// name. This nested-name-specifier must already have been transformed.
475 ///
476 /// \param Name The template name to transform.
477 ///
478 /// \param NameLoc The source location of the template name.
479 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000480 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000481 /// access expression, this is the type of the object whose member template
482 /// is being referenced.
483 ///
484 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
485 /// also refers to a name within the current (lexical) scope, this is the
486 /// declaration it refers to.
487 ///
488 /// By default, transforms the template name by transforming the declarations
489 /// and nested-name-specifiers that occur within the template name.
490 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000491 TemplateName
492 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
493 SourceLocation NameLoc,
494 QualType ObjectType = QualType(),
495 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000496
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// \brief Transform the given template argument.
498 ///
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// By default, this operation transforms the type, expression, or
500 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000501 /// new template argument from the transformed result. Subclasses may
502 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000503 ///
504 /// Returns true if there was an error.
505 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
506 TemplateArgumentLoc &Output);
507
Douglas Gregor62e06f22010-12-20 17:31:10 +0000508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
512 /// the transformed arguments to the output list.
513 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000514 /// Note that this overload of \c TransformTemplateArguments() is merely
515 /// a convenience function. Subclasses that wish to override this behavior
516 /// should override the iterator-based member template version.
517 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \param Inputs The set of template arguments to be transformed.
519 ///
520 /// \param NumInputs The number of template arguments in \p Inputs.
521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
526 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
527 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 TemplateArgumentListInfo &Outputs) {
529 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
530 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000531
532 /// \brief Transform the given set of template arguments.
533 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000534 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000537 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000538 /// \param First An iterator to the first template argument.
539 ///
540 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
542 /// \param Outputs The set of transformed template arguments output by this
543 /// routine.
544 ///
545 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 template<typename InputIterator>
547 bool TransformTemplateArguments(InputIterator First,
548 InputIterator Last,
549 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000550
John McCall0ad16662009-10-29 08:12:44 +0000551 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
552 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
553 TemplateArgumentLoc &ArgLoc);
554
John McCallbcd03502009-12-07 02:54:59 +0000555 /// \brief Fakes up a TypeSourceInfo for a type.
556 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
557 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000558 getDerived().getBaseLocation());
559 }
Mike Stump11289f42009-09-09 15:08:12 +0000560
John McCall550e0c22009-10-21 00:40:46 +0000561#define ABSTRACT_TYPELOC(CLASS, PARENT)
562#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000563 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000564#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
Richard Smith2e321552014-11-12 02:00:47 +0000566 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000567 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
568 FunctionProtoTypeLoc TL,
569 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000570 unsigned ThisTypeQuals,
571 Fn TransformExceptionSpec);
572
573 bool TransformExceptionSpec(SourceLocation Loc,
574 FunctionProtoType::ExceptionSpecInfo &ESI,
575 SmallVectorImpl<QualType> &Exceptions,
576 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000577
David Majnemerfad8f482013-10-15 09:33:02 +0000578 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000579
Chad Rosier1dcde962012-08-08 18:46:20 +0000580 QualType
John McCall31f82722010-11-12 08:19:04 +0000581 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
582 TemplateSpecializationTypeLoc TL,
583 TemplateName Template);
584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
587 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000588 TemplateName Template,
589 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000590
Nico Weberc153d242014-07-28 00:02:09 +0000591 QualType TransformDependentTemplateSpecializationType(
592 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
593 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000594
John McCall58f10c32010-03-11 09:03:00 +0000595 /// \brief Transforms the parameters of a function type into the
596 /// given vectors.
597 ///
598 /// The result vectors should be kept in sync; null entries in the
599 /// variables vector are acceptable.
600 ///
601 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000602 bool TransformFunctionTypeParams(SourceLocation Loc,
603 ParmVarDecl **Params, unsigned NumParams,
604 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000605 SmallVectorImpl<QualType> &PTypes,
606 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000607
608 /// \brief Transforms a single function-type parameter. Return null
609 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000610 ///
611 /// \param indexAdjustment - A number to add to the parameter's
612 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000613 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000614 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000615 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000616 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000617
John McCall31f82722010-11-12 08:19:04 +0000618 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000619
John McCalldadc5752010-08-24 06:29:42 +0000620 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
621 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000622
Faisal Vali2cba1332013-10-23 06:44:28 +0000623 TemplateParameterList *TransformTemplateParameterList(
624 TemplateParameterList *TPL) {
625 return TPL;
626 }
627
Richard Smithdb2630f2012-10-21 03:28:35 +0000628 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000629
Richard Smithdb2630f2012-10-21 03:28:35 +0000630 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000631 bool IsAddressOfOperand,
632 TypeSourceInfo **RecoveryTSI);
633
634 ExprResult TransformParenDependentScopeDeclRefExpr(
635 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
636 TypeSourceInfo **RecoveryTSI);
637
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000638 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000639
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000640// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
641// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000642#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000643 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000644 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000645#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000646 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000647 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000648#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000649#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000650
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000651#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000652 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000653 OMPClause *Transform ## Class(Class *S);
654#include "clang/Basic/OpenMPKinds.def"
655
Douglas Gregord6ff3322009-08-04 16:50:30 +0000656 /// \brief Build a new pointer type given its pointee type.
657 ///
658 /// By default, performs semantic analysis when building the pointer type.
659 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000660 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661
662 /// \brief Build a new block pointer type given its pointee type.
663 ///
Mike Stump11289f42009-09-09 15:08:12 +0000664 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000666 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667
John McCall70dd5f62009-10-30 00:06:24 +0000668 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000669 ///
John McCall70dd5f62009-10-30 00:06:24 +0000670 /// By default, performs semantic analysis when building the
671 /// reference type. Subclasses may override this routine to provide
672 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 ///
John McCall70dd5f62009-10-30 00:06:24 +0000674 /// \param LValue whether the type was written with an lvalue sigil
675 /// or an rvalue sigil.
676 QualType RebuildReferenceType(QualType ReferentType,
677 bool LValue,
678 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new member pointer type given the pointee type and the
681 /// class type it refers into.
682 ///
683 /// By default, performs semantic analysis when building the member pointer
684 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000685 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
686 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000687
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688 /// \brief Build a new array type given the element type, size
689 /// modifier, size of the array (if known), size expression, and index type
690 /// qualifiers.
691 ///
692 /// By default, performs semantic analysis when building the array type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 QualType RebuildArrayType(QualType ElementType,
696 ArrayType::ArraySizeModifier SizeMod,
697 const llvm::APInt *Size,
698 Expr *SizeExpr,
699 unsigned IndexTypeQuals,
700 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// \brief Build a new constant array type given the element type, size
703 /// modifier, (known) size of the array, and index type qualifiers.
704 ///
705 /// By default, performs semantic analysis when building the array type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000707 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 ArrayType::ArraySizeModifier SizeMod,
709 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000710 unsigned IndexTypeQuals,
711 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// \brief Build a new incomplete array type given the element type, size
714 /// modifier, and index type qualifiers.
715 ///
716 /// By default, performs semantic analysis when building the array type.
717 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000718 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722
Mike Stump11289f42009-09-09 15:08:12 +0000723 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// size modifier, size expression, and index type qualifiers.
725 ///
726 /// By default, performs semantic analysis when building the array type.
727 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000728 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000730 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 unsigned IndexTypeQuals,
732 SourceRange BracketsRange);
733
Mike Stump11289f42009-09-09 15:08:12 +0000734 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000735 /// size modifier, size expression, and index type qualifiers.
736 ///
737 /// By default, performs semantic analysis when building the array type.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000741 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 unsigned IndexTypeQuals,
743 SourceRange BracketsRange);
744
745 /// \brief Build a new vector type given the element type and
746 /// number of elements.
747 ///
748 /// By default, performs semantic analysis when building the vector type.
749 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000750 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000751 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753 /// \brief Build a new extended vector type given the element type and
754 /// number of elements.
755 ///
756 /// By default, performs semantic analysis when building the vector type.
757 /// Subclasses may override this routine to provide different behavior.
758 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
759 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000760
761 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 /// given the element type and number of elements.
763 ///
764 /// By default, performs semantic analysis when building the vector type.
765 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000766 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// \brief Build a new function type.
771 ///
772 /// By default, performs semantic analysis when building the function type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000775 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000776 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000777
John McCall550e0c22009-10-21 00:40:46 +0000778 /// \brief Build a new unprototyped function type.
779 QualType RebuildFunctionNoProtoType(QualType ResultType);
780
John McCallb96ec562009-12-04 22:46:56 +0000781 /// \brief Rebuild an unresolved typename type, given the decl that
782 /// the UnresolvedUsingTypenameDecl was transformed to.
783 QualType RebuildUnresolvedUsingType(Decl *D);
784
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000786 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 return SemaRef.Context.getTypeDeclType(Typedef);
788 }
789
790 /// \brief Build a new class/struct/union type.
791 QualType RebuildRecordType(RecordDecl *Record) {
792 return SemaRef.Context.getTypeDeclType(Record);
793 }
794
795 /// \brief Build a new Enum type.
796 QualType RebuildEnumType(EnumDecl *Enum) {
797 return SemaRef.Context.getTypeDeclType(Enum);
798 }
John McCallfcc33b02009-09-05 00:15:47 +0000799
Mike Stump11289f42009-09-09 15:08:12 +0000800 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000801 ///
802 /// By default, performs semantic analysis when building the typeof type.
803 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000804 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805
Mike Stump11289f42009-09-09 15:08:12 +0000806 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 ///
808 /// By default, builds a new TypeOfType with the given underlying type.
809 QualType RebuildTypeOfType(QualType Underlying);
810
Alexis Hunte852b102011-05-24 22:41:36 +0000811 /// \brief Build a new unary transform type.
812 QualType RebuildUnaryTransformType(QualType BaseType,
813 UnaryTransformType::UTTKind UKind,
814 SourceLocation Loc);
815
Richard Smith74aeef52013-04-26 16:15:35 +0000816 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000817 ///
818 /// By default, performs semantic analysis when building the decltype type.
819 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000820 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000821
Richard Smith74aeef52013-04-26 16:15:35 +0000822 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000823 ///
824 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000825 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000826 // Note, IsDependent is always false here: we implicitly convert an 'auto'
827 // which has been deduced to a dependent type into an undeduced 'auto', so
828 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000829 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
830 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000831 }
832
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 /// \brief Build a new template specialization type.
834 ///
835 /// By default, performs semantic analysis when building the template
836 /// specialization type. Subclasses may override this routine to provide
837 /// different behavior.
838 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000839 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000840 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000841
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000842 /// \brief Build a new parenthesized type.
843 ///
844 /// By default, builds a new ParenType type from the inner type.
845 /// Subclasses may override this routine to provide different behavior.
846 QualType RebuildParenType(QualType InnerType) {
847 return SemaRef.Context.getParenType(InnerType);
848 }
849
Douglas Gregord6ff3322009-08-04 16:50:30 +0000850 /// \brief Build a new qualified name type.
851 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000852 /// By default, builds a new ElaboratedType type from the keyword,
853 /// the nested-name-specifier and the named type.
854 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000855 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
856 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000857 NestedNameSpecifierLoc QualifierLoc,
858 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getElaboratedType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000861 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000862 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000863
864 /// \brief Build a new typename type that refers to a template-id.
865 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000866 /// By default, builds a new DependentNameType type from the
867 /// nested-name-specifier and the given type. Subclasses may override
868 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000869 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 ElaboratedTypeKeyword Keyword,
871 NestedNameSpecifierLoc QualifierLoc,
872 const IdentifierInfo *Name,
873 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000874 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 // Rebuild the template name.
876 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000877 CXXScopeSpec SS;
878 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000879 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000880 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
881 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000882
Douglas Gregora7a795b2011-03-01 20:11:18 +0000883 if (InstName.isNull())
884 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000885
Douglas Gregora7a795b2011-03-01 20:11:18 +0000886 // If it's still dependent, make a dependent specialization.
887 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000888 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
889 QualifierLoc.getNestedNameSpecifier(),
890 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000892
Douglas Gregora7a795b2011-03-01 20:11:18 +0000893 // Otherwise, make an elaborated type wrapping a non-dependent
894 // specialization.
895 QualType T =
896 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
897 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000898
Craig Topperc3ec1492014-05-26 06:22:03 +0000899 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000900 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000901
902 return SemaRef.Context.getElaboratedType(Keyword,
903 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000904 T);
905 }
906
Douglas Gregord6ff3322009-08-04 16:50:30 +0000907 /// \brief Build a new typename type that refers to an identifier.
908 ///
909 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000910 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000911 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000912 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000913 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000914 NestedNameSpecifierLoc QualifierLoc,
915 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000916 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000918 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000919
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000920 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000921 // If the name is still dependent, just build a new dependent name type.
922 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000923 return SemaRef.Context.getDependentNameType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000925 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 }
927
Abramo Bagnara6150c882010-05-11 21:36:43 +0000928 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000929 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000930 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000931
932 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
933
Abramo Bagnarad7548482010-05-19 21:37:53 +0000934 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000935 // into a non-dependent elaborated-type-specifier. Find the tag we're
936 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000937 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
939 if (!DC)
940 return QualType();
941
John McCallbf8c5192010-05-27 06:40:31 +0000942 if (SemaRef.RequireCompleteDeclContext(SS, DC))
943 return QualType();
944
Craig Topperc3ec1492014-05-26 06:22:03 +0000945 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::NotFound:
949 case LookupResult::NotFoundInCurrentInstantiation:
950 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000951
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 case LookupResult::Found:
953 Tag = Result.getAsSingle<TagDecl>();
954 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000955
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 case LookupResult::FoundOverloaded:
957 case LookupResult::FoundUnresolvedValue:
958 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000959
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 case LookupResult::Ambiguous:
961 // Let the LookupResult structure handle ambiguities.
962 return QualType();
963 }
964
965 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000966 // Check where the name exists but isn't a tag type and use that to emit
967 // better diagnostics.
968 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
969 SemaRef.LookupQualifiedName(Result, DC);
970 switch (Result.getResultKind()) {
971 case LookupResult::Found:
972 case LookupResult::FoundOverloaded:
973 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000974 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000975 unsigned Kind = 0;
976 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000977 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
978 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000979 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
980 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
981 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000982 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000983 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000985 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000986 break;
987 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000988 return QualType();
989 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000990
Richard Trieucaa33d32011-06-10 03:11:26 +0000991 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
992 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000993 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000994 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
995 return QualType();
996 }
997
998 // Build the elaborated-type-specifier type.
999 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001000 return SemaRef.Context.getElaboratedType(Keyword,
1001 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001002 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregor822d0302011-01-12 17:07:58 +00001005 /// \brief Build a new pack expansion type.
1006 ///
1007 /// By default, builds a new PackExpansionType type from the given pattern.
1008 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001009 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001010 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001011 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001012 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001013 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1014 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001015 }
1016
Eli Friedman0dfb8892011-10-06 23:00:33 +00001017 /// \brief Build a new atomic type given its value type.
1018 ///
1019 /// By default, performs semantic analysis when building the atomic type.
1020 /// Subclasses may override this routine to provide different behavior.
1021 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1022
Douglas Gregor71dc5092009-08-06 06:41:21 +00001023 /// \brief Build a new template name given a nested name specifier, a flag
1024 /// indicating whether the "template" keyword was provided, and the template
1025 /// that the template name refers to.
1026 ///
1027 /// By default, builds the new template name directly. Subclasses may override
1028 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001029 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001030 bool TemplateKW,
1031 TemplateDecl *Template);
1032
Douglas Gregor71dc5092009-08-06 06:41:21 +00001033 /// \brief Build a new template name given a nested name specifier and the
1034 /// name that is referred to as a template.
1035 ///
1036 /// By default, performs semantic analysis to determine whether the name can
1037 /// be resolved to a specific template, then builds the appropriate kind of
1038 /// template name. Subclasses may override this routine to provide different
1039 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001040 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1041 const IdentifierInfo &Name,
1042 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001043 QualType ObjectType,
1044 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001045
Douglas Gregor71395fa2009-11-04 00:56:37 +00001046 /// \brief Build a new template name given a nested name specifier and the
1047 /// overloaded operator name that is referred to as a template.
1048 ///
1049 /// By default, performs semantic analysis to determine whether the name can
1050 /// be resolved to a specific template, then builds the appropriate kind of
1051 /// template name. Subclasses may override this routine to provide different
1052 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001053 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001054 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001056 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001057
1058 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001059 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001060 ///
1061 /// By default, performs semantic analysis to determine whether the name can
1062 /// be resolved to a specific template, then builds the appropriate kind of
1063 /// template name. Subclasses may override this routine to provide different
1064 /// behavior.
1065 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1066 const TemplateArgument &ArgPack) {
1067 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1068 }
1069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new compound statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001074 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 MultiStmtArg Statements,
1076 SourceLocation RBraceLoc,
1077 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001078 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 IsStmtExpr);
1080 }
1081
1082 /// \brief Build a new case statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001089 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001091 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 ColonLoc);
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Attach the body to a new case statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001099 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001100 getSema().ActOnCaseStmtBody(S, Body);
1101 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 /// \brief Build a new default statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001108 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001110 Stmt *SubStmt) {
1111 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001112 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Build a new label statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001119 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1120 SourceLocation ColonLoc, Stmt *SubStmt) {
1121 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Richard Smithc202b282012-04-14 00:33:13 +00001124 /// \brief Build a new label statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001128 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1129 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001130 Stmt *SubStmt) {
1131 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1132 }
1133
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 /// \brief Build a new "if" statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001138 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001139 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001140 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001141 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
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 Start building a new switch statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001148 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001149 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001150 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001151 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Douglas Gregorebe10102009-08-20 07:17:43 +00001154 /// \brief Attach the body to the switch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001159 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001160 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001161 }
1162
1163 /// \brief Build a new while statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001167 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1168 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001169 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new do-while statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001177 SourceLocation WhileLoc, SourceLocation LParenLoc,
1178 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001179 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1180 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
1182
1183 /// \brief Build a new for statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001188 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 VarDecl *CondVar, Sema::FullExprArg Inc,
1190 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001191 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001192 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 }
Mike Stump11289f42009-09-09 15:08:12 +00001194
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 /// \brief Build a new goto statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001199 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1200 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001201 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new indirect goto statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001209 SourceLocation StarLoc,
1210 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001211 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 /// \brief Build a new return statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001219 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 /// \brief Build a new declaration statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001226 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001227 SourceLocation StartLoc, SourceLocation EndLoc) {
1228 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001229 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Anders Carlssonaaeef072010-01-24 05:50:09 +00001232 /// \brief Build a new inline asm statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001236 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1237 bool IsVolatile, unsigned NumOutputs,
1238 unsigned NumInputs, IdentifierInfo **Names,
1239 MultiExprArg Constraints, MultiExprArg Exprs,
1240 Expr *AsmString, MultiExprArg Clobbers,
1241 SourceLocation RParenLoc) {
1242 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1243 NumInputs, Names, Constraints, Exprs,
1244 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001245 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001246
Chad Rosier32503022012-06-11 20:47:18 +00001247 /// \brief Build a new MS style inline asm statement.
1248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001251 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001252 ArrayRef<Token> AsmToks,
1253 StringRef AsmString,
1254 unsigned NumOutputs, unsigned NumInputs,
1255 ArrayRef<StringRef> Constraints,
1256 ArrayRef<StringRef> Clobbers,
1257 ArrayRef<Expr*> Exprs,
1258 SourceLocation EndLoc) {
1259 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1260 NumOutputs, NumInputs,
1261 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001262 }
1263
James Dennett2a4d13c2012-06-15 07:13:21 +00001264 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001268 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001269 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001270 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001271 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001272 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001273 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001274 }
1275
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 /// \brief Rebuild an Objective-C exception declaration.
1277 ///
1278 /// By default, performs semantic analysis to build the new declaration.
1279 /// Subclasses may override this routine to provide different behavior.
1280 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1281 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001282 return getSema().BuildObjCExceptionDecl(TInfo, T,
1283 ExceptionDecl->getInnerLocStart(),
1284 ExceptionDecl->getLocation(),
1285 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001287
James Dennett2a4d13c2012-06-15 07:13:21 +00001288 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001293 SourceLocation RParenLoc,
1294 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001295 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001296 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001297 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001298 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001299
James Dennett2a4d13c2012-06-15 07:13:21 +00001300 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001301 ///
1302 /// By default, performs semantic analysis to build the new statement.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001305 Stmt *Body) {
1306 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001308
James Dennett2a4d13c2012-06-15 07:13:21 +00001309 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001314 Expr *Operand) {
1315 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001317
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001318 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001319 ///
1320 /// By default, performs semantic analysis to build the new statement.
1321 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001322 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001323 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001324 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001325 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001326 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001327 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1328 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001329 }
1330
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001331 /// \brief Build a new OpenMP 'if' clause.
1332 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001333 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001334 /// Subclasses may override this routine to provide different behavior.
1335 OMPClause *RebuildOMPIfClause(Expr *Condition,
1336 SourceLocation StartLoc,
1337 SourceLocation LParenLoc,
1338 SourceLocation EndLoc) {
1339 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1340 LParenLoc, EndLoc);
1341 }
1342
Alexey Bataev3778b602014-07-17 07:32:53 +00001343 /// \brief Build a new OpenMP 'final' clause.
1344 ///
1345 /// By default, performs semantic analysis to build the new OpenMP clause.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1351 EndLoc);
1352 }
1353
Alexey Bataev568a8332014-03-06 06:15:19 +00001354 /// \brief Build a new OpenMP 'num_threads' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1359 SourceLocation StartLoc,
1360 SourceLocation LParenLoc,
1361 SourceLocation EndLoc) {
1362 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1363 LParenLoc, EndLoc);
1364 }
1365
Alexey Bataev62c87d22014-03-21 04:51:18 +00001366 /// \brief Build a new OpenMP 'safelen' clause.
1367 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001368 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001369 /// Subclasses may override this routine to provide different behavior.
1370 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1374 }
1375
Alexander Musman8bd31e62014-05-27 15:12:19 +00001376 /// \brief Build a new OpenMP 'collapse' clause.
1377 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001378 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001379 /// Subclasses may override this routine to provide different behavior.
1380 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1381 SourceLocation LParenLoc,
1382 SourceLocation EndLoc) {
1383 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1384 EndLoc);
1385 }
1386
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001387 /// \brief Build a new OpenMP 'default' clause.
1388 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001389 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001390 /// Subclasses may override this routine to provide different behavior.
1391 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1392 SourceLocation KindKwLoc,
1393 SourceLocation StartLoc,
1394 SourceLocation LParenLoc,
1395 SourceLocation EndLoc) {
1396 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1397 StartLoc, LParenLoc, EndLoc);
1398 }
1399
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001400 /// \brief Build a new OpenMP 'proc_bind' clause.
1401 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001402 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001403 /// Subclasses may override this routine to provide different behavior.
1404 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1405 SourceLocation KindKwLoc,
1406 SourceLocation StartLoc,
1407 SourceLocation LParenLoc,
1408 SourceLocation EndLoc) {
1409 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1410 StartLoc, LParenLoc, EndLoc);
1411 }
1412
Alexey Bataev56dafe82014-06-20 07:16:17 +00001413 /// \brief Build a new OpenMP 'schedule' clause.
1414 ///
1415 /// By default, performs semantic analysis to build the new OpenMP clause.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1418 Expr *ChunkSize,
1419 SourceLocation StartLoc,
1420 SourceLocation LParenLoc,
1421 SourceLocation KindLoc,
1422 SourceLocation CommaLoc,
1423 SourceLocation EndLoc) {
1424 return getSema().ActOnOpenMPScheduleClause(
1425 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1426 }
1427
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001428 /// \brief Build a new OpenMP 'private' clause.
1429 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001430 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001431 /// Subclasses may override this routine to provide different behavior.
1432 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation EndLoc) {
1436 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1437 EndLoc);
1438 }
1439
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001440 /// \brief Build a new OpenMP 'firstprivate' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1445 SourceLocation StartLoc,
1446 SourceLocation LParenLoc,
1447 SourceLocation EndLoc) {
1448 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1449 EndLoc);
1450 }
1451
Alexander Musman1bb328c2014-06-04 13:06:39 +00001452 /// \brief Build a new OpenMP 'lastprivate' clause.
1453 ///
1454 /// By default, performs semantic analysis to build the new OpenMP clause.
1455 /// Subclasses may override this routine to provide different behavior.
1456 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1457 SourceLocation StartLoc,
1458 SourceLocation LParenLoc,
1459 SourceLocation EndLoc) {
1460 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1461 EndLoc);
1462 }
1463
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001464 /// \brief Build a new OpenMP 'shared' clause.
1465 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001466 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001467 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001468 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1469 SourceLocation StartLoc,
1470 SourceLocation LParenLoc,
1471 SourceLocation EndLoc) {
1472 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1473 EndLoc);
1474 }
1475
Alexey Bataevc5e02582014-06-16 07:08:35 +00001476 /// \brief Build a new OpenMP 'reduction' clause.
1477 ///
1478 /// By default, performs semantic analysis to build the new statement.
1479 /// Subclasses may override this routine to provide different behavior.
1480 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1481 SourceLocation StartLoc,
1482 SourceLocation LParenLoc,
1483 SourceLocation ColonLoc,
1484 SourceLocation EndLoc,
1485 CXXScopeSpec &ReductionIdScopeSpec,
1486 const DeclarationNameInfo &ReductionId) {
1487 return getSema().ActOnOpenMPReductionClause(
1488 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1489 ReductionId);
1490 }
1491
Alexander Musman8dba6642014-04-22 13:09:42 +00001492 /// \brief Build a new OpenMP 'linear' clause.
1493 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001494 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001495 /// Subclasses may override this routine to provide different behavior.
1496 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1497 SourceLocation StartLoc,
1498 SourceLocation LParenLoc,
1499 SourceLocation ColonLoc,
1500 SourceLocation EndLoc) {
1501 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1502 ColonLoc, EndLoc);
1503 }
1504
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001505 /// \brief Build a new OpenMP 'aligned' clause.
1506 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001507 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001508 /// Subclasses may override this routine to provide different behavior.
1509 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1510 SourceLocation StartLoc,
1511 SourceLocation LParenLoc,
1512 SourceLocation ColonLoc,
1513 SourceLocation EndLoc) {
1514 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1515 LParenLoc, ColonLoc, EndLoc);
1516 }
1517
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001518 /// \brief Build a new OpenMP 'copyin' clause.
1519 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001520 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1523 SourceLocation StartLoc,
1524 SourceLocation LParenLoc,
1525 SourceLocation EndLoc) {
1526 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1527 EndLoc);
1528 }
1529
Alexey Bataevbae9a792014-06-27 10:37:06 +00001530 /// \brief Build a new OpenMP 'copyprivate' clause.
1531 ///
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1535 SourceLocation StartLoc,
1536 SourceLocation LParenLoc,
1537 SourceLocation EndLoc) {
1538 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1539 EndLoc);
1540 }
1541
Alexey Bataev6125da92014-07-21 11:26:11 +00001542 /// \brief Build a new OpenMP 'flush' pseudo clause.
1543 ///
1544 /// By default, performs semantic analysis to build the new OpenMP clause.
1545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
1549 SourceLocation EndLoc) {
1550 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1551 EndLoc);
1552 }
1553
James Dennett2a4d13c2012-06-15 07:13:21 +00001554 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001555 ///
1556 /// By default, performs semantic analysis to build the new statement.
1557 /// Subclasses may override this routine to provide different behavior.
1558 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1559 Expr *object) {
1560 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1561 }
1562
James Dennett2a4d13c2012-06-15 07:13:21 +00001563 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001564 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001565 /// By default, performs semantic analysis to build the new statement.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001568 Expr *Object, Stmt *Body) {
1569 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001570 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001571
James Dennett2a4d13c2012-06-15 07:13:21 +00001572 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001573 ///
1574 /// By default, performs semantic analysis to build the new statement.
1575 /// Subclasses may override this routine to provide different behavior.
1576 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1577 Stmt *Body) {
1578 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1579 }
John McCall53848232011-07-27 01:07:15 +00001580
Douglas Gregorf68a5082010-04-22 23:10:45 +00001581 /// \brief Build a new Objective-C fast enumeration statement.
1582 ///
1583 /// By default, performs semantic analysis to build the new statement.
1584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001585 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001586 Stmt *Element,
1587 Expr *Collection,
1588 SourceLocation RParenLoc,
1589 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001590 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001591 Element,
John McCallb268a282010-08-23 23:25:46 +00001592 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001593 RParenLoc);
1594 if (ForEachStmt.isInvalid())
1595 return StmtError();
1596
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001597 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001599
Douglas Gregorebe10102009-08-20 07:17:43 +00001600 /// \brief Build a new C++ exception declaration.
1601 ///
1602 /// By default, performs semantic analysis to build the new decaration.
1603 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001604 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001605 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001606 SourceLocation StartLoc,
1607 SourceLocation IdLoc,
1608 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001609 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001610 StartLoc, IdLoc, Id);
1611 if (Var)
1612 getSema().CurContext->addDecl(Var);
1613 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001614 }
1615
1616 /// \brief Build a new C++ catch statement.
1617 ///
1618 /// By default, performs semantic analysis to build the new statement.
1619 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001620 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001621 VarDecl *ExceptionDecl,
1622 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001623 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1624 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626
Douglas Gregorebe10102009-08-20 07:17:43 +00001627 /// \brief Build a new C++ try statement.
1628 ///
1629 /// By default, performs semantic analysis to build the new statement.
1630 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001631 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1632 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001633 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Richard Smith02e85f32011-04-14 22:09:26 +00001636 /// \brief Build a new C++0x range-based for statement.
1637 ///
1638 /// By default, performs semantic analysis to build the new statement.
1639 /// Subclasses may override this routine to provide different behavior.
1640 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1641 SourceLocation ColonLoc,
1642 Stmt *Range, Stmt *BeginEnd,
1643 Expr *Cond, Expr *Inc,
1644 Stmt *LoopVar,
1645 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001646 // If we've just learned that the range is actually an Objective-C
1647 // collection, treat this as an Objective-C fast enumeration loop.
1648 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1649 if (RangeStmt->isSingleDecl()) {
1650 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001651 if (RangeVar->isInvalidDecl())
1652 return StmtError();
1653
Douglas Gregorf7106af2013-04-08 18:40:13 +00001654 Expr *RangeExpr = RangeVar->getInit();
1655 if (!RangeExpr->isTypeDependent() &&
1656 RangeExpr->getType()->isObjCObjectPointerType())
1657 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1658 RParenLoc);
1659 }
1660 }
1661 }
1662
Richard Smith02e85f32011-04-14 22:09:26 +00001663 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001664 Cond, Inc, LoopVar, RParenLoc,
1665 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001666 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001667
1668 /// \brief Build a new C++0x range-based for statement.
1669 ///
1670 /// By default, performs semantic analysis to build the new statement.
1671 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001672 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001673 bool IsIfExists,
1674 NestedNameSpecifierLoc QualifierLoc,
1675 DeclarationNameInfo NameInfo,
1676 Stmt *Nested) {
1677 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1678 QualifierLoc, NameInfo, Nested);
1679 }
1680
Richard Smith02e85f32011-04-14 22:09:26 +00001681 /// \brief Attach body to a C++0x range-based for statement.
1682 ///
1683 /// By default, performs semantic analysis to finish the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1685 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1686 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1687 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001688
David Majnemerfad8f482013-10-15 09:33:02 +00001689 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001690 Stmt *TryBlock, Stmt *Handler) {
1691 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001692 }
1693
David Majnemerfad8f482013-10-15 09:33:02 +00001694 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001695 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001696 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001697 }
1698
David Majnemerfad8f482013-10-15 09:33:02 +00001699 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001700 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001701 }
1702
Alexey Bataevec474782014-10-09 08:45:04 +00001703 /// \brief Build a new predefined expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
1707 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1708 PredefinedExpr::IdentType IT) {
1709 return getSema().BuildPredefinedExpr(Loc, IT);
1710 }
1711
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// \brief Build a new expression that references a declaration.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001716 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001717 LookupResult &R,
1718 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001719 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1720 }
1721
1722
1723 /// \brief Build a new expression that references a declaration.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001727 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001728 ValueDecl *VD,
1729 const DeclarationNameInfo &NameInfo,
1730 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001731 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001732 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001733
1734 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001735
1736 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
Mike Stump11289f42009-09-09 15:08:12 +00001738
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001740 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001745 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
1747
Douglas Gregorad8a3362009-09-04 17:36:40 +00001748 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001749 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001752 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001753 SourceLocation OperatorLoc,
1754 bool isArrow,
1755 CXXScopeSpec &SS,
1756 TypeSourceInfo *ScopeType,
1757 SourceLocation CCLoc,
1758 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001759 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001762 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001766 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001767 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001768 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 }
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregor882211c2010-04-28 22:16:22 +00001771 /// \brief Build a new builtin offsetof expression.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001776 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001777 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001778 unsigned NumComponents,
1779 SourceLocation RParenLoc) {
1780 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1781 NumComponents, RParenLoc);
1782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001783
1784 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001785 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001786 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001789 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1790 SourceLocation OpLoc,
1791 UnaryExprOrTypeTrait ExprKind,
1792 SourceRange R) {
1793 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 }
1795
Peter Collingbournee190dee2011-03-11 19:24:49 +00001796 /// \brief Build a new sizeof, alignof or vec step expression with an
1797 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001798 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001801 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1802 UnaryExprOrTypeTrait ExprKind,
1803 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001805 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001808
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001809 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001813 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001818 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001820 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001821 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 RBracketLoc);
1823 }
1824
1825 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001831 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001832 Expr *ExecConfig = nullptr) {
1833 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001834 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 }
1836
1837 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001838 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001842 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001843 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001844 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001845 const DeclarationNameInfo &MemberNameInfo,
1846 ValueDecl *Member,
1847 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001848 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001849 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001850 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1851 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001852 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001853 // We have a reference to an unnamed field. This is always the
1854 // base of an anonymous struct/union member access, i.e. the
1855 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001856 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001857 assert(Member->getType()->isRecordType() &&
1858 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001859
Richard Smithcab9a7d2011-10-26 19:06:56 +00001860 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001861 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001862 QualifierLoc.getNestedNameSpecifier(),
1863 FoundDecl, Member);
1864 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001865 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001866 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001867 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001868 MemberExpr *ME = new (getSema().Context)
1869 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1870 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001871 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001872 }
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001874 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001875 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001876
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001877 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001878 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001879
John McCall16df1e52010-03-30 21:47:33 +00001880 // FIXME: this involves duplicating earlier analysis in a lot of
1881 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001882 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001883 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001884 R.resolveKind();
1885
John McCallb268a282010-08-23 23:25:46 +00001886 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001887 SS, TemplateKWLoc,
1888 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001889 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 }
Mike Stump11289f42009-09-09 15:08:12 +00001891
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001893 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001897 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001898 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001899 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 }
1901
1902 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001903 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001907 SourceLocation QuestionLoc,
1908 Expr *LHS,
1909 SourceLocation ColonLoc,
1910 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001911 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1912 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001916 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001920 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001922 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001923 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001924 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 }
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001928 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001932 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001934 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001935 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 SourceLocation OpLoc,
1945 SourceLocation AccessorLoc,
1946 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001947
John McCall10eae182009-11-30 22:42:35 +00001948 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001949 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001950 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001951 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001952 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001953 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001954 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001955 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001963 MultiExprArg Inits,
1964 SourceLocation RBraceLoc,
1965 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001967 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001968 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001969 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001970
Douglas Gregord3d93062009-11-09 17:16:50 +00001971 // Patch in the result type we were given, which may have been computed
1972 // when the initial InitListExpr was built.
1973 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1974 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001975 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001979 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 MultiExprArg ArrayExprs,
1984 SourceLocation EqualOrColonLoc,
1985 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001986 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001989 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001992
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001993 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001997 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// By default, builds the implicit value initialization without performing
1999 /// any semantic analysis. Subclasses may override this routine to provide
2000 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002002 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 }
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002006 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002009 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002010 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002011 SourceLocation RParenLoc) {
2012 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002014 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
2016
2017 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002022 MultiExprArg SubExprs,
2023 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002024 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002028 ///
2029 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// rather than attempting to map the label statement itself.
2031 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002032 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002033 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002034 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 }
Mike Stump11289f42009-09-09 15:08:12 +00002036
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002044 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 }
Mike Stump11289f42009-09-09 15:08:12 +00002046
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// \brief Build a new __builtin_choose_expr expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002052 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation RParenLoc) {
2054 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002055 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 RParenLoc);
2057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
Peter Collingbourne91147592011-04-15 00:35:48 +00002059 /// \brief Build a new generic selection expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
2063 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2064 SourceLocation DefaultLoc,
2065 SourceLocation RParenLoc,
2066 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002067 ArrayRef<TypeSourceInfo *> Types,
2068 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002069 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002070 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002071 }
2072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// \brief Build a new overloaded operator call expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// The semantic analysis provides the behavior of template instantiation,
2077 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002078 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 /// argument-dependent lookup, etc. Subclasses may override this routine to
2080 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002083 Expr *Callee,
2084 Expr *First,
2085 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002086
2087 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// reinterpret_cast.
2089 ///
2090 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002091 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 Stmt::StmtClass Class,
2095 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002096 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 SourceLocation RAngleLoc,
2098 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002099 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 SourceLocation RParenLoc) {
2101 switch (Class) {
2102 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002103 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002104 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002105 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106
2107 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002108 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002109 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002110 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002111
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002113 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002114 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002115 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002119 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002120 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002121 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002122
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002124 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// \brief Build a new C++ static_cast expression.
2129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002134 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RAngleLoc,
2136 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002137 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002139 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002140 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002141 SourceRange(LAngleLoc, RAngleLoc),
2142 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 }
2144
2145 /// \brief Build a new C++ dynamic_cast expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002151 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 SourceLocation RAngleLoc,
2153 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002154 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002156 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002157 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002158 SourceRange(LAngleLoc, RAngleLoc),
2159 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
2161
2162 /// \brief Build a new C++ reinterpret_cast expression.
2163 ///
2164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002168 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 SourceLocation RAngleLoc,
2170 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002173 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002174 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002175 SourceRange(LAngleLoc, RAngleLoc),
2176 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
2178
2179 /// \brief Build a new C++ const_cast expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002185 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RAngleLoc,
2187 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002188 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002190 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002191 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002192 SourceRange(LAngleLoc, RAngleLoc),
2193 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 /// \brief Build a new C++ functional-style cast expression.
2197 ///
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002200 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2201 SourceLocation LParenLoc,
2202 Expr *Sub,
2203 SourceLocation RParenLoc) {
2204 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002205 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 RParenLoc);
2207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 /// \brief Build a new C++ typeid(type) expression.
2210 ///
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002213 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002214 SourceLocation TypeidLoc,
2215 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002217 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002218 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 }
Mike Stump11289f42009-09-09 15:08:12 +00002220
Francois Pichet9f4f2072010-09-08 12:20:18 +00002221
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// \brief Build a new C++ typeid(expr) expression.
2223 ///
2224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002226 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002227 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002228 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002230 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002231 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002232 }
2233
Francois Pichet9f4f2072010-09-08 12:20:18 +00002234 /// \brief Build a new C++ __uuidof(type) expression.
2235 ///
2236 /// By default, performs semantic analysis to build the new expression.
2237 /// Subclasses may override this routine to provide different behavior.
2238 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2239 SourceLocation TypeidLoc,
2240 TypeSourceInfo *Operand,
2241 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002242 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002243 RParenLoc);
2244 }
2245
2246 /// \brief Build a new C++ __uuidof(expr) expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2251 SourceLocation TypeidLoc,
2252 Expr *Operand,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2255 RParenLoc);
2256 }
2257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new C++ "this" expression.
2259 ///
2260 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002261 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002263 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002264 QualType ThisType,
2265 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002266 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002267 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
2269
2270 /// \brief Build a new C++ throw expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002274 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2275 bool IsThrownVariableInScope) {
2276 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 }
2278
2279 /// \brief Build a new C++ default-argument expression.
2280 ///
2281 /// By default, builds a new default-argument expression, which does not
2282 /// require any semantic analysis. Subclasses may override this routine to
2283 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002284 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002285 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002286 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 }
2288
Richard Smith852c9db2013-04-20 22:23:05 +00002289 /// \brief Build a new C++11 default-initialization expression.
2290 ///
2291 /// By default, builds a new default field initialization expression, which
2292 /// does not require any semantic analysis. Subclasses may override this
2293 /// routine to provide different behavior.
2294 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2295 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002296 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002297 }
2298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// \brief Build a new C++ zero-initialization expression.
2300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002303 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2304 SourceLocation LParenLoc,
2305 SourceLocation RParenLoc) {
2306 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002307 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 /// \brief Build a new C++ "new" expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002314 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002315 bool UseGlobal,
2316 SourceLocation PlacementLParen,
2317 MultiExprArg PlacementArgs,
2318 SourceLocation PlacementRParen,
2319 SourceRange TypeIdParens,
2320 QualType AllocatedType,
2321 TypeSourceInfo *AllocatedTypeInfo,
2322 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002323 SourceRange DirectInitRange,
2324 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002325 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002327 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002329 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002330 AllocatedType,
2331 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002332 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002333 DirectInitRange,
2334 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// \brief Build a new C++ "delete" expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002341 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 bool IsGlobalDelete,
2343 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002344 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002346 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregor29c42f22012-02-24 07:38:34 +00002349 /// \brief Build a new type trait expression.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
2353 ExprResult RebuildTypeTrait(TypeTrait Trait,
2354 SourceLocation StartLoc,
2355 ArrayRef<TypeSourceInfo *> Args,
2356 SourceLocation RParenLoc) {
2357 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002359
John Wiegley6242b6a2011-04-28 00:16:57 +00002360 /// \brief Build a new array type trait expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2365 SourceLocation StartLoc,
2366 TypeSourceInfo *TSInfo,
2367 Expr *DimExpr,
2368 SourceLocation RParenLoc) {
2369 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2370 }
2371
John Wiegleyf9f65842011-04-25 06:54:41 +00002372 /// \brief Build a new expression trait expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
2376 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2377 SourceLocation StartLoc,
2378 Expr *Queried,
2379 SourceLocation RParenLoc) {
2380 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2381 }
2382
Mike Stump11289f42009-09-09 15:08:12 +00002383 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 /// expression.
2385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002388 ExprResult RebuildDependentScopeDeclRefExpr(
2389 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002390 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002391 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002392 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002393 bool IsAddressOfOperand,
2394 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002396 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002397
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002398 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002399 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2400 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002401
Reid Kleckner32506ed2014-06-12 23:03:48 +00002402 return getSema().BuildQualifiedDeclarationNameExpr(
2403 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
2405
2406 /// \brief Build a new template-id expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002411 SourceLocation TemplateKWLoc,
2412 LookupResult &R,
2413 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002414 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002415 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2416 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
2419 /// \brief Build a new object-construction expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002424 SourceLocation Loc,
2425 CXXConstructorDecl *Constructor,
2426 bool IsElidable,
2427 MultiExprArg Args,
2428 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002429 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002430 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002431 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002432 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002433 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002434 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002435 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002436 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002437 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002438
Douglas Gregordb121ba2009-12-14 16:27:04 +00002439 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002440 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002441 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002442 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002443 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002444 RequiresZeroInit, ConstructKind,
2445 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 }
2447
2448 /// \brief Build a new object-construction expression.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002452 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2453 SourceLocation LParenLoc,
2454 MultiExprArg Args,
2455 SourceLocation RParenLoc) {
2456 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002458 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 RParenLoc);
2460 }
2461
2462 /// \brief Build a new object-construction expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002466 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2467 SourceLocation LParenLoc,
2468 MultiExprArg Args,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002472 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 RParenLoc);
2474 }
Mike Stump11289f42009-09-09 15:08:12 +00002475
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 /// \brief Build a new member reference expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002480 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002481 QualType BaseType,
2482 bool IsArrow,
2483 SourceLocation OperatorLoc,
2484 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002485 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002486 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002487 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002488 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002490 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002491
John McCallb268a282010-08-23 23:25:46 +00002492 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002493 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002494 SS, TemplateKWLoc,
2495 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002496 MemberNameInfo,
2497 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 }
2499
John McCall10eae182009-11-30 22:42:35 +00002500 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002504 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2505 SourceLocation OperatorLoc,
2506 bool IsArrow,
2507 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002508 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002509 NamedDecl *FirstQualifierInScope,
2510 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002511 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002512 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002513 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002514
John McCallb268a282010-08-23 23:25:46 +00002515 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002516 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002517 SS, TemplateKWLoc,
2518 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002519 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002522 /// \brief Build a new noexcept expression.
2523 ///
2524 /// By default, performs semantic analysis to build the new expression.
2525 /// Subclasses may override this routine to provide different behavior.
2526 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2527 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2528 }
2529
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002530 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002531 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2532 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002533 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002534 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002535 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2537 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002538 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
2540 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2541 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002542 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002543 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002544
Patrick Beard0caa3942012-04-19 00:25:12 +00002545 /// \brief Build a new Objective-C boxed expression.
2546 ///
2547 /// By default, performs semantic analysis to build the new expression.
2548 /// Subclasses may override this routine to provide different behavior.
2549 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2550 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002552
Ted Kremeneke65b0862012-03-06 20:05:56 +00002553 /// \brief Build a new Objective-C array literal.
2554 ///
2555 /// By default, performs semantic analysis to build the new expression.
2556 /// Subclasses may override this routine to provide different behavior.
2557 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2558 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002559 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002560 MultiExprArg(Elements, NumElements));
2561 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002562
2563 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002564 Expr *Base, Expr *Key,
2565 ObjCMethodDecl *getterMethod,
2566 ObjCMethodDecl *setterMethod) {
2567 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2568 getterMethod, setterMethod);
2569 }
2570
2571 /// \brief Build a new Objective-C dictionary literal.
2572 ///
2573 /// By default, performs semantic analysis to build the new expression.
2574 /// Subclasses may override this routine to provide different behavior.
2575 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2576 ObjCDictionaryElement *Elements,
2577 unsigned NumElements) {
2578 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002580
James Dennett2a4d13c2012-06-15 07:13:21 +00002581 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 ///
2583 /// By default, performs semantic analysis to build the new expression.
2584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002585 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002586 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002588 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002589 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002590
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002591 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002592 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002593 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002594 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002595 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002596 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002597 MultiExprArg Args,
2598 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002599 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2600 ReceiverTypeInfo->getType(),
2601 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002602 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002603 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 }
2605
2606 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002607 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002608 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002609 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002610 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002611 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002612 MultiExprArg Args,
2613 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002614 return SemaRef.BuildInstanceMessage(Receiver,
2615 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002616 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002617 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002618 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002619 }
2620
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002621 /// \brief Build a new Objective-C instance/class message to 'super'.
2622 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2623 Selector Sel,
2624 ArrayRef<SourceLocation> SelectorLocs,
2625 ObjCMethodDecl *Method,
2626 SourceLocation LBracLoc,
2627 MultiExprArg Args,
2628 SourceLocation RBracLoc) {
2629 ObjCInterfaceDecl *Class = Method->getClassInterface();
2630 QualType ReceiverTy = SemaRef.Context.getObjCInterfaceType(Class);
2631
2632 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2633 ReceiverTy,
2634 SuperLoc,
2635 Sel, Method, LBracLoc, SelectorLocs,
2636 RBracLoc, Args)
2637 : SemaRef.BuildClassMessage(nullptr,
2638 ReceiverTy,
2639 SuperLoc,
2640 Sel, Method, LBracLoc, SelectorLocs,
2641 RBracLoc, Args);
2642
2643
2644 }
2645
Douglas Gregord51d90d2010-04-26 20:11:03 +00002646 /// \brief Build a new Objective-C ivar reference expression.
2647 ///
2648 /// By default, performs semantic analysis to build the new expression.
2649 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002650 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002651 SourceLocation IvarLoc,
2652 bool IsArrow, bool IsFreeIvar) {
2653 // FIXME: We lose track of the IsFreeIvar bit.
2654 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002655 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2656 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002657 /*FIXME:*/IvarLoc, IsArrow,
2658 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002659 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002660 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002661 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002662 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002663
2664 /// \brief Build a new Objective-C property reference expression.
2665 ///
2666 /// By default, performs semantic analysis to build the new expression.
2667 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002668 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002669 ObjCPropertyDecl *Property,
2670 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002671 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002672 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2673 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2674 /*FIXME:*/PropertyLoc,
2675 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002676 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002677 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002678 NameInfo,
2679 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002680 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002681
John McCallb7bd14f2010-12-02 01:19:52 +00002682 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002683 ///
2684 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002685 /// Subclasses may override this routine to provide different behavior.
2686 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2687 ObjCMethodDecl *Getter,
2688 ObjCMethodDecl *Setter,
2689 SourceLocation PropertyLoc) {
2690 // Since these expressions can only be value-dependent, we do not
2691 // need to perform semantic analysis again.
2692 return Owned(
2693 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2694 VK_LValue, OK_ObjCProperty,
2695 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002696 }
2697
Douglas Gregord51d90d2010-04-26 20:11:03 +00002698 /// \brief Build a new Objective-C "isa" expression.
2699 ///
2700 /// By default, performs semantic analysis to build the new expression.
2701 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002702 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002703 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002704 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002705 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2706 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002707 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002708 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002709 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002710 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002711 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002713
Douglas Gregora16548e2009-08-11 05:31:07 +00002714 /// \brief Build a new shuffle vector expression.
2715 ///
2716 /// By default, performs semantic analysis to build the new expression.
2717 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002718 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002719 MultiExprArg SubExprs,
2720 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002721 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002722 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002723 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2724 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2725 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002726 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002729 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002730 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2731 SemaRef.Context.BuiltinFnTy,
2732 VK_RValue, BuiltinLoc);
2733 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2734 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002735 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002736
2737 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002738 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002739 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002740 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002741
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002743 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002744 }
John McCall31f82722010-11-12 08:19:04 +00002745
Hal Finkelc4d7c822013-09-18 03:29:45 +00002746 /// \brief Build a new convert vector expression.
2747 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2748 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2749 SourceLocation RParenLoc) {
2750 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2751 BuiltinLoc, RParenLoc);
2752 }
2753
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002754 /// \brief Build a new template argument pack expansion.
2755 ///
2756 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002757 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002758 /// different behavior.
2759 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002760 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002761 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002762 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002763 case TemplateArgument::Expression: {
2764 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002765 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2766 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002767 if (Result.isInvalid())
2768 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002769
Douglas Gregor98318c22011-01-03 21:37:45 +00002770 return TemplateArgumentLoc(Result.get(), Result.get());
2771 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002772
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002773 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002774 return TemplateArgumentLoc(TemplateArgument(
2775 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002776 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002777 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002778 Pattern.getTemplateNameLoc(),
2779 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002780
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002781 case TemplateArgument::Null:
2782 case TemplateArgument::Integral:
2783 case TemplateArgument::Declaration:
2784 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002785 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002786 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002787 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002788
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002789 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002790 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002791 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002792 EllipsisLoc,
2793 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002794 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2795 Expansion);
2796 break;
2797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002798
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002799 return TemplateArgumentLoc();
2800 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002801
Douglas Gregor968f23a2011-01-03 19:31:53 +00002802 /// \brief Build a new expression pack expansion.
2803 ///
2804 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002805 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002806 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002807 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002808 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002809 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002810 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002811
Richard Smith0f0af192014-11-08 05:07:16 +00002812 /// \brief Build a new C++1z fold-expression.
2813 ///
2814 /// By default, performs semantic analysis in order to build a new fold
2815 /// expression.
2816 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2817 BinaryOperatorKind Operator,
2818 SourceLocation EllipsisLoc, Expr *RHS,
2819 SourceLocation RParenLoc) {
2820 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2821 RHS, RParenLoc);
2822 }
2823
2824 /// \brief Build an empty C++1z fold-expression with the given operator.
2825 ///
2826 /// By default, produces the fallback value for the fold-expression, or
2827 /// produce an error if there is no fallback value.
2828 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2829 BinaryOperatorKind Operator) {
2830 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2831 }
2832
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002833 /// \brief Build a new atomic operation expression.
2834 ///
2835 /// By default, performs semantic analysis to build the new expression.
2836 /// Subclasses may override this routine to provide different behavior.
2837 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2838 MultiExprArg SubExprs,
2839 QualType RetTy,
2840 AtomicExpr::AtomicOp Op,
2841 SourceLocation RParenLoc) {
2842 // Just create the expression; there is not any interesting semantic
2843 // analysis here because we can't actually build an AtomicExpr until
2844 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002845 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002846 RParenLoc);
2847 }
2848
John McCall31f82722010-11-12 08:19:04 +00002849private:
Douglas Gregor14454802011-02-25 02:25:35 +00002850 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2851 QualType ObjectType,
2852 NamedDecl *FirstQualifierInScope,
2853 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002854
2855 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2856 QualType ObjectType,
2857 NamedDecl *FirstQualifierInScope,
2858 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002859
2860 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2861 NamedDecl *FirstQualifierInScope,
2862 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002863};
Douglas Gregora16548e2009-08-11 05:31:07 +00002864
Douglas Gregorebe10102009-08-20 07:17:43 +00002865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002866StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002867 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002868 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002869
Douglas Gregorebe10102009-08-20 07:17:43 +00002870 switch (S->getStmtClass()) {
2871 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002872
Douglas Gregorebe10102009-08-20 07:17:43 +00002873 // Transform individual statement nodes
2874#define STMT(Node, Parent) \
2875 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002876#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002877#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002878#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002879
Douglas Gregorebe10102009-08-20 07:17:43 +00002880 // Transform expressions by calling TransformExpr.
2881#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002882#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002883#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002884#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002885 {
John McCalldadc5752010-08-24 06:29:42 +00002886 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002887 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002888 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002889
Richard Smith945f8d32013-01-14 22:39:08 +00002890 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002891 }
Mike Stump11289f42009-09-09 15:08:12 +00002892 }
2893
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002894 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002895}
Mike Stump11289f42009-09-09 15:08:12 +00002896
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002897template<typename Derived>
2898OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2899 if (!S)
2900 return S;
2901
2902 switch (S->getClauseKind()) {
2903 default: break;
2904 // Transform individual clause nodes
2905#define OPENMP_CLAUSE(Name, Class) \
2906 case OMPC_ ## Name : \
2907 return getDerived().Transform ## Class(cast<Class>(S));
2908#include "clang/Basic/OpenMPKinds.def"
2909 }
2910
2911 return S;
2912}
2913
Mike Stump11289f42009-09-09 15:08:12 +00002914
Douglas Gregore922c772009-08-04 22:27:00 +00002915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002916ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002917 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002918 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002919
2920 switch (E->getStmtClass()) {
2921 case Stmt::NoStmtClass: break;
2922#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002923#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002924#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002925 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002926#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002927 }
2928
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002929 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002930}
2931
2932template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002933ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002934 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002935 // Initializers are instantiated like expressions, except that various outer
2936 // layers are stripped.
2937 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002938 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002939
2940 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2941 Init = ExprTemp->getSubExpr();
2942
Richard Smithe6ca4752013-05-30 22:40:16 +00002943 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2944 Init = MTE->GetTemporaryExpr();
2945
Richard Smithd59b8322012-12-19 01:39:02 +00002946 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2947 Init = Binder->getSubExpr();
2948
2949 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2950 Init = ICE->getSubExprAsWritten();
2951
Richard Smithcc1b96d2013-06-12 22:31:48 +00002952 if (CXXStdInitializerListExpr *ILE =
2953 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002954 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002955
Richard Smithc6abd962014-07-25 01:12:44 +00002956 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002957 // InitListExprs. Other forms of copy-initialization will be a no-op if
2958 // the initializer is already the right type.
2959 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002960 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002961 return getDerived().TransformExpr(Init);
2962
2963 // Revert value-initialization back to empty parens.
2964 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2965 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002966 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002967 Parens.getEnd());
2968 }
2969
2970 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2971 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002972 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002973 SourceLocation());
2974
2975 // Revert initialization by constructor back to a parenthesized or braced list
2976 // of expressions. Any other form of initializer can just be reused directly.
2977 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002978 return getDerived().TransformExpr(Init);
2979
Richard Smithf8adcdc2014-07-17 05:12:35 +00002980 // If the initialization implicitly converted an initializer list to a
2981 // std::initializer_list object, unwrap the std::initializer_list too.
2982 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002983 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002984
Richard Smithd59b8322012-12-19 01:39:02 +00002985 SmallVector<Expr*, 8> NewArgs;
2986 bool ArgChanged = false;
2987 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002988 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002989 return ExprError();
2990
2991 // If this was list initialization, revert to list form.
2992 if (Construct->isListInitialization())
2993 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2994 Construct->getLocEnd(),
2995 Construct->getType());
2996
Richard Smithd59b8322012-12-19 01:39:02 +00002997 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002998 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002999 if (Parens.isInvalid()) {
3000 // This was a variable declaration's initialization for which no initializer
3001 // was specified.
3002 assert(NewArgs.empty() &&
3003 "no parens or braces but have direct init with arguments?");
3004 return ExprEmpty();
3005 }
Richard Smithd59b8322012-12-19 01:39:02 +00003006 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3007 Parens.getEnd());
3008}
3009
3010template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003011bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3012 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003013 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003014 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003015 bool *ArgChanged) {
3016 for (unsigned I = 0; I != NumInputs; ++I) {
3017 // If requested, drop call arguments that need to be dropped.
3018 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3019 if (ArgChanged)
3020 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003021
Douglas Gregora3efea12011-01-03 19:04:46 +00003022 break;
3023 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003024
Douglas Gregor968f23a2011-01-03 19:31:53 +00003025 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3026 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003027
Chris Lattner01cf8db2011-07-20 06:58:45 +00003028 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003029 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3030 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003031
Douglas Gregor968f23a2011-01-03 19:31:53 +00003032 // Determine whether the set of unexpanded parameter packs can and should
3033 // be expanded.
3034 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003035 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003036 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3037 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003038 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3039 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003040 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003041 Expand, RetainExpansion,
3042 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003043 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003044
Douglas Gregor968f23a2011-01-03 19:31:53 +00003045 if (!Expand) {
3046 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003047 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003048 // expansion.
3049 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3050 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3051 if (OutPattern.isInvalid())
3052 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003053
3054 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003055 Expansion->getEllipsisLoc(),
3056 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003057 if (Out.isInvalid())
3058 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor968f23a2011-01-03 19:31:53 +00003060 if (ArgChanged)
3061 *ArgChanged = true;
3062 Outputs.push_back(Out.get());
3063 continue;
3064 }
John McCall542e7c62011-07-06 07:30:07 +00003065
3066 // Record right away that the argument was changed. This needs
3067 // to happen even if the array expands to nothing.
3068 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003069
Douglas Gregor968f23a2011-01-03 19:31:53 +00003070 // The transform has determined that we should perform an elementwise
3071 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003072 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003073 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3074 ExprResult Out = getDerived().TransformExpr(Pattern);
3075 if (Out.isInvalid())
3076 return true;
3077
Richard Smith9467be42014-06-06 17:33:35 +00003078 // FIXME: Can this happen? We should not try to expand the pack
3079 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003080 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003081 Out = getDerived().RebuildPackExpansion(
3082 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003083 if (Out.isInvalid())
3084 return true;
3085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003086
Douglas Gregor968f23a2011-01-03 19:31:53 +00003087 Outputs.push_back(Out.get());
3088 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003089
Richard Smith9467be42014-06-06 17:33:35 +00003090 // If we're supposed to retain a pack expansion, do so by temporarily
3091 // forgetting the partially-substituted parameter pack.
3092 if (RetainExpansion) {
3093 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3094
3095 ExprResult Out = getDerived().TransformExpr(Pattern);
3096 if (Out.isInvalid())
3097 return true;
3098
3099 Out = getDerived().RebuildPackExpansion(
3100 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3101 if (Out.isInvalid())
3102 return true;
3103
3104 Outputs.push_back(Out.get());
3105 }
3106
Douglas Gregor968f23a2011-01-03 19:31:53 +00003107 continue;
3108 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003109
Richard Smithd59b8322012-12-19 01:39:02 +00003110 ExprResult Result =
3111 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3112 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003113 if (Result.isInvalid())
3114 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregora3efea12011-01-03 19:04:46 +00003116 if (Result.get() != Inputs[I] && ArgChanged)
3117 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
3119 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003121
Douglas Gregora3efea12011-01-03 19:04:46 +00003122 return false;
3123}
3124
3125template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003126NestedNameSpecifierLoc
3127TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3128 NestedNameSpecifierLoc NNS,
3129 QualType ObjectType,
3130 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003131 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003132 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003133 Qualifier = Qualifier.getPrefix())
3134 Qualifiers.push_back(Qualifier);
3135
3136 CXXScopeSpec SS;
3137 while (!Qualifiers.empty()) {
3138 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3139 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
Douglas Gregor14454802011-02-25 02:25:35 +00003141 switch (QNNS->getKind()) {
3142 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003143 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003144 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003145 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003146 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003147 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003148 FirstQualifierInScope, false))
3149 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003150
Douglas Gregor14454802011-02-25 02:25:35 +00003151 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003152
Douglas Gregor14454802011-02-25 02:25:35 +00003153 case NestedNameSpecifier::Namespace: {
3154 NamespaceDecl *NS
3155 = cast_or_null<NamespaceDecl>(
3156 getDerived().TransformDecl(
3157 Q.getLocalBeginLoc(),
3158 QNNS->getAsNamespace()));
3159 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3160 break;
3161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
Douglas Gregor14454802011-02-25 02:25:35 +00003163 case NestedNameSpecifier::NamespaceAlias: {
3164 NamespaceAliasDecl *Alias
3165 = cast_or_null<NamespaceAliasDecl>(
3166 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3167 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003168 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003169 Q.getLocalEndLoc());
3170 break;
3171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregor14454802011-02-25 02:25:35 +00003173 case NestedNameSpecifier::Global:
3174 // There is no meaningful transformation that one could perform on the
3175 // global scope.
3176 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3177 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003178
Nikola Smiljanic67860242014-09-26 00:28:20 +00003179 case NestedNameSpecifier::Super: {
3180 CXXRecordDecl *RD =
3181 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3182 SourceLocation(), QNNS->getAsRecordDecl()));
3183 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3184 break;
3185 }
3186
Douglas Gregor14454802011-02-25 02:25:35 +00003187 case NestedNameSpecifier::TypeSpecWithTemplate:
3188 case NestedNameSpecifier::TypeSpec: {
3189 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3190 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003191
Douglas Gregor14454802011-02-25 02:25:35 +00003192 if (!TL)
3193 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003194
Douglas Gregor14454802011-02-25 02:25:35 +00003195 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003196 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003197 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003198 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003199 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003200 if (TL.getType()->isEnumeralType())
3201 SemaRef.Diag(TL.getBeginLoc(),
3202 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003203 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3204 Q.getLocalEndLoc());
3205 break;
3206 }
Richard Trieude756fb2011-05-07 01:36:37 +00003207 // If the nested-name-specifier is an invalid type def, don't emit an
3208 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003209 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3210 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003211 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003212 << TL.getType() << SS.getRange();
3213 }
Douglas Gregor14454802011-02-25 02:25:35 +00003214 return NestedNameSpecifierLoc();
3215 }
Douglas Gregore16af532011-02-28 18:50:33 +00003216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003217
Douglas Gregore16af532011-02-28 18:50:33 +00003218 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003219 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003220 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003222
Douglas Gregor14454802011-02-25 02:25:35 +00003223 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003224 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003225 !getDerived().AlwaysRebuild())
3226 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003227
3228 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003229 // nested-name-specifier, do so.
3230 if (SS.location_size() == NNS.getDataLength() &&
3231 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3232 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3233
3234 // Allocate new nested-name-specifier location information.
3235 return SS.getWithLocInContext(SemaRef.Context);
3236}
3237
3238template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003239DeclarationNameInfo
3240TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003241::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003242 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003243 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003244 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003245
3246 switch (Name.getNameKind()) {
3247 case DeclarationName::Identifier:
3248 case DeclarationName::ObjCZeroArgSelector:
3249 case DeclarationName::ObjCOneArgSelector:
3250 case DeclarationName::ObjCMultiArgSelector:
3251 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003252 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003253 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003254 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003255
Douglas Gregorf816bd72009-09-03 22:13:48 +00003256 case DeclarationName::CXXConstructorName:
3257 case DeclarationName::CXXDestructorName:
3258 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003259 TypeSourceInfo *NewTInfo;
3260 CanQualType NewCanTy;
3261 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003262 NewTInfo = getDerived().TransformType(OldTInfo);
3263 if (!NewTInfo)
3264 return DeclarationNameInfo();
3265 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003266 }
3267 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003268 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003269 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003270 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003271 if (NewT.isNull())
3272 return DeclarationNameInfo();
3273 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3274 }
Mike Stump11289f42009-09-09 15:08:12 +00003275
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003276 DeclarationName NewName
3277 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3278 NewCanTy);
3279 DeclarationNameInfo NewNameInfo(NameInfo);
3280 NewNameInfo.setName(NewName);
3281 NewNameInfo.setNamedTypeInfo(NewTInfo);
3282 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003283 }
Mike Stump11289f42009-09-09 15:08:12 +00003284 }
3285
David Blaikie83d382b2011-09-23 05:06:16 +00003286 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003287}
3288
3289template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003290TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003291TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3292 TemplateName Name,
3293 SourceLocation NameLoc,
3294 QualType ObjectType,
3295 NamedDecl *FirstQualifierInScope) {
3296 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3297 TemplateDecl *Template = QTN->getTemplateDecl();
3298 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003299
Douglas Gregor9db53502011-03-02 18:07:45 +00003300 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003301 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003302 Template));
3303 if (!TransTemplate)
3304 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Douglas Gregor9db53502011-03-02 18:07:45 +00003306 if (!getDerived().AlwaysRebuild() &&
3307 SS.getScopeRep() == QTN->getQualifier() &&
3308 TransTemplate == Template)
3309 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor9db53502011-03-02 18:07:45 +00003311 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3312 TransTemplate);
3313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregor9db53502011-03-02 18:07:45 +00003315 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3316 if (SS.getScopeRep()) {
3317 // These apply to the scope specifier, not the template.
3318 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003319 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003320 }
3321
Douglas Gregor9db53502011-03-02 18:07:45 +00003322 if (!getDerived().AlwaysRebuild() &&
3323 SS.getScopeRep() == DTN->getQualifier() &&
3324 ObjectType.isNull())
3325 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregor9db53502011-03-02 18:07:45 +00003327 if (DTN->isIdentifier()) {
3328 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003329 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003330 NameLoc,
3331 ObjectType,
3332 FirstQualifierInScope);
3333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003334
Douglas Gregor9db53502011-03-02 18:07:45 +00003335 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3336 ObjectType);
3337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregor9db53502011-03-02 18:07:45 +00003339 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3340 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003341 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003342 Template));
3343 if (!TransTemplate)
3344 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregor9db53502011-03-02 18:07:45 +00003346 if (!getDerived().AlwaysRebuild() &&
3347 TransTemplate == Template)
3348 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregor9db53502011-03-02 18:07:45 +00003350 return TemplateName(TransTemplate);
3351 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003352
Douglas Gregor9db53502011-03-02 18:07:45 +00003353 if (SubstTemplateTemplateParmPackStorage *SubstPack
3354 = Name.getAsSubstTemplateTemplateParmPack()) {
3355 TemplateTemplateParmDecl *TransParam
3356 = cast_or_null<TemplateTemplateParmDecl>(
3357 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3358 if (!TransParam)
3359 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregor9db53502011-03-02 18:07:45 +00003361 if (!getDerived().AlwaysRebuild() &&
3362 TransParam == SubstPack->getParameterPack())
3363 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
3365 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003366 SubstPack->getArgumentPack());
3367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregor9db53502011-03-02 18:07:45 +00003369 // These should be getting filtered out before they reach the AST.
3370 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003371}
3372
3373template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003374void TreeTransform<Derived>::InventTemplateArgumentLoc(
3375 const TemplateArgument &Arg,
3376 TemplateArgumentLoc &Output) {
3377 SourceLocation Loc = getDerived().getBaseLocation();
3378 switch (Arg.getKind()) {
3379 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003380 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003381 break;
3382
3383 case TemplateArgument::Type:
3384 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003385 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003386
John McCall0ad16662009-10-29 08:12:44 +00003387 break;
3388
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003389 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003390 case TemplateArgument::TemplateExpansion: {
3391 NestedNameSpecifierLocBuilder Builder;
3392 TemplateName Template = Arg.getAsTemplate();
3393 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3394 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3395 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3396 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor9d802122011-03-02 17:09:35 +00003398 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003399 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003400 Builder.getWithLocInContext(SemaRef.Context),
3401 Loc);
3402 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003403 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003404 Builder.getWithLocInContext(SemaRef.Context),
3405 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003407 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003408 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003409
John McCall0ad16662009-10-29 08:12:44 +00003410 case TemplateArgument::Expression:
3411 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3412 break;
3413
3414 case TemplateArgument::Declaration:
3415 case TemplateArgument::Integral:
3416 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003417 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003418 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003419 break;
3420 }
3421}
3422
3423template<typename Derived>
3424bool TreeTransform<Derived>::TransformTemplateArgument(
3425 const TemplateArgumentLoc &Input,
3426 TemplateArgumentLoc &Output) {
3427 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003428 switch (Arg.getKind()) {
3429 case TemplateArgument::Null:
3430 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003431 case TemplateArgument::Pack:
3432 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003433 case TemplateArgument::NullPtr:
3434 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregore922c772009-08-04 22:27:00 +00003436 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003437 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003438 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003439 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003440
3441 DI = getDerived().TransformType(DI);
3442 if (!DI) return true;
3443
3444 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3445 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003446 }
Mike Stump11289f42009-09-09 15:08:12 +00003447
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003448 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003449 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3450 if (QualifierLoc) {
3451 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3452 if (!QualifierLoc)
3453 return true;
3454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregordf846d12011-03-02 18:46:51 +00003456 CXXScopeSpec SS;
3457 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003458 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003459 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3460 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003461 if (Template.isNull())
3462 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregor9d802122011-03-02 17:09:35 +00003464 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003465 Input.getTemplateNameLoc());
3466 return false;
3467 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003468
3469 case TemplateArgument::TemplateExpansion:
3470 llvm_unreachable("Caller should expand pack expansions");
3471
Douglas Gregore922c772009-08-04 22:27:00 +00003472 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003473 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003474 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003475 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003476
John McCall0ad16662009-10-29 08:12:44 +00003477 Expr *InputExpr = Input.getSourceExpression();
3478 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3479
Chris Lattnercdb591a2011-04-25 20:37:58 +00003480 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003481 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003482 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003483 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003484 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003485 }
Douglas Gregore922c772009-08-04 22:27:00 +00003486 }
Mike Stump11289f42009-09-09 15:08:12 +00003487
Douglas Gregore922c772009-08-04 22:27:00 +00003488 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003489 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003490}
3491
Douglas Gregorfe921a72010-12-20 23:36:19 +00003492/// \brief Iterator adaptor that invents template argument location information
3493/// for each of the template arguments in its underlying iterator.
3494template<typename Derived, typename InputIterator>
3495class TemplateArgumentLocInventIterator {
3496 TreeTransform<Derived> &Self;
3497 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregorfe921a72010-12-20 23:36:19 +00003499public:
3500 typedef TemplateArgumentLoc value_type;
3501 typedef TemplateArgumentLoc reference;
3502 typedef typename std::iterator_traits<InputIterator>::difference_type
3503 difference_type;
3504 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003505
Douglas Gregorfe921a72010-12-20 23:36:19 +00003506 class pointer {
3507 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003508
Douglas Gregorfe921a72010-12-20 23:36:19 +00003509 public:
3510 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Douglas Gregorfe921a72010-12-20 23:36:19 +00003512 const TemplateArgumentLoc *operator->() const { return &Arg; }
3513 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003514
Douglas Gregorfe921a72010-12-20 23:36:19 +00003515 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregorfe921a72010-12-20 23:36:19 +00003517 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3518 InputIterator Iter)
3519 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003520
Douglas Gregorfe921a72010-12-20 23:36:19 +00003521 TemplateArgumentLocInventIterator &operator++() {
3522 ++Iter;
3523 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregorfe921a72010-12-20 23:36:19 +00003526 TemplateArgumentLocInventIterator operator++(int) {
3527 TemplateArgumentLocInventIterator Old(*this);
3528 ++(*this);
3529 return Old;
3530 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003531
Douglas Gregorfe921a72010-12-20 23:36:19 +00003532 reference operator*() const {
3533 TemplateArgumentLoc Result;
3534 Self.InventTemplateArgumentLoc(*Iter, Result);
3535 return Result;
3536 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
Douglas Gregorfe921a72010-12-20 23:36:19 +00003538 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregorfe921a72010-12-20 23:36:19 +00003540 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3541 const TemplateArgumentLocInventIterator &Y) {
3542 return X.Iter == Y.Iter;
3543 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003544
Douglas Gregorfe921a72010-12-20 23:36:19 +00003545 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3546 const TemplateArgumentLocInventIterator &Y) {
3547 return X.Iter != Y.Iter;
3548 }
3549};
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregor42cafa82010-12-20 17:42:22 +00003551template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003552template<typename InputIterator>
3553bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3554 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003555 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003556 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003557 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003558 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003560 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3561 // Unpack argument packs, which we translate them into separate
3562 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003563 // FIXME: We could do much better if we could guarantee that the
3564 // TemplateArgumentLocInfo for the pack expansion would be usable for
3565 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003566 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003567 TemplateArgument::pack_iterator>
3568 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003569 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003570 In.getArgument().pack_begin()),
3571 PackLocIterator(*this,
3572 In.getArgument().pack_end()),
3573 Outputs))
3574 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003575
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003576 continue;
3577 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003579 if (In.getArgument().isPackExpansion()) {
3580 // We have a pack expansion, for which we will be substituting into
3581 // the pattern.
3582 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003583 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003584 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003585 = getSema().getTemplateArgumentPackExpansionPattern(
3586 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Chris Lattner01cf8db2011-07-20 06:58:45 +00003588 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003589 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3590 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003592 // Determine whether the set of unexpanded parameter packs can and should
3593 // be expanded.
3594 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003595 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003596 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003597 if (getDerived().TryExpandParameterPacks(Ellipsis,
3598 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003599 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003600 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003601 RetainExpansion,
3602 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003603 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003605 if (!Expand) {
3606 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003607 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003608 // expansion.
3609 TemplateArgumentLoc OutPattern;
3610 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3611 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3612 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003614 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3615 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003616 if (Out.getArgument().isNull())
3617 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003619 Outputs.addArgument(Out);
3620 continue;
3621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003622
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003623 // The transform has determined that we should perform an elementwise
3624 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003625 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003626 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3627
3628 if (getDerived().TransformTemplateArgument(Pattern, Out))
3629 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003631 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003632 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3633 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003634 if (Out.getArgument().isNull())
3635 return true;
3636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003638 Outputs.addArgument(Out);
3639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003640
Douglas Gregor48d24112011-01-10 20:53:55 +00003641 // If we're supposed to retain a pack expansion, do so by temporarily
3642 // forgetting the partially-substituted parameter pack.
3643 if (RetainExpansion) {
3644 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor48d24112011-01-10 20:53:55 +00003646 if (getDerived().TransformTemplateArgument(Pattern, Out))
3647 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003649 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3650 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003651 if (Out.getArgument().isNull())
3652 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor48d24112011-01-10 20:53:55 +00003654 Outputs.addArgument(Out);
3655 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003656
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003657 continue;
3658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
3660 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003661 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003662 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor42cafa82010-12-20 17:42:22 +00003664 Outputs.addArgument(Out);
3665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
Douglas Gregor42cafa82010-12-20 17:42:22 +00003667 return false;
3668
3669}
3670
Douglas Gregord6ff3322009-08-04 16:50:30 +00003671//===----------------------------------------------------------------------===//
3672// Type transformation
3673//===----------------------------------------------------------------------===//
3674
3675template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003676QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003677 if (getDerived().AlreadyTransformed(T))
3678 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003679
John McCall550e0c22009-10-21 00:40:46 +00003680 // Temporary workaround. All of these transformations should
3681 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003682 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3683 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003684
John McCall31f82722010-11-12 08:19:04 +00003685 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003686
John McCall550e0c22009-10-21 00:40:46 +00003687 if (!NewDI)
3688 return QualType();
3689
3690 return NewDI->getType();
3691}
3692
3693template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003694TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003695 // Refine the base location to the type's location.
3696 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3697 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003698 if (getDerived().AlreadyTransformed(DI->getType()))
3699 return DI;
3700
3701 TypeLocBuilder TLB;
3702
3703 TypeLoc TL = DI->getTypeLoc();
3704 TLB.reserve(TL.getFullDataSize());
3705
John McCall31f82722010-11-12 08:19:04 +00003706 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003707 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003708 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003709
John McCallbcd03502009-12-07 02:54:59 +00003710 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003711}
3712
3713template<typename Derived>
3714QualType
John McCall31f82722010-11-12 08:19:04 +00003715TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003716 switch (T.getTypeLocClass()) {
3717#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003718#define TYPELOC(CLASS, PARENT) \
3719 case TypeLoc::CLASS: \
3720 return getDerived().Transform##CLASS##Type(TLB, \
3721 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003722#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003723 }
Mike Stump11289f42009-09-09 15:08:12 +00003724
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003725 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003726}
3727
3728/// FIXME: By default, this routine adds type qualifiers only to types
3729/// that can have qualifiers, and silently suppresses those qualifiers
3730/// that are not permitted (e.g., qualifiers on reference or function
3731/// types). This is the right thing for template instantiation, but
3732/// probably not for other clients.
3733template<typename Derived>
3734QualType
3735TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003736 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003737 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003738
John McCall31f82722010-11-12 08:19:04 +00003739 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003740 if (Result.isNull())
3741 return QualType();
3742
3743 // Silently suppress qualifiers if the result type can't be qualified.
3744 // FIXME: this is the right thing for template instantiation, but
3745 // probably not for other clients.
3746 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003747 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003748
John McCall31168b02011-06-15 23:02:42 +00003749 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003750 // resulting type.
3751 if (Quals.hasObjCLifetime()) {
3752 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3753 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003754 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003755 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003756 // A lifetime qualifier applied to a substituted template parameter
3757 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003758 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003759 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003760 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3761 QualType Replacement = SubstTypeParam->getReplacementType();
3762 Qualifiers Qs = Replacement.getQualifiers();
3763 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003764 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003765 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3766 Qs);
3767 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003768 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003769 Replacement);
3770 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003771 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3772 // 'auto' types behave the same way as template parameters.
3773 QualType Deduced = AutoTy->getDeducedType();
3774 Qualifiers Qs = Deduced.getQualifiers();
3775 Qs.removeObjCLifetime();
3776 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3777 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003778 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3779 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003780 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003781 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003782 // Otherwise, complain about the addition of a qualifier to an
3783 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003784 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003785 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003786 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003787
Douglas Gregore46db902011-06-17 22:11:49 +00003788 Quals.removeObjCLifetime();
3789 }
3790 }
3791 }
John McCallcb0f89a2010-06-05 06:41:15 +00003792 if (!Quals.empty()) {
3793 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003794 // BuildQualifiedType might not add qualifiers if they are invalid.
3795 if (Result.hasLocalQualifiers())
3796 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003797 // No location information to preserve.
3798 }
John McCall550e0c22009-10-21 00:40:46 +00003799
3800 return Result;
3801}
3802
Douglas Gregor14454802011-02-25 02:25:35 +00003803template<typename Derived>
3804TypeLoc
3805TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3806 QualType ObjectType,
3807 NamedDecl *UnqualLookup,
3808 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003809 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003810 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003811
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003812 TypeSourceInfo *TSI =
3813 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3814 if (TSI)
3815 return TSI->getTypeLoc();
3816 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003817}
3818
Douglas Gregor579c15f2011-03-02 18:32:08 +00003819template<typename Derived>
3820TypeSourceInfo *
3821TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3822 QualType ObjectType,
3823 NamedDecl *UnqualLookup,
3824 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003825 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003826 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003827
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003828 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3829 UnqualLookup, SS);
3830}
3831
3832template <typename Derived>
3833TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3834 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3835 CXXScopeSpec &SS) {
3836 QualType T = TL.getType();
3837 assert(!getDerived().AlreadyTransformed(T));
3838
Douglas Gregor579c15f2011-03-02 18:32:08 +00003839 TypeLocBuilder TLB;
3840 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor579c15f2011-03-02 18:32:08 +00003842 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003843 TemplateSpecializationTypeLoc SpecTL =
3844 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003845
Douglas Gregor579c15f2011-03-02 18:32:08 +00003846 TemplateName Template
3847 = getDerived().TransformTemplateName(SS,
3848 SpecTL.getTypePtr()->getTemplateName(),
3849 SpecTL.getTemplateNameLoc(),
3850 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003851 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003852 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003853
3854 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003855 Template);
3856 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003857 DependentTemplateSpecializationTypeLoc SpecTL =
3858 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor579c15f2011-03-02 18:32:08 +00003860 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003861 = getDerived().RebuildTemplateName(SS,
3862 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003863 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003864 ObjectType, UnqualLookup);
3865 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003866 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
3868 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003869 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003870 Template,
3871 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003872 } else {
3873 // Nothing special needs to be done for these.
3874 Result = getDerived().TransformType(TLB, TL);
3875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
3877 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003878 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003879
Douglas Gregor579c15f2011-03-02 18:32:08 +00003880 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3881}
3882
John McCall550e0c22009-10-21 00:40:46 +00003883template <class TyLoc> static inline
3884QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3885 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3886 NewT.setNameLoc(T.getNameLoc());
3887 return T.getType();
3888}
3889
John McCall550e0c22009-10-21 00:40:46 +00003890template<typename Derived>
3891QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003892 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003893 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3894 NewT.setBuiltinLoc(T.getBuiltinLoc());
3895 if (T.needsExtraLocalData())
3896 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3897 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003898}
Mike Stump11289f42009-09-09 15:08:12 +00003899
Douglas Gregord6ff3322009-08-04 16:50:30 +00003900template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003901QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003902 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003903 // FIXME: recurse?
3904 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905}
Mike Stump11289f42009-09-09 15:08:12 +00003906
Reid Kleckner0503a872013-12-05 01:23:43 +00003907template <typename Derived>
3908QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3909 AdjustedTypeLoc TL) {
3910 // Adjustments applied during transformation are handled elsewhere.
3911 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3912}
3913
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003915QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3916 DecayedTypeLoc TL) {
3917 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3918 if (OriginalType.isNull())
3919 return QualType();
3920
3921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 OriginalType != TL.getOriginalLoc().getType())
3924 Result = SemaRef.Context.getDecayedType(OriginalType);
3925 TLB.push<DecayedTypeLoc>(Result);
3926 // Nothing to set for DecayedTypeLoc.
3927 return Result;
3928}
3929
3930template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003931QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003932 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003933 QualType PointeeType
3934 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003935 if (PointeeType.isNull())
3936 return QualType();
3937
3938 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003939 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003940 // A dependent pointer type 'T *' has is being transformed such
3941 // that an Objective-C class type is being replaced for 'T'. The
3942 // resulting pointer type is an ObjCObjectPointerType, not a
3943 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003944 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003945
John McCall8b07ec22010-05-15 11:32:37 +00003946 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3947 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003948 return Result;
3949 }
John McCall31f82722010-11-12 08:19:04 +00003950
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003951 if (getDerived().AlwaysRebuild() ||
3952 PointeeType != TL.getPointeeLoc().getType()) {
3953 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3954 if (Result.isNull())
3955 return QualType();
3956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
John McCall31168b02011-06-15 23:02:42 +00003958 // Objective-C ARC can add lifetime qualifiers to the type that we're
3959 // pointing to.
3960 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003961
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003962 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3963 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003965}
Mike Stump11289f42009-09-09 15:08:12 +00003966
3967template<typename Derived>
3968QualType
John McCall550e0c22009-10-21 00:40:46 +00003969TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003970 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003971 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003972 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3973 if (PointeeType.isNull())
3974 return QualType();
3975
3976 QualType Result = TL.getType();
3977 if (getDerived().AlwaysRebuild() ||
3978 PointeeType != TL.getPointeeLoc().getType()) {
3979 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003980 TL.getSigilLoc());
3981 if (Result.isNull())
3982 return QualType();
3983 }
3984
Douglas Gregor049211a2010-04-22 16:50:51 +00003985 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003986 NewT.setSigilLoc(TL.getSigilLoc());
3987 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988}
3989
John McCall70dd5f62009-10-30 00:06:24 +00003990/// Transforms a reference type. Note that somewhat paradoxically we
3991/// don't care whether the type itself is an l-value type or an r-value
3992/// type; we only care if the type was *written* as an l-value type
3993/// or an r-value type.
3994template<typename Derived>
3995QualType
3996TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003997 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003998 const ReferenceType *T = TL.getTypePtr();
3999
4000 // Note that this works with the pointee-as-written.
4001 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4002 if (PointeeType.isNull())
4003 return QualType();
4004
4005 QualType Result = TL.getType();
4006 if (getDerived().AlwaysRebuild() ||
4007 PointeeType != T->getPointeeTypeAsWritten()) {
4008 Result = getDerived().RebuildReferenceType(PointeeType,
4009 T->isSpelledAsLValue(),
4010 TL.getSigilLoc());
4011 if (Result.isNull())
4012 return QualType();
4013 }
4014
John McCall31168b02011-06-15 23:02:42 +00004015 // Objective-C ARC can add lifetime qualifiers to the type that we're
4016 // referring to.
4017 TLB.TypeWasModifiedSafely(
4018 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4019
John McCall70dd5f62009-10-30 00:06:24 +00004020 // r-value references can be rebuilt as l-value references.
4021 ReferenceTypeLoc NewTL;
4022 if (isa<LValueReferenceType>(Result))
4023 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4024 else
4025 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4026 NewTL.setSigilLoc(TL.getSigilLoc());
4027
4028 return Result;
4029}
4030
Mike Stump11289f42009-09-09 15:08:12 +00004031template<typename Derived>
4032QualType
John McCall550e0c22009-10-21 00:40:46 +00004033TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004034 LValueReferenceTypeLoc TL) {
4035 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036}
4037
Mike Stump11289f42009-09-09 15:08:12 +00004038template<typename Derived>
4039QualType
John McCall550e0c22009-10-21 00:40:46 +00004040TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004041 RValueReferenceTypeLoc TL) {
4042 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043}
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004046QualType
John McCall550e0c22009-10-21 00:40:46 +00004047TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004048 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004049 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050 if (PointeeType.isNull())
4051 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004052
Abramo Bagnara509357842011-03-05 14:42:21 +00004053 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004054 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004055 if (OldClsTInfo) {
4056 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4057 if (!NewClsTInfo)
4058 return QualType();
4059 }
4060
4061 const MemberPointerType *T = TL.getTypePtr();
4062 QualType OldClsType = QualType(T->getClass(), 0);
4063 QualType NewClsType;
4064 if (NewClsTInfo)
4065 NewClsType = NewClsTInfo->getType();
4066 else {
4067 NewClsType = getDerived().TransformType(OldClsType);
4068 if (NewClsType.isNull())
4069 return QualType();
4070 }
Mike Stump11289f42009-09-09 15:08:12 +00004071
John McCall550e0c22009-10-21 00:40:46 +00004072 QualType Result = TL.getType();
4073 if (getDerived().AlwaysRebuild() ||
4074 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004075 NewClsType != OldClsType) {
4076 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004077 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004078 if (Result.isNull())
4079 return QualType();
4080 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081
Reid Kleckner0503a872013-12-05 01:23:43 +00004082 // If we had to adjust the pointee type when building a member pointer, make
4083 // sure to push TypeLoc info for it.
4084 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4085 if (MPT && PointeeType != MPT->getPointeeType()) {
4086 assert(isa<AdjustedType>(MPT->getPointeeType()));
4087 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4088 }
4089
John McCall550e0c22009-10-21 00:40:46 +00004090 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4091 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004092 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004093
4094 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095}
4096
Mike Stump11289f42009-09-09 15:08:12 +00004097template<typename Derived>
4098QualType
John McCall550e0c22009-10-21 00:40:46 +00004099TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004100 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004101 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004102 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103 if (ElementType.isNull())
4104 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004105
John McCall550e0c22009-10-21 00:40:46 +00004106 QualType Result = TL.getType();
4107 if (getDerived().AlwaysRebuild() ||
4108 ElementType != T->getElementType()) {
4109 Result = getDerived().RebuildConstantArrayType(ElementType,
4110 T->getSizeModifier(),
4111 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004112 T->getIndexTypeCVRQualifiers(),
4113 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004114 if (Result.isNull())
4115 return QualType();
4116 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004117
4118 // We might have either a ConstantArrayType or a VariableArrayType now:
4119 // a ConstantArrayType is allowed to have an element type which is a
4120 // VariableArrayType if the type is dependent. Fortunately, all array
4121 // types have the same location layout.
4122 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004123 NewTL.setLBracketLoc(TL.getLBracketLoc());
4124 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004125
John McCall550e0c22009-10-21 00:40:46 +00004126 Expr *Size = TL.getSizeExpr();
4127 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004128 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4129 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004130 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4131 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004132 }
4133 NewTL.setSizeExpr(Size);
4134
4135 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136}
Mike Stump11289f42009-09-09 15:08:12 +00004137
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004139QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004140 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004141 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004142 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004143 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004144 if (ElementType.isNull())
4145 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004146
John McCall550e0c22009-10-21 00:40:46 +00004147 QualType Result = TL.getType();
4148 if (getDerived().AlwaysRebuild() ||
4149 ElementType != T->getElementType()) {
4150 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004152 T->getIndexTypeCVRQualifiers(),
4153 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004154 if (Result.isNull())
4155 return QualType();
4156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004157
John McCall550e0c22009-10-21 00:40:46 +00004158 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4159 NewTL.setLBracketLoc(TL.getLBracketLoc());
4160 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004161 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004162
4163 return Result;
4164}
4165
4166template<typename Derived>
4167QualType
4168TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004169 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004170 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004171 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4172 if (ElementType.isNull())
4173 return QualType();
4174
John McCalldadc5752010-08-24 06:29:42 +00004175 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004176 = getDerived().TransformExpr(T->getSizeExpr());
4177 if (SizeResult.isInvalid())
4178 return QualType();
4179
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004180 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004181
4182 QualType Result = TL.getType();
4183 if (getDerived().AlwaysRebuild() ||
4184 ElementType != T->getElementType() ||
4185 Size != T->getSizeExpr()) {
4186 Result = getDerived().RebuildVariableArrayType(ElementType,
4187 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004188 Size,
John McCall550e0c22009-10-21 00:40:46 +00004189 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004190 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004191 if (Result.isNull())
4192 return QualType();
4193 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004194
Serge Pavlov774c6d02014-02-06 03:49:11 +00004195 // We might have constant size array now, but fortunately it has the same
4196 // location layout.
4197 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004198 NewTL.setLBracketLoc(TL.getLBracketLoc());
4199 NewTL.setRBracketLoc(TL.getRBracketLoc());
4200 NewTL.setSizeExpr(Size);
4201
4202 return Result;
4203}
4204
4205template<typename Derived>
4206QualType
4207TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004208 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004209 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004210 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4211 if (ElementType.isNull())
4212 return QualType();
4213
Richard Smith764d2fe2011-12-20 02:08:33 +00004214 // Array bounds are constant expressions.
4215 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4216 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004217
John McCall33ddac02011-01-19 10:06:00 +00004218 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4219 Expr *origSize = TL.getSizeExpr();
4220 if (!origSize) origSize = T->getSizeExpr();
4221
4222 ExprResult sizeResult
4223 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004224 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004225 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004226 return QualType();
4227
John McCall33ddac02011-01-19 10:06:00 +00004228 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004229
4230 QualType Result = TL.getType();
4231 if (getDerived().AlwaysRebuild() ||
4232 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004233 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004234 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4235 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004236 size,
John McCall550e0c22009-10-21 00:40:46 +00004237 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004238 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004239 if (Result.isNull())
4240 return QualType();
4241 }
John McCall550e0c22009-10-21 00:40:46 +00004242
4243 // We might have any sort of array type now, but fortunately they
4244 // all have the same location layout.
4245 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4246 NewTL.setLBracketLoc(TL.getLBracketLoc());
4247 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004248 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004249
4250 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004251}
Mike Stump11289f42009-09-09 15:08:12 +00004252
4253template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004255 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004256 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004257 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004258
4259 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004260 QualType ElementType = getDerived().TransformType(T->getElementType());
4261 if (ElementType.isNull())
4262 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004263
Richard Smith764d2fe2011-12-20 02:08:33 +00004264 // Vector sizes are constant expressions.
4265 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4266 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004267
John McCalldadc5752010-08-24 06:29:42 +00004268 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004269 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004270 if (Size.isInvalid())
4271 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004272
John McCall550e0c22009-10-21 00:40:46 +00004273 QualType Result = TL.getType();
4274 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004275 ElementType != T->getElementType() ||
4276 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004277 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004278 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004279 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004280 if (Result.isNull())
4281 return QualType();
4282 }
John McCall550e0c22009-10-21 00:40:46 +00004283
4284 // Result might be dependent or not.
4285 if (isa<DependentSizedExtVectorType>(Result)) {
4286 DependentSizedExtVectorTypeLoc NewTL
4287 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4288 NewTL.setNameLoc(TL.getNameLoc());
4289 } else {
4290 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4291 NewTL.setNameLoc(TL.getNameLoc());
4292 }
4293
4294 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004295}
Mike Stump11289f42009-09-09 15:08:12 +00004296
4297template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004298QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004299 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004300 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004301 QualType ElementType = getDerived().TransformType(T->getElementType());
4302 if (ElementType.isNull())
4303 return QualType();
4304
John McCall550e0c22009-10-21 00:40:46 +00004305 QualType Result = TL.getType();
4306 if (getDerived().AlwaysRebuild() ||
4307 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004308 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004309 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004310 if (Result.isNull())
4311 return QualType();
4312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004313
John McCall550e0c22009-10-21 00:40:46 +00004314 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4315 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004316
John McCall550e0c22009-10-21 00:40:46 +00004317 return Result;
4318}
4319
4320template<typename Derived>
4321QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004322 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004323 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004324 QualType ElementType = getDerived().TransformType(T->getElementType());
4325 if (ElementType.isNull())
4326 return QualType();
4327
4328 QualType Result = TL.getType();
4329 if (getDerived().AlwaysRebuild() ||
4330 ElementType != T->getElementType()) {
4331 Result = getDerived().RebuildExtVectorType(ElementType,
4332 T->getNumElements(),
4333 /*FIXME*/ SourceLocation());
4334 if (Result.isNull())
4335 return QualType();
4336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004337
John McCall550e0c22009-10-21 00:40:46 +00004338 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4339 NewTL.setNameLoc(TL.getNameLoc());
4340
4341 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004342}
Mike Stump11289f42009-09-09 15:08:12 +00004343
David Blaikie05785d12013-02-20 22:23:23 +00004344template <typename Derived>
4345ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4346 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4347 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004348 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004349 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004350
Douglas Gregor715e4612011-01-14 22:40:04 +00004351 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004352 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004353 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004354 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004355 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004356
Douglas Gregor715e4612011-01-14 22:40:04 +00004357 TypeLocBuilder TLB;
4358 TypeLoc NewTL = OldDI->getTypeLoc();
4359 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004360
4361 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004362 OldExpansionTL.getPatternLoc());
4363 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004364 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004365
4366 Result = RebuildPackExpansionType(Result,
4367 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004368 OldExpansionTL.getEllipsisLoc(),
4369 NumExpansions);
4370 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004371 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregor715e4612011-01-14 22:40:04 +00004373 PackExpansionTypeLoc NewExpansionTL
4374 = TLB.push<PackExpansionTypeLoc>(Result);
4375 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4376 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4377 } else
4378 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004379 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004380 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004381
John McCall8fb0d9d2011-05-01 22:35:37 +00004382 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004383 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004384
4385 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4386 OldParm->getDeclContext(),
4387 OldParm->getInnerLocStart(),
4388 OldParm->getLocation(),
4389 OldParm->getIdentifier(),
4390 NewDI->getType(),
4391 NewDI,
4392 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004393 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004394 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4395 OldParm->getFunctionScopeIndex() + indexAdjustment);
4396 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004397}
4398
4399template<typename Derived>
4400bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004401 TransformFunctionTypeParams(SourceLocation Loc,
4402 ParmVarDecl **Params, unsigned NumParams,
4403 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004404 SmallVectorImpl<QualType> &OutParamTypes,
4405 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004406 int indexAdjustment = 0;
4407
Douglas Gregordd472162011-01-07 00:20:55 +00004408 for (unsigned i = 0; i != NumParams; ++i) {
4409 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004410 assert(OldParm->getFunctionScopeIndex() == i);
4411
David Blaikie05785d12013-02-20 22:23:23 +00004412 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004413 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004414 if (OldParm->isParameterPack()) {
4415 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004416 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004417
Douglas Gregor5499af42011-01-05 23:12:31 +00004418 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004419 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004420 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004421 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4422 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004423 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4424
Douglas Gregor5499af42011-01-05 23:12:31 +00004425 // Determine whether we should expand the parameter packs.
4426 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004427 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004428 Optional<unsigned> OrigNumExpansions =
4429 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004430 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004431 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4432 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004433 Unexpanded,
4434 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004435 RetainExpansion,
4436 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004437 return true;
4438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004439
Douglas Gregor5499af42011-01-05 23:12:31 +00004440 if (ShouldExpand) {
4441 // Expand the function parameter pack into multiple, separate
4442 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004443 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004444 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004445 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004446 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004447 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004448 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004449 OrigNumExpansions,
4450 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004451 if (!NewParm)
4452 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004453
Douglas Gregordd472162011-01-07 00:20:55 +00004454 OutParamTypes.push_back(NewParm->getType());
4455 if (PVars)
4456 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004457 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004458
4459 // If we're supposed to retain a pack expansion, do so by temporarily
4460 // forgetting the partially-substituted parameter pack.
4461 if (RetainExpansion) {
4462 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004463 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004464 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004465 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004466 OrigNumExpansions,
4467 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004468 if (!NewParm)
4469 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004470
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004471 OutParamTypes.push_back(NewParm->getType());
4472 if (PVars)
4473 PVars->push_back(NewParm);
4474 }
4475
John McCall8fb0d9d2011-05-01 22:35:37 +00004476 // The next parameter should have the same adjustment as the
4477 // last thing we pushed, but we post-incremented indexAdjustment
4478 // on every push. Also, if we push nothing, the adjustment should
4479 // go down by one.
4480 indexAdjustment--;
4481
Douglas Gregor5499af42011-01-05 23:12:31 +00004482 // We're done with the pack expansion.
4483 continue;
4484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004485
4486 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004487 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004488 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4489 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004490 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004491 NumExpansions,
4492 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004493 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004494 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004495 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004497
John McCall58f10c32010-03-11 09:03:00 +00004498 if (!NewParm)
4499 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004500
Douglas Gregordd472162011-01-07 00:20:55 +00004501 OutParamTypes.push_back(NewParm->getType());
4502 if (PVars)
4503 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004504 continue;
4505 }
John McCall58f10c32010-03-11 09:03:00 +00004506
4507 // Deal with the possibility that we don't have a parameter
4508 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004509 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004510 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004511 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004512 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004513 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004514 = dyn_cast<PackExpansionType>(OldType)) {
4515 // We have a function parameter pack that may need to be expanded.
4516 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004517 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004518 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004519
Douglas Gregor5499af42011-01-05 23:12:31 +00004520 // Determine whether we should expand the parameter packs.
4521 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004522 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004523 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004524 Unexpanded,
4525 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004526 RetainExpansion,
4527 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004528 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004529 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004530
Douglas Gregor5499af42011-01-05 23:12:31 +00004531 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004532 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004533 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004534 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004535 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4536 QualType NewType = getDerived().TransformType(Pattern);
4537 if (NewType.isNull())
4538 return true;
John McCall58f10c32010-03-11 09:03:00 +00004539
Douglas Gregordd472162011-01-07 00:20:55 +00004540 OutParamTypes.push_back(NewType);
4541 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004542 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004544
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 // We're done with the pack expansion.
4546 continue;
4547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004548
Douglas Gregor48d24112011-01-10 20:53:55 +00004549 // If we're supposed to retain a pack expansion, do so by temporarily
4550 // forgetting the partially-substituted parameter pack.
4551 if (RetainExpansion) {
4552 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4553 QualType NewType = getDerived().TransformType(Pattern);
4554 if (NewType.isNull())
4555 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004556
Douglas Gregor48d24112011-01-10 20:53:55 +00004557 OutParamTypes.push_back(NewType);
4558 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004559 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004560 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004561
Chad Rosier1dcde962012-08-08 18:46:20 +00004562 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004563 // expansion.
4564 OldType = Expansion->getPattern();
4565 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004566 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4567 NewType = getDerived().TransformType(OldType);
4568 } else {
4569 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004571
Douglas Gregor5499af42011-01-05 23:12:31 +00004572 if (NewType.isNull())
4573 return true;
4574
4575 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004576 NewType = getSema().Context.getPackExpansionType(NewType,
4577 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004578
Douglas Gregordd472162011-01-07 00:20:55 +00004579 OutParamTypes.push_back(NewType);
4580 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004581 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004582 }
4583
John McCall8fb0d9d2011-05-01 22:35:37 +00004584#ifndef NDEBUG
4585 if (PVars) {
4586 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4587 if (ParmVarDecl *parm = (*PVars)[i])
4588 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004589 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004590#endif
4591
4592 return false;
4593}
John McCall58f10c32010-03-11 09:03:00 +00004594
4595template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004596QualType
John McCall550e0c22009-10-21 00:40:46 +00004597TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004599 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004600 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004601 return getDerived().TransformFunctionProtoType(
4602 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004603 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4604 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4605 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004606 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004607}
4608
Richard Smith2e321552014-11-12 02:00:47 +00004609template<typename Derived> template<typename Fn>
4610QualType TreeTransform<Derived>::TransformFunctionProtoType(
4611 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4612 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004613 // Transform the parameters and return type.
4614 //
Richard Smithf623c962012-04-17 00:58:00 +00004615 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004616 // When the function has a trailing return type, we instantiate the
4617 // parameters before the return type, since the return type can then refer
4618 // to the parameters themselves (via decltype, sizeof, etc.).
4619 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004620 SmallVector<QualType, 4> ParamTypes;
4621 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004622 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004623
Douglas Gregor7fb25412010-10-01 18:44:50 +00004624 QualType ResultType;
4625
Richard Smith1226c602012-08-14 22:51:13 +00004626 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004627 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004628 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004629 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004630 return QualType();
4631
Douglas Gregor3024f072012-04-16 07:05:22 +00004632 {
4633 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004634 // If a declaration declares a member function or member function
4635 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004636 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004637 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004638 // declarator.
4639 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004640
Alp Toker42a16a62014-01-25 23:51:36 +00004641 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004642 if (ResultType.isNull())
4643 return QualType();
4644 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004645 }
4646 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004647 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004648 if (ResultType.isNull())
4649 return QualType();
4650
Alp Toker9cacbab2014-01-20 20:26:09 +00004651 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004652 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004653 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004654 return QualType();
4655 }
4656
Richard Smith2e321552014-11-12 02:00:47 +00004657 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4658
4659 bool EPIChanged = false;
4660 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4661 return QualType();
4662
4663 // FIXME: Need to transform ConsumedParameters for variadic template
4664 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004665
John McCall550e0c22009-10-21 00:40:46 +00004666 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004667 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004668 T->getNumParams() != ParamTypes.size() ||
4669 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004670 ParamTypes.begin()) || EPIChanged) {
4671 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004672 if (Result.isNull())
4673 return QualType();
4674 }
Mike Stump11289f42009-09-09 15:08:12 +00004675
John McCall550e0c22009-10-21 00:40:46 +00004676 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004677 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004678 NewTL.setLParenLoc(TL.getLParenLoc());
4679 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004680 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004681 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4682 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004683
4684 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004685}
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregord6ff3322009-08-04 16:50:30 +00004687template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004688bool TreeTransform<Derived>::TransformExceptionSpec(
4689 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4690 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4691 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4692
4693 // Instantiate a dynamic noexcept expression, if any.
4694 if (ESI.Type == EST_ComputedNoexcept) {
4695 EnterExpressionEvaluationContext Unevaluated(getSema(),
4696 Sema::ConstantEvaluated);
4697 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4698 if (NoexceptExpr.isInvalid())
4699 return true;
4700
4701 NoexceptExpr = getSema().CheckBooleanCondition(
4702 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4703 if (NoexceptExpr.isInvalid())
4704 return true;
4705
4706 if (!NoexceptExpr.get()->isValueDependent()) {
4707 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4708 NoexceptExpr.get(), nullptr,
4709 diag::err_noexcept_needs_constant_expression,
4710 /*AllowFold*/false);
4711 if (NoexceptExpr.isInvalid())
4712 return true;
4713 }
4714
4715 if (ESI.NoexceptExpr != NoexceptExpr.get())
4716 Changed = true;
4717 ESI.NoexceptExpr = NoexceptExpr.get();
4718 }
4719
4720 if (ESI.Type != EST_Dynamic)
4721 return false;
4722
4723 // Instantiate a dynamic exception specification's type.
4724 for (QualType T : ESI.Exceptions) {
4725 if (const PackExpansionType *PackExpansion =
4726 T->getAs<PackExpansionType>()) {
4727 Changed = true;
4728
4729 // We have a pack expansion. Instantiate it.
4730 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4731 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4732 Unexpanded);
4733 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4734
4735 // Determine whether the set of unexpanded parameter packs can and
4736 // should
4737 // be expanded.
4738 bool Expand = false;
4739 bool RetainExpansion = false;
4740 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4741 // FIXME: Track the location of the ellipsis (and track source location
4742 // information for the types in the exception specification in general).
4743 if (getDerived().TryExpandParameterPacks(
4744 Loc, SourceRange(), Unexpanded, Expand,
4745 RetainExpansion, NumExpansions))
4746 return true;
4747
4748 if (!Expand) {
4749 // We can't expand this pack expansion into separate arguments yet;
4750 // just substitute into the pattern and create a new pack expansion
4751 // type.
4752 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4753 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4754 if (U.isNull())
4755 return true;
4756
4757 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4758 Exceptions.push_back(U);
4759 continue;
4760 }
4761
4762 // Substitute into the pack expansion pattern for each slice of the
4763 // pack.
4764 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4765 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4766
4767 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4768 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4769 return true;
4770
4771 Exceptions.push_back(U);
4772 }
4773 } else {
4774 QualType U = getDerived().TransformType(T);
4775 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4776 return true;
4777 if (T != U)
4778 Changed = true;
4779
4780 Exceptions.push_back(U);
4781 }
4782 }
4783
4784 ESI.Exceptions = Exceptions;
4785 return false;
4786}
4787
4788template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004789QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004790 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004791 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004792 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004793 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004794 if (ResultType.isNull())
4795 return QualType();
4796
4797 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004798 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004799 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4800
4801 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004802 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004803 NewTL.setLParenLoc(TL.getLParenLoc());
4804 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004805 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004806
4807 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004808}
Mike Stump11289f42009-09-09 15:08:12 +00004809
John McCallb96ec562009-12-04 22:46:56 +00004810template<typename Derived> QualType
4811TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004812 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004813 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004814 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004815 if (!D)
4816 return QualType();
4817
4818 QualType Result = TL.getType();
4819 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4820 Result = getDerived().RebuildUnresolvedUsingType(D);
4821 if (Result.isNull())
4822 return QualType();
4823 }
4824
4825 // We might get an arbitrary type spec type back. We should at
4826 // least always get a type spec type, though.
4827 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4828 NewTL.setNameLoc(TL.getNameLoc());
4829
4830 return Result;
4831}
4832
Douglas Gregord6ff3322009-08-04 16:50:30 +00004833template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004834QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004835 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004836 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004837 TypedefNameDecl *Typedef
4838 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4839 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004840 if (!Typedef)
4841 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004842
John McCall550e0c22009-10-21 00:40:46 +00004843 QualType Result = TL.getType();
4844 if (getDerived().AlwaysRebuild() ||
4845 Typedef != T->getDecl()) {
4846 Result = getDerived().RebuildTypedefType(Typedef);
4847 if (Result.isNull())
4848 return QualType();
4849 }
Mike Stump11289f42009-09-09 15:08:12 +00004850
John McCall550e0c22009-10-21 00:40:46 +00004851 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4852 NewTL.setNameLoc(TL.getNameLoc());
4853
4854 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004855}
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregord6ff3322009-08-04 16:50:30 +00004857template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004858QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004859 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004860 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004861 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4862 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004863
John McCalldadc5752010-08-24 06:29:42 +00004864 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004865 if (E.isInvalid())
4866 return QualType();
4867
Eli Friedmane4f22df2012-02-29 04:03:55 +00004868 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4869 if (E.isInvalid())
4870 return QualType();
4871
John McCall550e0c22009-10-21 00:40:46 +00004872 QualType Result = TL.getType();
4873 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004874 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004875 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004876 if (Result.isNull())
4877 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004878 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004879 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004880
John McCall550e0c22009-10-21 00:40:46 +00004881 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004882 NewTL.setTypeofLoc(TL.getTypeofLoc());
4883 NewTL.setLParenLoc(TL.getLParenLoc());
4884 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004885
4886 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004887}
Mike Stump11289f42009-09-09 15:08:12 +00004888
4889template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004890QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004891 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004892 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4893 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4894 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004895 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004896
John McCall550e0c22009-10-21 00:40:46 +00004897 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004898 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4899 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004900 if (Result.isNull())
4901 return QualType();
4902 }
Mike Stump11289f42009-09-09 15:08:12 +00004903
John McCall550e0c22009-10-21 00:40:46 +00004904 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004905 NewTL.setTypeofLoc(TL.getTypeofLoc());
4906 NewTL.setLParenLoc(TL.getLParenLoc());
4907 NewTL.setRParenLoc(TL.getRParenLoc());
4908 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004909
4910 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004911}
Mike Stump11289f42009-09-09 15:08:12 +00004912
4913template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004914QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004915 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004916 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004917
Douglas Gregore922c772009-08-04 22:27:00 +00004918 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004919 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4920 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004921
John McCalldadc5752010-08-24 06:29:42 +00004922 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004923 if (E.isInvalid())
4924 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004925
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004926 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004927 if (E.isInvalid())
4928 return QualType();
4929
John McCall550e0c22009-10-21 00:40:46 +00004930 QualType Result = TL.getType();
4931 if (getDerived().AlwaysRebuild() ||
4932 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004933 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004934 if (Result.isNull())
4935 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004936 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004937 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004938
John McCall550e0c22009-10-21 00:40:46 +00004939 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4940 NewTL.setNameLoc(TL.getNameLoc());
4941
4942 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004943}
4944
4945template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004946QualType TreeTransform<Derived>::TransformUnaryTransformType(
4947 TypeLocBuilder &TLB,
4948 UnaryTransformTypeLoc TL) {
4949 QualType Result = TL.getType();
4950 if (Result->isDependentType()) {
4951 const UnaryTransformType *T = TL.getTypePtr();
4952 QualType NewBase =
4953 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4954 Result = getDerived().RebuildUnaryTransformType(NewBase,
4955 T->getUTTKind(),
4956 TL.getKWLoc());
4957 if (Result.isNull())
4958 return QualType();
4959 }
4960
4961 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4962 NewTL.setKWLoc(TL.getKWLoc());
4963 NewTL.setParensRange(TL.getParensRange());
4964 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4965 return Result;
4966}
4967
4968template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004969QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4970 AutoTypeLoc TL) {
4971 const AutoType *T = TL.getTypePtr();
4972 QualType OldDeduced = T->getDeducedType();
4973 QualType NewDeduced;
4974 if (!OldDeduced.isNull()) {
4975 NewDeduced = getDerived().TransformType(OldDeduced);
4976 if (NewDeduced.isNull())
4977 return QualType();
4978 }
4979
4980 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004981 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4982 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004983 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004984 if (Result.isNull())
4985 return QualType();
4986 }
4987
4988 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4989 NewTL.setNameLoc(TL.getNameLoc());
4990
4991 return Result;
4992}
4993
4994template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004995QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004996 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004997 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004998 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004999 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5000 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005001 if (!Record)
5002 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005003
John McCall550e0c22009-10-21 00:40:46 +00005004 QualType Result = TL.getType();
5005 if (getDerived().AlwaysRebuild() ||
5006 Record != T->getDecl()) {
5007 Result = getDerived().RebuildRecordType(Record);
5008 if (Result.isNull())
5009 return QualType();
5010 }
Mike Stump11289f42009-09-09 15:08:12 +00005011
John McCall550e0c22009-10-21 00:40:46 +00005012 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5013 NewTL.setNameLoc(TL.getNameLoc());
5014
5015 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
5018template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005019QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005020 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005021 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005023 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5024 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005025 if (!Enum)
5026 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005027
John McCall550e0c22009-10-21 00:40:46 +00005028 QualType Result = TL.getType();
5029 if (getDerived().AlwaysRebuild() ||
5030 Enum != T->getDecl()) {
5031 Result = getDerived().RebuildEnumType(Enum);
5032 if (Result.isNull())
5033 return QualType();
5034 }
Mike Stump11289f42009-09-09 15:08:12 +00005035
John McCall550e0c22009-10-21 00:40:46 +00005036 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5037 NewTL.setNameLoc(TL.getNameLoc());
5038
5039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005040}
John McCallfcc33b02009-09-05 00:15:47 +00005041
John McCalle78aac42010-03-10 03:28:59 +00005042template<typename Derived>
5043QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5044 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005045 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005046 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5047 TL.getTypePtr()->getDecl());
5048 if (!D) return QualType();
5049
5050 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5051 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5052 return T;
5053}
5054
Douglas Gregord6ff3322009-08-04 16:50:30 +00005055template<typename Derived>
5056QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005057 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005058 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005059 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060}
5061
Mike Stump11289f42009-09-09 15:08:12 +00005062template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005063QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005064 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005065 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005066 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005067
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005068 // Substitute into the replacement type, which itself might involve something
5069 // that needs to be transformed. This only tends to occur with default
5070 // template arguments of template template parameters.
5071 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5072 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5073 if (Replacement.isNull())
5074 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005075
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005076 // Always canonicalize the replacement type.
5077 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5078 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005079 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005080 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005081
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005082 // Propagate type-source information.
5083 SubstTemplateTypeParmTypeLoc NewTL
5084 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5085 NewTL.setNameLoc(TL.getNameLoc());
5086 return Result;
5087
John McCallcebee162009-10-18 09:09:24 +00005088}
5089
5090template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005091QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5092 TypeLocBuilder &TLB,
5093 SubstTemplateTypeParmPackTypeLoc TL) {
5094 return TransformTypeSpecType(TLB, TL);
5095}
5096
5097template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005098QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005099 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005100 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005101 const TemplateSpecializationType *T = TL.getTypePtr();
5102
Douglas Gregordf846d12011-03-02 18:46:51 +00005103 // The nested-name-specifier never matters in a TemplateSpecializationType,
5104 // because we can't have a dependent nested-name-specifier anyway.
5105 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005106 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005107 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5108 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005109 if (Template.isNull())
5110 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005111
John McCall31f82722010-11-12 08:19:04 +00005112 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5113}
5114
Eli Friedman0dfb8892011-10-06 23:00:33 +00005115template<typename Derived>
5116QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5117 AtomicTypeLoc TL) {
5118 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5119 if (ValueType.isNull())
5120 return QualType();
5121
5122 QualType Result = TL.getType();
5123 if (getDerived().AlwaysRebuild() ||
5124 ValueType != TL.getValueLoc().getType()) {
5125 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5126 if (Result.isNull())
5127 return QualType();
5128 }
5129
5130 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5131 NewTL.setKWLoc(TL.getKWLoc());
5132 NewTL.setLParenLoc(TL.getLParenLoc());
5133 NewTL.setRParenLoc(TL.getRParenLoc());
5134
5135 return Result;
5136}
5137
Chad Rosier1dcde962012-08-08 18:46:20 +00005138 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005139 /// container that provides a \c getArgLoc() member function.
5140 ///
5141 /// This iterator is intended to be used with the iterator form of
5142 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5143 template<typename ArgLocContainer>
5144 class TemplateArgumentLocContainerIterator {
5145 ArgLocContainer *Container;
5146 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005147
Douglas Gregorfe921a72010-12-20 23:36:19 +00005148 public:
5149 typedef TemplateArgumentLoc value_type;
5150 typedef TemplateArgumentLoc reference;
5151 typedef int difference_type;
5152 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005153
Douglas Gregorfe921a72010-12-20 23:36:19 +00005154 class pointer {
5155 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005156
Douglas Gregorfe921a72010-12-20 23:36:19 +00005157 public:
5158 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregorfe921a72010-12-20 23:36:19 +00005160 const TemplateArgumentLoc *operator->() const {
5161 return &Arg;
5162 }
5163 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005164
5165
Douglas Gregorfe921a72010-12-20 23:36:19 +00005166 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005167
Douglas Gregorfe921a72010-12-20 23:36:19 +00005168 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5169 unsigned Index)
5170 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005171
Douglas Gregorfe921a72010-12-20 23:36:19 +00005172 TemplateArgumentLocContainerIterator &operator++() {
5173 ++Index;
5174 return *this;
5175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005176
Douglas Gregorfe921a72010-12-20 23:36:19 +00005177 TemplateArgumentLocContainerIterator operator++(int) {
5178 TemplateArgumentLocContainerIterator Old(*this);
5179 ++(*this);
5180 return Old;
5181 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005182
Douglas Gregorfe921a72010-12-20 23:36:19 +00005183 TemplateArgumentLoc operator*() const {
5184 return Container->getArgLoc(Index);
5185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005186
Douglas Gregorfe921a72010-12-20 23:36:19 +00005187 pointer operator->() const {
5188 return pointer(Container->getArgLoc(Index));
5189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
Douglas Gregorfe921a72010-12-20 23:36:19 +00005191 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005192 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005193 return X.Container == Y.Container && X.Index == Y.Index;
5194 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005195
Douglas Gregorfe921a72010-12-20 23:36:19 +00005196 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005197 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005198 return !(X == Y);
5199 }
5200 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005201
5202
John McCall31f82722010-11-12 08:19:04 +00005203template <typename Derived>
5204QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5205 TypeLocBuilder &TLB,
5206 TemplateSpecializationTypeLoc TL,
5207 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005208 TemplateArgumentListInfo NewTemplateArgs;
5209 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5210 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005211 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5212 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005213 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005214 ArgIterator(TL, TL.getNumArgs()),
5215 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005216 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005217
John McCall0ad16662009-10-29 08:12:44 +00005218 // FIXME: maybe don't rebuild if all the template arguments are the same.
5219
5220 QualType Result =
5221 getDerived().RebuildTemplateSpecializationType(Template,
5222 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005223 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005224
5225 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005226 // Specializations of template template parameters are represented as
5227 // TemplateSpecializationTypes, and substitution of type alias templates
5228 // within a dependent context can transform them into
5229 // DependentTemplateSpecializationTypes.
5230 if (isa<DependentTemplateSpecializationType>(Result)) {
5231 DependentTemplateSpecializationTypeLoc NewTL
5232 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005233 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005234 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005235 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005236 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005237 NewTL.setLAngleLoc(TL.getLAngleLoc());
5238 NewTL.setRAngleLoc(TL.getRAngleLoc());
5239 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5240 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5241 return Result;
5242 }
5243
John McCall0ad16662009-10-29 08:12:44 +00005244 TemplateSpecializationTypeLoc NewTL
5245 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005246 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005247 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5248 NewTL.setLAngleLoc(TL.getLAngleLoc());
5249 NewTL.setRAngleLoc(TL.getRAngleLoc());
5250 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5251 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005252 }
Mike Stump11289f42009-09-09 15:08:12 +00005253
John McCall0ad16662009-10-29 08:12:44 +00005254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005255}
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregor5a064722011-02-28 17:23:35 +00005257template <typename Derived>
5258QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5259 TypeLocBuilder &TLB,
5260 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005261 TemplateName Template,
5262 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005263 TemplateArgumentListInfo NewTemplateArgs;
5264 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5265 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5266 typedef TemplateArgumentLocContainerIterator<
5267 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005268 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005269 ArgIterator(TL, TL.getNumArgs()),
5270 NewTemplateArgs))
5271 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005272
Douglas Gregor5a064722011-02-28 17:23:35 +00005273 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005274
Douglas Gregor5a064722011-02-28 17:23:35 +00005275 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5276 QualType Result
5277 = getSema().Context.getDependentTemplateSpecializationType(
5278 TL.getTypePtr()->getKeyword(),
5279 DTN->getQualifier(),
5280 DTN->getIdentifier(),
5281 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005282
Douglas Gregor5a064722011-02-28 17:23:35 +00005283 DependentTemplateSpecializationTypeLoc NewTL
5284 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005285 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005286 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005287 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005288 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005289 NewTL.setLAngleLoc(TL.getLAngleLoc());
5290 NewTL.setRAngleLoc(TL.getRAngleLoc());
5291 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5292 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5293 return Result;
5294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005295
5296 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005297 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005298 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005299 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005300
Douglas Gregor5a064722011-02-28 17:23:35 +00005301 if (!Result.isNull()) {
5302 /// FIXME: Wrap this in an elaborated-type-specifier?
5303 TemplateSpecializationTypeLoc NewTL
5304 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005305 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005306 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005307 NewTL.setLAngleLoc(TL.getLAngleLoc());
5308 NewTL.setRAngleLoc(TL.getRAngleLoc());
5309 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5310 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5311 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005312
Douglas Gregor5a064722011-02-28 17:23:35 +00005313 return Result;
5314}
5315
Mike Stump11289f42009-09-09 15:08:12 +00005316template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005317QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005318TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005319 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005320 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005321
Douglas Gregor844cb502011-03-01 18:12:44 +00005322 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005323 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005324 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005325 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005326 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5327 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005328 return QualType();
5329 }
Mike Stump11289f42009-09-09 15:08:12 +00005330
John McCall31f82722010-11-12 08:19:04 +00005331 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5332 if (NamedT.isNull())
5333 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005334
Richard Smith3f1b5d02011-05-05 21:57:07 +00005335 // C++0x [dcl.type.elab]p2:
5336 // If the identifier resolves to a typedef-name or the simple-template-id
5337 // resolves to an alias template specialization, the
5338 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005339 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5340 if (const TemplateSpecializationType *TST =
5341 NamedT->getAs<TemplateSpecializationType>()) {
5342 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005343 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5344 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005345 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5346 diag::err_tag_reference_non_tag) << 4;
5347 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5348 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005349 }
5350 }
5351
John McCall550e0c22009-10-21 00:40:46 +00005352 QualType Result = TL.getType();
5353 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005354 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005355 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005356 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005357 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005358 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005359 if (Result.isNull())
5360 return QualType();
5361 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005362
Abramo Bagnara6150c882010-05-11 21:36:43 +00005363 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005364 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005365 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005366 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005367}
Mike Stump11289f42009-09-09 15:08:12 +00005368
5369template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005370QualType TreeTransform<Derived>::TransformAttributedType(
5371 TypeLocBuilder &TLB,
5372 AttributedTypeLoc TL) {
5373 const AttributedType *oldType = TL.getTypePtr();
5374 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5375 if (modifiedType.isNull())
5376 return QualType();
5377
5378 QualType result = TL.getType();
5379
5380 // FIXME: dependent operand expressions?
5381 if (getDerived().AlwaysRebuild() ||
5382 modifiedType != oldType->getModifiedType()) {
5383 // TODO: this is really lame; we should really be rebuilding the
5384 // equivalent type from first principles.
5385 QualType equivalentType
5386 = getDerived().TransformType(oldType->getEquivalentType());
5387 if (equivalentType.isNull())
5388 return QualType();
5389 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5390 modifiedType,
5391 equivalentType);
5392 }
5393
5394 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5395 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5396 if (TL.hasAttrOperand())
5397 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5398 if (TL.hasAttrExprOperand())
5399 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5400 else if (TL.hasAttrEnumOperand())
5401 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5402
5403 return result;
5404}
5405
5406template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005407QualType
5408TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5409 ParenTypeLoc TL) {
5410 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5411 if (Inner.isNull())
5412 return QualType();
5413
5414 QualType Result = TL.getType();
5415 if (getDerived().AlwaysRebuild() ||
5416 Inner != TL.getInnerLoc().getType()) {
5417 Result = getDerived().RebuildParenType(Inner);
5418 if (Result.isNull())
5419 return QualType();
5420 }
5421
5422 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5423 NewTL.setLParenLoc(TL.getLParenLoc());
5424 NewTL.setRParenLoc(TL.getRParenLoc());
5425 return Result;
5426}
5427
5428template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005429QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005430 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005431 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005432
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005433 NestedNameSpecifierLoc QualifierLoc
5434 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5435 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005436 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005437
John McCallc392f372010-06-11 00:33:02 +00005438 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005439 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005440 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005441 QualifierLoc,
5442 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005443 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005444 if (Result.isNull())
5445 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005446
Abramo Bagnarad7548482010-05-19 21:37:53 +00005447 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5448 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005449 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5450
Abramo Bagnarad7548482010-05-19 21:37:53 +00005451 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005452 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005453 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005454 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005455 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005456 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005457 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005458 NewTL.setNameLoc(TL.getNameLoc());
5459 }
John McCall550e0c22009-10-21 00:40:46 +00005460 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005461}
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregord6ff3322009-08-04 16:50:30 +00005463template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005464QualType TreeTransform<Derived>::
5465 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005466 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005467 NestedNameSpecifierLoc QualifierLoc;
5468 if (TL.getQualifierLoc()) {
5469 QualifierLoc
5470 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5471 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005472 return QualType();
5473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005474
John McCall31f82722010-11-12 08:19:04 +00005475 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005476 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005477}
5478
5479template<typename Derived>
5480QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005481TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5482 DependentTemplateSpecializationTypeLoc TL,
5483 NestedNameSpecifierLoc QualifierLoc) {
5484 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005485
Douglas Gregora7a795b2011-03-01 20:11:18 +00005486 TemplateArgumentListInfo NewTemplateArgs;
5487 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5488 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005489
Douglas Gregora7a795b2011-03-01 20:11:18 +00005490 typedef TemplateArgumentLocContainerIterator<
5491 DependentTemplateSpecializationTypeLoc> ArgIterator;
5492 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5493 ArgIterator(TL, TL.getNumArgs()),
5494 NewTemplateArgs))
5495 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005496
Douglas Gregora7a795b2011-03-01 20:11:18 +00005497 QualType Result
5498 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5499 QualifierLoc,
5500 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005501 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005502 NewTemplateArgs);
5503 if (Result.isNull())
5504 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005505
Douglas Gregora7a795b2011-03-01 20:11:18 +00005506 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5507 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005508
Douglas Gregora7a795b2011-03-01 20:11:18 +00005509 // Copy information relevant to the template specialization.
5510 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005511 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005512 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005513 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005514 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5515 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005516 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005517 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005518
Douglas Gregora7a795b2011-03-01 20:11:18 +00005519 // Copy information relevant to the elaborated type.
5520 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005521 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005522 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005523 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5524 DependentTemplateSpecializationTypeLoc SpecTL
5525 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005526 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005527 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005528 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005529 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005530 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5531 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005532 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005533 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005534 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005535 TemplateSpecializationTypeLoc SpecTL
5536 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005537 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005538 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005539 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5540 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005541 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005542 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005543 }
5544 return Result;
5545}
5546
5547template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005548QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5549 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005550 QualType Pattern
5551 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005552 if (Pattern.isNull())
5553 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005554
5555 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005556 if (getDerived().AlwaysRebuild() ||
5557 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005558 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005559 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005560 TL.getEllipsisLoc(),
5561 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005562 if (Result.isNull())
5563 return QualType();
5564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005565
Douglas Gregor822d0302011-01-12 17:07:58 +00005566 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5567 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5568 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005569}
5570
5571template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005572QualType
5573TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005574 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005575 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005576 TLB.pushFullCopy(TL);
5577 return TL.getType();
5578}
5579
5580template<typename Derived>
5581QualType
5582TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005583 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005584 // ObjCObjectType is never dependent.
5585 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005586 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005587}
Mike Stump11289f42009-09-09 15:08:12 +00005588
5589template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005590QualType
5591TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005592 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005593 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005594 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005595 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005596}
5597
Douglas Gregord6ff3322009-08-04 16:50:30 +00005598//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005599// Statement transformation
5600//===----------------------------------------------------------------------===//
5601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005602StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005603TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005604 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005605}
5606
5607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005608StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005609TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5610 return getDerived().TransformCompoundStmt(S, false);
5611}
5612
5613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005614StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005615TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005616 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005617 Sema::CompoundScopeRAII CompoundScope(getSema());
5618
John McCall1ababa62010-08-27 19:56:05 +00005619 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005621 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005622 for (auto *B : S->body()) {
5623 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005624 if (Result.isInvalid()) {
5625 // Immediately fail if this was a DeclStmt, since it's very
5626 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005627 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005628 return StmtError();
5629
5630 // Otherwise, just keep processing substatements and fail later.
5631 SubStmtInvalid = true;
5632 continue;
5633 }
Mike Stump11289f42009-09-09 15:08:12 +00005634
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005635 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005636 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005637 }
Mike Stump11289f42009-09-09 15:08:12 +00005638
John McCall1ababa62010-08-27 19:56:05 +00005639 if (SubStmtInvalid)
5640 return StmtError();
5641
Douglas Gregorebe10102009-08-20 07:17:43 +00005642 if (!getDerived().AlwaysRebuild() &&
5643 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005644 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005645
5646 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005647 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005648 S->getRBracLoc(),
5649 IsStmtExpr);
5650}
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregorebe10102009-08-20 07:17:43 +00005652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005653StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005654TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005655 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005656 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005657 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5658 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005659
Eli Friedman06577382009-11-19 03:14:00 +00005660 // Transform the left-hand case value.
5661 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005662 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005663 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005665
Eli Friedman06577382009-11-19 03:14:00 +00005666 // Transform the right-hand case value (for the GNU case-range extension).
5667 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005668 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005669 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005670 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005671 }
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 // Build the case statement.
5674 // Case statements are always rebuilt so that they will attached to their
5675 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005676 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005677 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005679 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 S->getColonLoc());
5681 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005682 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005685 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005686 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005690 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005691}
5692
5693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005694StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005695TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005697 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005699 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 // Default statements are always rebuilt
5702 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005703 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005704}
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregorebe10102009-08-20 07:17:43 +00005706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005708TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005709 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
Chris Lattnercab02a62011-02-17 20:34:02 +00005713 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5714 S->getDecl());
5715 if (!LD)
5716 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005717
5718
Douglas Gregorebe10102009-08-20 07:17:43 +00005719 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005720 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005721 cast<LabelDecl>(LD), SourceLocation(),
5722 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005723}
Mike Stump11289f42009-09-09 15:08:12 +00005724
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005725template <typename Derived>
5726const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5727 if (!R)
5728 return R;
5729
5730 switch (R->getKind()) {
5731// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5732#define ATTR(X)
5733#define PRAGMA_SPELLING_ATTR(X) \
5734 case attr::X: \
5735 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5736#include "clang/Basic/AttrList.inc"
5737 default:
5738 return R;
5739 }
5740}
5741
5742template <typename Derived>
5743StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5744 bool AttrsChanged = false;
5745 SmallVector<const Attr *, 1> Attrs;
5746
5747 // Visit attributes and keep track if any are transformed.
5748 for (const auto *I : S->getAttrs()) {
5749 const Attr *R = getDerived().TransformAttr(I);
5750 AttrsChanged |= (I != R);
5751 Attrs.push_back(R);
5752 }
5753
Richard Smithc202b282012-04-14 00:33:13 +00005754 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5755 if (SubStmt.isInvalid())
5756 return StmtError();
5757
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005758 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005759 return S;
5760
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005761 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005762 SubStmt.get());
5763}
5764
5765template<typename Derived>
5766StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005767TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005768 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005769 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005770 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005771 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005772 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005773 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005774 getDerived().TransformDefinition(
5775 S->getConditionVariable()->getLocation(),
5776 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005777 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005779 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005780 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005781
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005782 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005783 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005784
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005785 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005786 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005787 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005788 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005789 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005791
John McCallb268a282010-08-23 23:25:46 +00005792 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005793 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005794 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005796 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005797 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005799
Douglas Gregorebe10102009-08-20 07:17:43 +00005800 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005801 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005802 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005803 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregorebe10102009-08-20 07:17:43 +00005805 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005806 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005807 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005808 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005809
Douglas Gregorebe10102009-08-20 07:17:43 +00005810 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005811 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005812 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005813 Then.get() == S->getThen() &&
5814 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005815 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005817 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005818 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005819 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005820}
5821
5822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005823StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005824TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005826 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005827 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005828 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005829 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005830 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005831 getDerived().TransformDefinition(
5832 S->getConditionVariable()->getLocation(),
5833 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005834 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005836 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005837 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005838
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005839 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005841 }
Mike Stump11289f42009-09-09 15:08:12 +00005842
Douglas Gregorebe10102009-08-20 07:17:43 +00005843 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005844 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005845 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005846 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005847 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregorebe10102009-08-20 07:17:43 +00005850 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005851 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005852 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005853 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005854
Douglas Gregorebe10102009-08-20 07:17:43 +00005855 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005856 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5857 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005858}
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregorebe10102009-08-20 07:17:43 +00005860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005861StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005862TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005863 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005864 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005865 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005866 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005867 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005868 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005869 getDerived().TransformDefinition(
5870 S->getConditionVariable()->getLocation(),
5871 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005872 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005874 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005875 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005877 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005879
5880 if (S->getCond()) {
5881 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005882 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5883 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005884 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005885 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005887 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005888 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005889 }
Mike Stump11289f42009-09-09 15:08:12 +00005890
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005891 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005892 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005893 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005894
Douglas Gregorebe10102009-08-20 07:17:43 +00005895 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005896 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005897 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005899
Douglas Gregorebe10102009-08-20 07:17:43 +00005900 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005901 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005902 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005903 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005904 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005906 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005907 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005908}
Mike Stump11289f42009-09-09 15:08:12 +00005909
Douglas Gregorebe10102009-08-20 07:17:43 +00005910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005911StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005912TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005913 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005914 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005915 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005917
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005918 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005919 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005920 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005922
Douglas Gregorebe10102009-08-20 07:17:43 +00005923 if (!getDerived().AlwaysRebuild() &&
5924 Cond.get() == S->getCond() &&
5925 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005926 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005927
John McCallb268a282010-08-23 23:25:46 +00005928 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5929 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005930 S->getRParenLoc());
5931}
Mike Stump11289f42009-09-09 15:08:12 +00005932
Douglas Gregorebe10102009-08-20 07:17:43 +00005933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005934StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005935TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005936 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005937 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005938 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005939 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregorebe10102009-08-20 07:17:43 +00005941 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005942 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005943 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005944 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005945 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005946 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005947 getDerived().TransformDefinition(
5948 S->getConditionVariable()->getLocation(),
5949 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005950 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005951 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005952 } else {
5953 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005954
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005955 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005957
5958 if (S->getCond()) {
5959 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005960 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5961 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005962 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005963 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005965
John McCallb268a282010-08-23 23:25:46 +00005966 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005967 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005968 }
Mike Stump11289f42009-09-09 15:08:12 +00005969
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005970 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005971 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005972 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005973
Douglas Gregorebe10102009-08-20 07:17:43 +00005974 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005975 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005976 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005978
Richard Smith945f8d32013-01-14 22:39:08 +00005979 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005980 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005982
Douglas Gregorebe10102009-08-20 07:17:43 +00005983 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005984 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005985 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005987
Douglas Gregorebe10102009-08-20 07:17:43 +00005988 if (!getDerived().AlwaysRebuild() &&
5989 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005990 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005991 Inc.get() == S->getInc() &&
5992 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005993 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005994
Douglas Gregorebe10102009-08-20 07:17:43 +00005995 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005996 Init.get(), FullCond, ConditionVar,
5997 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005998}
5999
6000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006001StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006002TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006003 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6004 S->getLabel());
6005 if (!LD)
6006 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006009 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006010 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006011}
6012
6013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006014StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006015TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006016 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006017 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006019 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 if (!getDerived().AlwaysRebuild() &&
6022 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006023 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006024
6025 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006026 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006027}
6028
6029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006030StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006031TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006032 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregorebe10102009-08-20 07:17:43 +00006035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006036StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006037TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006038 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006039}
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006042StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006043TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006044 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6045 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006047 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006048
Mike Stump11289f42009-09-09 15:08:12 +00006049 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006050 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006051 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
Mike Stump11289f42009-09-09 15:08:12 +00006053
Douglas Gregorebe10102009-08-20 07:17:43 +00006054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006056TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006057 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006058 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006059 for (auto *D : S->decls()) {
6060 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006061 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006063
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006064 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006065 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006066
Douglas Gregorebe10102009-08-20 07:17:43 +00006067 Decls.push_back(Transformed);
6068 }
Mike Stump11289f42009-09-09 15:08:12 +00006069
Douglas Gregorebe10102009-08-20 07:17:43 +00006070 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006071 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006072
Rafael Espindolaab417692013-07-09 12:05:01 +00006073 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006074}
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregorebe10102009-08-20 07:17:43 +00006076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006077StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006078TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006079
Benjamin Kramerf0623432012-08-23 22:51:59 +00006080 SmallVector<Expr*, 8> Constraints;
6081 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006082 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006083
John McCalldadc5752010-08-24 06:29:42 +00006084 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006085 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006086
6087 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006088
Anders Carlssonaaeef072010-01-24 05:50:09 +00006089 // Go through the outputs.
6090 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006091 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006092
Anders Carlssonaaeef072010-01-24 05:50:09 +00006093 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006094 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006095
Anders Carlssonaaeef072010-01-24 05:50:09 +00006096 // Transform the output expr.
6097 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006098 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006099 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006100 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006101
Anders Carlssonaaeef072010-01-24 05:50:09 +00006102 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006103
John McCallb268a282010-08-23 23:25:46 +00006104 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006105 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006106
Anders Carlssonaaeef072010-01-24 05:50:09 +00006107 // Go through the inputs.
6108 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006109 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006110
Anders Carlssonaaeef072010-01-24 05:50:09 +00006111 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006112 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006113
Anders Carlssonaaeef072010-01-24 05:50:09 +00006114 // Transform the input expr.
6115 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006116 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006117 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006119
Anders Carlssonaaeef072010-01-24 05:50:09 +00006120 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006121
John McCallb268a282010-08-23 23:25:46 +00006122 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006124
Anders Carlssonaaeef072010-01-24 05:50:09 +00006125 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006126 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006127
6128 // Go through the clobbers.
6129 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006130 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006131
6132 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006133 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006134 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6135 S->isVolatile(), S->getNumOutputs(),
6136 S->getNumInputs(), Names.data(),
6137 Constraints, Exprs, AsmString.get(),
6138 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006139}
6140
Chad Rosier32503022012-06-11 20:47:18 +00006141template<typename Derived>
6142StmtResult
6143TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006144 ArrayRef<Token> AsmToks =
6145 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006146
John McCallf413f5e2013-05-03 00:10:13 +00006147 bool HadError = false, HadChange = false;
6148
6149 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6150 SmallVector<Expr*, 8> TransformedExprs;
6151 TransformedExprs.reserve(SrcExprs.size());
6152 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6153 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6154 if (!Result.isUsable()) {
6155 HadError = true;
6156 } else {
6157 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006158 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006159 }
6160 }
6161
6162 if (HadError) return StmtError();
6163 if (!HadChange && !getDerived().AlwaysRebuild())
6164 return Owned(S);
6165
Chad Rosierb6f46c12012-08-15 16:53:30 +00006166 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006167 AsmToks, S->getAsmString(),
6168 S->getNumOutputs(), S->getNumInputs(),
6169 S->getAllConstraints(), S->getClobbers(),
6170 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006171}
Douglas Gregorebe10102009-08-20 07:17:43 +00006172
6173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006174StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006175TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006176 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006177 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006178 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006180
Douglas Gregor96c79492010-04-23 22:50:49 +00006181 // Transform the @catch statements (if present).
6182 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006183 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006184 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006185 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006186 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006188 if (Catch.get() != S->getCatchStmt(I))
6189 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006190 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006192
Douglas Gregor306de2f2010-04-22 23:59:56 +00006193 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006194 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006195 if (S->getFinallyStmt()) {
6196 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6197 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006199 }
6200
6201 // If nothing changed, just retain this statement.
6202 if (!getDerived().AlwaysRebuild() &&
6203 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006204 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006205 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006206 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006207
Douglas Gregor306de2f2010-04-22 23:59:56 +00006208 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006209 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006210 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006211}
Mike Stump11289f42009-09-09 15:08:12 +00006212
Douglas Gregorebe10102009-08-20 07:17:43 +00006213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006214StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006215TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006216 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006217 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006218 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006219 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006220 if (FromVar->getTypeSourceInfo()) {
6221 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6222 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006224 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006225
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006226 QualType T;
6227 if (TSInfo)
6228 T = TSInfo->getType();
6229 else {
6230 T = getDerived().TransformType(FromVar->getType());
6231 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006232 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006233 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006234
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006235 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6236 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006238 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006239
John McCalldadc5752010-08-24 06:29:42 +00006240 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006241 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006242 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006243
6244 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006245 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006246 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006247}
Mike Stump11289f42009-09-09 15:08:12 +00006248
Douglas Gregorebe10102009-08-20 07:17:43 +00006249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006250StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006251TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006252 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006253 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006254 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006255 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006256
Douglas Gregor306de2f2010-04-22 23:59:56 +00006257 // If nothing changed, just retain this statement.
6258 if (!getDerived().AlwaysRebuild() &&
6259 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006260 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006261
6262 // Build a new statement.
6263 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006264 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006265}
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregorebe10102009-08-20 07:17:43 +00006267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006268StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006269TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006270 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006271 if (S->getThrowExpr()) {
6272 Operand = getDerived().TransformExpr(S->getThrowExpr());
6273 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006276
Douglas Gregor2900c162010-04-22 21:44:01 +00006277 if (!getDerived().AlwaysRebuild() &&
6278 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006279 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006280
John McCallb268a282010-08-23 23:25:46 +00006281 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006282}
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregorebe10102009-08-20 07:17:43 +00006284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006285StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006286TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006287 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006288 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006289 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006290 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006292 Object =
6293 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6294 Object.get());
6295 if (Object.isInvalid())
6296 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006297
Douglas Gregor6148de72010-04-22 22:01:21 +00006298 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006299 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006300 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006301 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006302
Douglas Gregor6148de72010-04-22 22:01:21 +00006303 // If nothing change, just retain the current statement.
6304 if (!getDerived().AlwaysRebuild() &&
6305 Object.get() == S->getSynchExpr() &&
6306 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006307 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006308
6309 // Build a new statement.
6310 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006311 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006312}
6313
6314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006315StmtResult
John McCall31168b02011-06-15 23:02:42 +00006316TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6317 ObjCAutoreleasePoolStmt *S) {
6318 // Transform the body.
6319 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6320 if (Body.isInvalid())
6321 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
John McCall31168b02011-06-15 23:02:42 +00006323 // If nothing changed, just retain this statement.
6324 if (!getDerived().AlwaysRebuild() &&
6325 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006326 return S;
John McCall31168b02011-06-15 23:02:42 +00006327
6328 // Build a new statement.
6329 return getDerived().RebuildObjCAutoreleasePoolStmt(
6330 S->getAtLoc(), Body.get());
6331}
6332
6333template<typename Derived>
6334StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006335TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006336 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006337 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006338 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006339 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006340 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006341
Douglas Gregorf68a5082010-04-22 23:10:45 +00006342 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006343 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006344 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006345 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006346
Douglas Gregorf68a5082010-04-22 23:10:45 +00006347 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006348 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006349 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006350 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006351
Douglas Gregorf68a5082010-04-22 23:10:45 +00006352 // If nothing changed, just retain this statement.
6353 if (!getDerived().AlwaysRebuild() &&
6354 Element.get() == S->getElement() &&
6355 Collection.get() == S->getCollection() &&
6356 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006357 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006358
Douglas Gregorf68a5082010-04-22 23:10:45 +00006359 // Build a new statement.
6360 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006361 Element.get(),
6362 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006363 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006364 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006365}
6366
David Majnemer5f7efef2013-10-15 09:50:08 +00006367template <typename Derived>
6368StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006369 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006370 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006371 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6372 TypeSourceInfo *T =
6373 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006374 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006376
David Majnemer5f7efef2013-10-15 09:50:08 +00006377 Var = getDerived().RebuildExceptionDecl(
6378 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6379 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006380 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006381 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006382 }
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregorebe10102009-08-20 07:17:43 +00006384 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006385 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006386 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006387 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006388
David Majnemer5f7efef2013-10-15 09:50:08 +00006389 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006390 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006391 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006392
David Majnemer5f7efef2013-10-15 09:50:08 +00006393 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006394}
Mike Stump11289f42009-09-09 15:08:12 +00006395
David Majnemer5f7efef2013-10-15 09:50:08 +00006396template <typename Derived>
6397StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006398 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006399 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006400 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregorebe10102009-08-20 07:17:43 +00006403 // Transform the handlers.
6404 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006405 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006406 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006407 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006409 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006410
Douglas Gregorebe10102009-08-20 07:17:43 +00006411 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006412 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006413 }
Mike Stump11289f42009-09-09 15:08:12 +00006414
David Majnemer5f7efef2013-10-15 09:50:08 +00006415 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006416 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006417 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006418
John McCallb268a282010-08-23 23:25:46 +00006419 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006420 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006421}
Mike Stump11289f42009-09-09 15:08:12 +00006422
Richard Smith02e85f32011-04-14 22:09:26 +00006423template<typename Derived>
6424StmtResult
6425TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6426 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6427 if (Range.isInvalid())
6428 return StmtError();
6429
6430 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6431 if (BeginEnd.isInvalid())
6432 return StmtError();
6433
6434 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6435 if (Cond.isInvalid())
6436 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006437 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006438 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006439 if (Cond.isInvalid())
6440 return StmtError();
6441 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006442 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006443
6444 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6445 if (Inc.isInvalid())
6446 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006447 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006448 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006449
6450 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6451 if (LoopVar.isInvalid())
6452 return StmtError();
6453
6454 StmtResult NewStmt = S;
6455 if (getDerived().AlwaysRebuild() ||
6456 Range.get() != S->getRangeStmt() ||
6457 BeginEnd.get() != S->getBeginEndStmt() ||
6458 Cond.get() != S->getCond() ||
6459 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006460 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006461 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6462 S->getColonLoc(), Range.get(),
6463 BeginEnd.get(), Cond.get(),
6464 Inc.get(), LoopVar.get(),
6465 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006466 if (NewStmt.isInvalid())
6467 return StmtError();
6468 }
Richard Smith02e85f32011-04-14 22:09:26 +00006469
6470 StmtResult Body = getDerived().TransformStmt(S->getBody());
6471 if (Body.isInvalid())
6472 return StmtError();
6473
6474 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6475 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006476 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006477 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6478 S->getColonLoc(), Range.get(),
6479 BeginEnd.get(), Cond.get(),
6480 Inc.get(), LoopVar.get(),
6481 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006482 if (NewStmt.isInvalid())
6483 return StmtError();
6484 }
Richard Smith02e85f32011-04-14 22:09:26 +00006485
6486 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006487 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006488
6489 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6490}
6491
John Wiegley1c0675e2011-04-28 01:08:34 +00006492template<typename Derived>
6493StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006494TreeTransform<Derived>::TransformMSDependentExistsStmt(
6495 MSDependentExistsStmt *S) {
6496 // Transform the nested-name-specifier, if any.
6497 NestedNameSpecifierLoc QualifierLoc;
6498 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006499 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006500 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6501 if (!QualifierLoc)
6502 return StmtError();
6503 }
6504
6505 // Transform the declaration name.
6506 DeclarationNameInfo NameInfo = S->getNameInfo();
6507 if (NameInfo.getName()) {
6508 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6509 if (!NameInfo.getName())
6510 return StmtError();
6511 }
6512
6513 // Check whether anything changed.
6514 if (!getDerived().AlwaysRebuild() &&
6515 QualifierLoc == S->getQualifierLoc() &&
6516 NameInfo.getName() == S->getNameInfo().getName())
6517 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006518
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006519 // Determine whether this name exists, if we can.
6520 CXXScopeSpec SS;
6521 SS.Adopt(QualifierLoc);
6522 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006523 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006524 case Sema::IER_Exists:
6525 if (S->isIfExists())
6526 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006527
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006528 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6529
6530 case Sema::IER_DoesNotExist:
6531 if (S->isIfNotExists())
6532 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006533
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006534 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006535
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006536 case Sema::IER_Dependent:
6537 Dependent = true;
6538 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006539
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006540 case Sema::IER_Error:
6541 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006543
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006544 // We need to continue with the instantiation, so do so now.
6545 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6546 if (SubStmt.isInvalid())
6547 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006548
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006549 // If we have resolved the name, just transform to the substatement.
6550 if (!Dependent)
6551 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006552
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006553 // The name is still dependent, so build a dependent expression again.
6554 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6555 S->isIfExists(),
6556 QualifierLoc,
6557 NameInfo,
6558 SubStmt.get());
6559}
6560
6561template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006562ExprResult
6563TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6564 NestedNameSpecifierLoc QualifierLoc;
6565 if (E->getQualifierLoc()) {
6566 QualifierLoc
6567 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6568 if (!QualifierLoc)
6569 return ExprError();
6570 }
6571
6572 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6573 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6574 if (!PD)
6575 return ExprError();
6576
6577 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6578 if (Base.isInvalid())
6579 return ExprError();
6580
6581 return new (SemaRef.getASTContext())
6582 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6583 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6584 QualifierLoc, E->getMemberLoc());
6585}
6586
David Majnemerfad8f482013-10-15 09:33:02 +00006587template <typename Derived>
6588StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006589 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006590 if (TryBlock.isInvalid())
6591 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006592
6593 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006594 if (Handler.isInvalid())
6595 return StmtError();
6596
David Majnemerfad8f482013-10-15 09:33:02 +00006597 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6598 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006599 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006600
Warren Huntf6be4cb2014-07-25 20:52:51 +00006601 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6602 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006603}
6604
David Majnemerfad8f482013-10-15 09:33:02 +00006605template <typename Derived>
6606StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006607 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006608 if (Block.isInvalid())
6609 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006610
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006611 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006612}
6613
David Majnemerfad8f482013-10-15 09:33:02 +00006614template <typename Derived>
6615StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006616 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006617 if (FilterExpr.isInvalid())
6618 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006619
David Majnemer7e755502013-10-15 09:30:14 +00006620 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006621 if (Block.isInvalid())
6622 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006623
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006624 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6625 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006626}
6627
David Majnemerfad8f482013-10-15 09:33:02 +00006628template <typename Derived>
6629StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6630 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006631 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6632 else
6633 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6634}
6635
Nico Weber9b982072014-07-07 00:12:30 +00006636template<typename Derived>
6637StmtResult
6638TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6639 return S;
6640}
6641
Alexander Musman64d33f12014-06-04 07:53:32 +00006642//===----------------------------------------------------------------------===//
6643// OpenMP directive transformation
6644//===----------------------------------------------------------------------===//
6645template <typename Derived>
6646StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6647 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006648
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006649 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006650 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006651 ArrayRef<OMPClause *> Clauses = D->clauses();
6652 TClauses.reserve(Clauses.size());
6653 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6654 I != E; ++I) {
6655 if (*I) {
6656 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006657 if (Clause)
6658 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006659 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006660 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006661 }
6662 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006663 StmtResult AssociatedStmt;
6664 if (D->hasAssociatedStmt()) {
6665 if (!D->getAssociatedStmt()) {
6666 return StmtError();
6667 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006668 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6669 /*CurScope=*/nullptr);
6670 StmtResult Body;
6671 {
6672 Sema::CompoundScopeRAII CompoundScope(getSema());
6673 Body = getDerived().TransformStmt(
6674 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6675 }
6676 AssociatedStmt =
6677 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006678 if (AssociatedStmt.isInvalid()) {
6679 return StmtError();
6680 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006681 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006682 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006683 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006684 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006685
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006686 // Transform directive name for 'omp critical' directive.
6687 DeclarationNameInfo DirName;
6688 if (D->getDirectiveKind() == OMPD_critical) {
6689 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6690 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6691 }
6692
Alexander Musman64d33f12014-06-04 07:53:32 +00006693 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006694 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6695 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006696}
6697
Alexander Musman64d33f12014-06-04 07:53:32 +00006698template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006699StmtResult
6700TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6701 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006702 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6703 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006704 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6705 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6706 return Res;
6707}
6708
Alexander Musman64d33f12014-06-04 07:53:32 +00006709template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006710StmtResult
6711TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6712 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006713 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6714 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006715 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6716 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006717 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006718}
6719
Alexey Bataevf29276e2014-06-18 04:14:57 +00006720template <typename Derived>
6721StmtResult
6722TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6723 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006724 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6725 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006726 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6727 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6728 return Res;
6729}
6730
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006731template <typename Derived>
6732StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006733TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6734 DeclarationNameInfo DirName;
6735 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6736 D->getLocStart());
6737 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6738 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6739 return Res;
6740}
6741
6742template <typename Derived>
6743StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006744TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6745 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006746 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6747 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006748 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6749 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6750 return Res;
6751}
6752
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006753template <typename Derived>
6754StmtResult
6755TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6756 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006757 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6758 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006759 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6760 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6761 return Res;
6762}
6763
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006764template <typename Derived>
6765StmtResult
6766TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6767 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006768 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6769 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006770 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6771 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6772 return Res;
6773}
6774
Alexey Bataev4acb8592014-07-07 13:01:15 +00006775template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006776StmtResult
6777TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6778 DeclarationNameInfo DirName;
6779 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6780 D->getLocStart());
6781 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6782 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6783 return Res;
6784}
6785
6786template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006787StmtResult
6788TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6789 getDerived().getSema().StartOpenMPDSABlock(
6790 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6791 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6792 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6793 return Res;
6794}
6795
6796template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006797StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6798 OMPParallelForDirective *D) {
6799 DeclarationNameInfo DirName;
6800 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6801 nullptr, D->getLocStart());
6802 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6803 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6804 return Res;
6805}
6806
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006807template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006808StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6809 OMPParallelForSimdDirective *D) {
6810 DeclarationNameInfo DirName;
6811 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6812 nullptr, D->getLocStart());
6813 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6814 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6815 return Res;
6816}
6817
6818template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006819StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6820 OMPParallelSectionsDirective *D) {
6821 DeclarationNameInfo DirName;
6822 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6823 nullptr, D->getLocStart());
6824 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6825 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6826 return Res;
6827}
6828
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006829template <typename Derived>
6830StmtResult
6831TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6832 DeclarationNameInfo DirName;
6833 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6834 D->getLocStart());
6835 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6836 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6837 return Res;
6838}
6839
Alexey Bataev68446b72014-07-18 07:47:19 +00006840template <typename Derived>
6841StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6842 OMPTaskyieldDirective *D) {
6843 DeclarationNameInfo DirName;
6844 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6845 D->getLocStart());
6846 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6847 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6848 return Res;
6849}
6850
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006851template <typename Derived>
6852StmtResult
6853TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6854 DeclarationNameInfo DirName;
6855 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6856 D->getLocStart());
6857 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6858 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6859 return Res;
6860}
6861
Alexey Bataev2df347a2014-07-18 10:17:07 +00006862template <typename Derived>
6863StmtResult
6864TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6865 DeclarationNameInfo DirName;
6866 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6867 D->getLocStart());
6868 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6869 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6870 return Res;
6871}
6872
Alexey Bataev6125da92014-07-21 11:26:11 +00006873template <typename Derived>
6874StmtResult
6875TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6876 DeclarationNameInfo DirName;
6877 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6878 D->getLocStart());
6879 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6880 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6881 return Res;
6882}
6883
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006884template <typename Derived>
6885StmtResult
6886TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6887 DeclarationNameInfo DirName;
6888 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6889 D->getLocStart());
6890 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6891 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6892 return Res;
6893}
6894
Alexey Bataev0162e452014-07-22 10:10:35 +00006895template <typename Derived>
6896StmtResult
6897TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6898 DeclarationNameInfo DirName;
6899 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6900 D->getLocStart());
6901 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6902 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6903 return Res;
6904}
6905
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006906template <typename Derived>
6907StmtResult
6908TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6909 DeclarationNameInfo DirName;
6910 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6911 D->getLocStart());
6912 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6913 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6914 return Res;
6915}
6916
Alexey Bataev13314bf2014-10-09 04:18:56 +00006917template <typename Derived>
6918StmtResult
6919TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6920 DeclarationNameInfo DirName;
6921 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6922 D->getLocStart());
6923 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6924 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6925 return Res;
6926}
6927
Alexander Musman64d33f12014-06-04 07:53:32 +00006928//===----------------------------------------------------------------------===//
6929// OpenMP clause transformation
6930//===----------------------------------------------------------------------===//
6931template <typename Derived>
6932OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006933 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6934 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006935 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006936 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006937 C->getLParenLoc(), C->getLocEnd());
6938}
6939
Alexander Musman64d33f12014-06-04 07:53:32 +00006940template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006941OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6942 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6943 if (Cond.isInvalid())
6944 return nullptr;
6945 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6946 C->getLParenLoc(), C->getLocEnd());
6947}
6948
6949template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006950OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006951TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6952 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6953 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006954 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006955 return getDerived().RebuildOMPNumThreadsClause(
6956 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006957}
6958
Alexey Bataev62c87d22014-03-21 04:51:18 +00006959template <typename Derived>
6960OMPClause *
6961TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6962 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6963 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006964 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006965 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006966 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006967}
6968
Alexander Musman8bd31e62014-05-27 15:12:19 +00006969template <typename Derived>
6970OMPClause *
6971TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6972 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6973 if (E.isInvalid())
6974 return 0;
6975 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006976 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006977}
6978
Alexander Musman64d33f12014-06-04 07:53:32 +00006979template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006980OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006981TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006982 return getDerived().RebuildOMPDefaultClause(
6983 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6984 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006985}
6986
Alexander Musman64d33f12014-06-04 07:53:32 +00006987template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006988OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006989TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006990 return getDerived().RebuildOMPProcBindClause(
6991 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6992 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006993}
6994
Alexander Musman64d33f12014-06-04 07:53:32 +00006995template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006996OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006997TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6998 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6999 if (E.isInvalid())
7000 return nullptr;
7001 return getDerived().RebuildOMPScheduleClause(
7002 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7003 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7004}
7005
7006template <typename Derived>
7007OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007008TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7009 // No need to rebuild this clause, no template-dependent parameters.
7010 return C;
7011}
7012
7013template <typename Derived>
7014OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007015TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7016 // No need to rebuild this clause, no template-dependent parameters.
7017 return C;
7018}
7019
7020template <typename Derived>
7021OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007022TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7023 // No need to rebuild this clause, no template-dependent parameters.
7024 return C;
7025}
7026
7027template <typename Derived>
7028OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007029TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7030 // No need to rebuild this clause, no template-dependent parameters.
7031 return C;
7032}
7033
7034template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007035OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7036 // No need to rebuild this clause, no template-dependent parameters.
7037 return C;
7038}
7039
7040template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007041OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7042 // No need to rebuild this clause, no template-dependent parameters.
7043 return C;
7044}
7045
7046template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007047OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007048TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7049 // No need to rebuild this clause, no template-dependent parameters.
7050 return C;
7051}
7052
7053template <typename Derived>
7054OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007055TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7056 // No need to rebuild this clause, no template-dependent parameters.
7057 return C;
7058}
7059
7060template <typename Derived>
7061OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007062TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7063 // No need to rebuild this clause, no template-dependent parameters.
7064 return C;
7065}
7066
7067template <typename Derived>
7068OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007069TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007070 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007071 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007072 for (auto *VE : C->varlists()) {
7073 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007074 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007075 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007076 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007077 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007078 return getDerived().RebuildOMPPrivateClause(
7079 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007080}
7081
Alexander Musman64d33f12014-06-04 07:53:32 +00007082template <typename Derived>
7083OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7084 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007085 llvm::SmallVector<Expr *, 16> Vars;
7086 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007087 for (auto *VE : C->varlists()) {
7088 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007089 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007090 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007091 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007092 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007093 return getDerived().RebuildOMPFirstprivateClause(
7094 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007095}
7096
Alexander Musman64d33f12014-06-04 07:53:32 +00007097template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007098OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007099TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7100 llvm::SmallVector<Expr *, 16> Vars;
7101 Vars.reserve(C->varlist_size());
7102 for (auto *VE : C->varlists()) {
7103 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7104 if (EVar.isInvalid())
7105 return nullptr;
7106 Vars.push_back(EVar.get());
7107 }
7108 return getDerived().RebuildOMPLastprivateClause(
7109 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7110}
7111
7112template <typename Derived>
7113OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007114TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7115 llvm::SmallVector<Expr *, 16> Vars;
7116 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007117 for (auto *VE : C->varlists()) {
7118 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007119 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007120 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007121 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007122 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007123 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7124 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007125}
7126
Alexander Musman64d33f12014-06-04 07:53:32 +00007127template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007128OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007129TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7130 llvm::SmallVector<Expr *, 16> Vars;
7131 Vars.reserve(C->varlist_size());
7132 for (auto *VE : C->varlists()) {
7133 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7134 if (EVar.isInvalid())
7135 return nullptr;
7136 Vars.push_back(EVar.get());
7137 }
7138 CXXScopeSpec ReductionIdScopeSpec;
7139 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7140
7141 DeclarationNameInfo NameInfo = C->getNameInfo();
7142 if (NameInfo.getName()) {
7143 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7144 if (!NameInfo.getName())
7145 return nullptr;
7146 }
7147 return getDerived().RebuildOMPReductionClause(
7148 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7149 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7150}
7151
7152template <typename Derived>
7153OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007154TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7155 llvm::SmallVector<Expr *, 16> Vars;
7156 Vars.reserve(C->varlist_size());
7157 for (auto *VE : C->varlists()) {
7158 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7159 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007160 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007161 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007162 }
7163 ExprResult Step = getDerived().TransformExpr(C->getStep());
7164 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007165 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007166 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7167 C->getLParenLoc(),
7168 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007169}
7170
Alexander Musman64d33f12014-06-04 07:53:32 +00007171template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007172OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007173TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7174 llvm::SmallVector<Expr *, 16> Vars;
7175 Vars.reserve(C->varlist_size());
7176 for (auto *VE : C->varlists()) {
7177 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7178 if (EVar.isInvalid())
7179 return nullptr;
7180 Vars.push_back(EVar.get());
7181 }
7182 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7183 if (Alignment.isInvalid())
7184 return nullptr;
7185 return getDerived().RebuildOMPAlignedClause(
7186 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7187 C->getColonLoc(), C->getLocEnd());
7188}
7189
Alexander Musman64d33f12014-06-04 07:53:32 +00007190template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007191OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007192TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7193 llvm::SmallVector<Expr *, 16> Vars;
7194 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007195 for (auto *VE : C->varlists()) {
7196 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007197 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007198 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007199 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007200 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007201 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7202 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007203}
7204
Alexey Bataevbae9a792014-06-27 10:37:06 +00007205template <typename Derived>
7206OMPClause *
7207TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7208 llvm::SmallVector<Expr *, 16> Vars;
7209 Vars.reserve(C->varlist_size());
7210 for (auto *VE : C->varlists()) {
7211 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7212 if (EVar.isInvalid())
7213 return nullptr;
7214 Vars.push_back(EVar.get());
7215 }
7216 return getDerived().RebuildOMPCopyprivateClause(
7217 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7218}
7219
Alexey Bataev6125da92014-07-21 11:26:11 +00007220template <typename Derived>
7221OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7222 llvm::SmallVector<Expr *, 16> Vars;
7223 Vars.reserve(C->varlist_size());
7224 for (auto *VE : C->varlists()) {
7225 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7226 if (EVar.isInvalid())
7227 return nullptr;
7228 Vars.push_back(EVar.get());
7229 }
7230 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7231 C->getLParenLoc(), C->getLocEnd());
7232}
7233
Douglas Gregorebe10102009-08-20 07:17:43 +00007234//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007235// Expression transformation
7236//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007239TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007240 if (!E->isTypeDependent())
7241 return E;
7242
7243 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7244 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007245}
Mike Stump11289f42009-09-09 15:08:12 +00007246
7247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007249TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007250 NestedNameSpecifierLoc QualifierLoc;
7251 if (E->getQualifierLoc()) {
7252 QualifierLoc
7253 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7254 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007255 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007256 }
John McCallce546572009-12-08 09:08:17 +00007257
7258 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007259 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7260 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007261 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007262 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007263
John McCall815039a2010-08-17 21:27:17 +00007264 DeclarationNameInfo NameInfo = E->getNameInfo();
7265 if (NameInfo.getName()) {
7266 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7267 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007268 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007269 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007270
7271 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007272 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007273 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007274 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007275 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007276
7277 // Mark it referenced in the new context regardless.
7278 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007279 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007280
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007281 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007282 }
John McCallce546572009-12-08 09:08:17 +00007283
Craig Topperc3ec1492014-05-26 06:22:03 +00007284 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007285 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007286 TemplateArgs = &TransArgs;
7287 TransArgs.setLAngleLoc(E->getLAngleLoc());
7288 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007289 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7290 E->getNumTemplateArgs(),
7291 TransArgs))
7292 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007293 }
7294
Chad Rosier1dcde962012-08-08 18:46:20 +00007295 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007296 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007297}
Mike Stump11289f42009-09-09 15:08:12 +00007298
Douglas Gregora16548e2009-08-11 05:31:07 +00007299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007300ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007301TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007302 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007303}
Mike Stump11289f42009-09-09 15:08:12 +00007304
Douglas Gregora16548e2009-08-11 05:31:07 +00007305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007307TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007308 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007309}
Mike Stump11289f42009-09-09 15:08:12 +00007310
Douglas Gregora16548e2009-08-11 05:31:07 +00007311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007313TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007314 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007315}
Mike Stump11289f42009-09-09 15:08:12 +00007316
Douglas Gregora16548e2009-08-11 05:31:07 +00007317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007319TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007320 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007321}
Mike Stump11289f42009-09-09 15:08:12 +00007322
Douglas Gregora16548e2009-08-11 05:31:07 +00007323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007325TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007326 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007327}
7328
7329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007330ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007331TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007332 if (FunctionDecl *FD = E->getDirectCallee())
7333 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007334 return SemaRef.MaybeBindToTemporary(E);
7335}
7336
7337template<typename Derived>
7338ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007339TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7340 ExprResult ControllingExpr =
7341 getDerived().TransformExpr(E->getControllingExpr());
7342 if (ControllingExpr.isInvalid())
7343 return ExprError();
7344
Chris Lattner01cf8db2011-07-20 06:58:45 +00007345 SmallVector<Expr *, 4> AssocExprs;
7346 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007347 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7348 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7349 if (TS) {
7350 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7351 if (!AssocType)
7352 return ExprError();
7353 AssocTypes.push_back(AssocType);
7354 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007355 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007356 }
7357
7358 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7359 if (AssocExpr.isInvalid())
7360 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007361 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007362 }
7363
7364 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7365 E->getDefaultLoc(),
7366 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007367 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007368 AssocTypes,
7369 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007370}
7371
7372template<typename Derived>
7373ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007374TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007375 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007378
Douglas Gregora16548e2009-08-11 05:31:07 +00007379 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007380 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007381
John McCallb268a282010-08-23 23:25:46 +00007382 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007383 E->getRParen());
7384}
7385
Richard Smithdb2630f2012-10-21 03:28:35 +00007386/// \brief The operand of a unary address-of operator has special rules: it's
7387/// allowed to refer to a non-static member of a class even if there's no 'this'
7388/// object available.
7389template<typename Derived>
7390ExprResult
7391TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7392 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007393 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007394 else
7395 return getDerived().TransformExpr(E);
7396}
7397
Mike Stump11289f42009-09-09 15:08:12 +00007398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007400TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007401 ExprResult SubExpr;
7402 if (E->getOpcode() == UO_AddrOf)
7403 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7404 else
7405 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007406 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007408
Douglas Gregora16548e2009-08-11 05:31:07 +00007409 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007410 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007411
Douglas Gregora16548e2009-08-11 05:31:07 +00007412 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7413 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007414 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007415}
Mike Stump11289f42009-09-09 15:08:12 +00007416
Douglas Gregora16548e2009-08-11 05:31:07 +00007417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007418ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007419TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7420 // Transform the type.
7421 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7422 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007423 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007424
Douglas Gregor882211c2010-04-28 22:16:22 +00007425 // Transform all of the components into components similar to what the
7426 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007427 // FIXME: It would be slightly more efficient in the non-dependent case to
7428 // just map FieldDecls, rather than requiring the rebuilder to look for
7429 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007430 // template code that we don't care.
7431 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007432 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007433 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007434 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007435 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7436 const Node &ON = E->getComponent(I);
7437 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007438 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007439 Comp.LocStart = ON.getSourceRange().getBegin();
7440 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007441 switch (ON.getKind()) {
7442 case Node::Array: {
7443 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007444 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007445 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007446 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007447
Douglas Gregor882211c2010-04-28 22:16:22 +00007448 ExprChanged = ExprChanged || Index.get() != FromIndex;
7449 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007450 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007451 break;
7452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007453
Douglas Gregor882211c2010-04-28 22:16:22 +00007454 case Node::Field:
7455 case Node::Identifier:
7456 Comp.isBrackets = false;
7457 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007458 if (!Comp.U.IdentInfo)
7459 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007460
Douglas Gregor882211c2010-04-28 22:16:22 +00007461 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007462
Douglas Gregord1702062010-04-29 00:18:15 +00007463 case Node::Base:
7464 // Will be recomputed during the rebuild.
7465 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007467
Douglas Gregor882211c2010-04-28 22:16:22 +00007468 Components.push_back(Comp);
7469 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007470
Douglas Gregor882211c2010-04-28 22:16:22 +00007471 // If nothing changed, retain the existing expression.
7472 if (!getDerived().AlwaysRebuild() &&
7473 Type == E->getTypeSourceInfo() &&
7474 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007475 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007476
Douglas Gregor882211c2010-04-28 22:16:22 +00007477 // Build a new offsetof expression.
7478 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7479 Components.data(), Components.size(),
7480 E->getRParenLoc());
7481}
7482
7483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007484ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007485TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7486 assert(getDerived().AlreadyTransformed(E->getType()) &&
7487 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007488 return E;
John McCall8d69a212010-11-15 23:31:06 +00007489}
7490
7491template<typename Derived>
7492ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007493TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7494 return E;
7495}
7496
7497template<typename Derived>
7498ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007499TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007500 // Rebuild the syntactic form. The original syntactic form has
7501 // opaque-value expressions in it, so strip those away and rebuild
7502 // the result. This is a really awful way of doing this, but the
7503 // better solution (rebuilding the semantic expressions and
7504 // rebinding OVEs as necessary) doesn't work; we'd need
7505 // TreeTransform to not strip away implicit conversions.
7506 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7507 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007508 if (result.isInvalid()) return ExprError();
7509
7510 // If that gives us a pseudo-object result back, the pseudo-object
7511 // expression must have been an lvalue-to-rvalue conversion which we
7512 // should reapply.
7513 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007514 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007515
7516 return result;
7517}
7518
7519template<typename Derived>
7520ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007521TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7522 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007523 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007524 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007525
John McCallbcd03502009-12-07 02:54:59 +00007526 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007527 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007529
John McCall4c98fd82009-11-04 07:28:41 +00007530 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007531 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007532
Peter Collingbournee190dee2011-03-11 19:24:49 +00007533 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7534 E->getKind(),
7535 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007536 }
Mike Stump11289f42009-09-09 15:08:12 +00007537
Eli Friedmane4f22df2012-02-29 04:03:55 +00007538 // C++0x [expr.sizeof]p1:
7539 // The operand is either an expression, which is an unevaluated operand
7540 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007541 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7542 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007543
Reid Kleckner32506ed2014-06-12 23:03:48 +00007544 // Try to recover if we have something like sizeof(T::X) where X is a type.
7545 // Notably, there must be *exactly* one set of parens if X is a type.
7546 TypeSourceInfo *RecoveryTSI = nullptr;
7547 ExprResult SubExpr;
7548 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7549 if (auto *DRE =
7550 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7551 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7552 PE, DRE, false, &RecoveryTSI);
7553 else
7554 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7555
7556 if (RecoveryTSI) {
7557 return getDerived().RebuildUnaryExprOrTypeTrait(
7558 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7559 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007561
Eli Friedmane4f22df2012-02-29 04:03:55 +00007562 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007563 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007564
Peter Collingbournee190dee2011-03-11 19:24:49 +00007565 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7566 E->getOperatorLoc(),
7567 E->getKind(),
7568 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007569}
Mike Stump11289f42009-09-09 15:08:12 +00007570
Douglas Gregora16548e2009-08-11 05:31:07 +00007571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007573TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007574 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007575 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007577
John McCalldadc5752010-08-24 06:29:42 +00007578 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007579 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007581
7582
Douglas Gregora16548e2009-08-11 05:31:07 +00007583 if (!getDerived().AlwaysRebuild() &&
7584 LHS.get() == E->getLHS() &&
7585 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007586 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007587
John McCallb268a282010-08-23 23:25:46 +00007588 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007590 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007591 E->getRBracketLoc());
7592}
Mike Stump11289f42009-09-09 15:08:12 +00007593
7594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007596TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007597 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007598 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007599 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007600 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007601
7602 // Transform arguments.
7603 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007604 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007605 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007606 &ArgChanged))
7607 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007608
Douglas Gregora16548e2009-08-11 05:31:07 +00007609 if (!getDerived().AlwaysRebuild() &&
7610 Callee.get() == E->getCallee() &&
7611 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007612 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007613
Douglas Gregora16548e2009-08-11 05:31:07 +00007614 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007615 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007616 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007617 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007618 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007619 E->getRParenLoc());
7620}
Mike Stump11289f42009-09-09 15:08:12 +00007621
7622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007624TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007625 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007626 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007627 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007628
Douglas Gregorea972d32011-02-28 21:54:11 +00007629 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007630 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007631 QualifierLoc
7632 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007633
Douglas Gregorea972d32011-02-28 21:54:11 +00007634 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007635 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007636 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007637 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007638
Eli Friedman2cfcef62009-12-04 06:40:45 +00007639 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007640 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7641 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007642 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007644
John McCall16df1e52010-03-30 21:47:33 +00007645 NamedDecl *FoundDecl = E->getFoundDecl();
7646 if (FoundDecl == E->getMemberDecl()) {
7647 FoundDecl = Member;
7648 } else {
7649 FoundDecl = cast_or_null<NamedDecl>(
7650 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7651 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007652 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007653 }
7654
Douglas Gregora16548e2009-08-11 05:31:07 +00007655 if (!getDerived().AlwaysRebuild() &&
7656 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007657 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007658 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007659 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007660 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007661
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007662 // Mark it referenced in the new context regardless.
7663 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007664 SemaRef.MarkMemberReferenced(E);
7665
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007666 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007667 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007668
John McCall6b51f282009-11-23 01:53:49 +00007669 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007670 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007671 TransArgs.setLAngleLoc(E->getLAngleLoc());
7672 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007673 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7674 E->getNumTemplateArgs(),
7675 TransArgs))
7676 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007677 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007678
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007680 SourceLocation FakeOperatorLoc =
7681 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007682
John McCall38836f02010-01-15 08:34:02 +00007683 // FIXME: to do this check properly, we will need to preserve the
7684 // first-qualifier-in-scope here, just in case we had a dependent
7685 // base (and therefore couldn't do the check) and a
7686 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007687 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007688
John McCallb268a282010-08-23 23:25:46 +00007689 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007690 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007691 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007692 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007693 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007694 Member,
John McCall16df1e52010-03-30 21:47:33 +00007695 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007696 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007697 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007698 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007699}
Mike Stump11289f42009-09-09 15:08:12 +00007700
Douglas Gregora16548e2009-08-11 05:31:07 +00007701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007702ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007703TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007704 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007705 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007707
John McCalldadc5752010-08-24 06:29:42 +00007708 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007709 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007711
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 if (!getDerived().AlwaysRebuild() &&
7713 LHS.get() == E->getLHS() &&
7714 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007715 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007716
Lang Hames5de91cc2012-10-02 04:45:10 +00007717 Sema::FPContractStateRAII FPContractState(getSema());
7718 getSema().FPFeatures.fp_contract = E->isFPContractable();
7719
Douglas Gregora16548e2009-08-11 05:31:07 +00007720 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007721 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007722}
7723
Mike Stump11289f42009-09-09 15:08:12 +00007724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007725ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007726TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007727 CompoundAssignOperator *E) {
7728 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007729}
Mike Stump11289f42009-09-09 15:08:12 +00007730
Douglas Gregora16548e2009-08-11 05:31:07 +00007731template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007732ExprResult TreeTransform<Derived>::
7733TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7734 // Just rebuild the common and RHS expressions and see whether we
7735 // get any changes.
7736
7737 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7738 if (commonExpr.isInvalid())
7739 return ExprError();
7740
7741 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7742 if (rhs.isInvalid())
7743 return ExprError();
7744
7745 if (!getDerived().AlwaysRebuild() &&
7746 commonExpr.get() == e->getCommon() &&
7747 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007748 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007749
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007750 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007751 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007752 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007753 e->getColonLoc(),
7754 rhs.get());
7755}
7756
7757template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007758ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007759TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007760 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007761 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007762 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007763
John McCalldadc5752010-08-24 06:29:42 +00007764 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007765 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007767
John McCalldadc5752010-08-24 06:29:42 +00007768 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007769 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007771
Douglas Gregora16548e2009-08-11 05:31:07 +00007772 if (!getDerived().AlwaysRebuild() &&
7773 Cond.get() == E->getCond() &&
7774 LHS.get() == E->getLHS() &&
7775 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007776 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007777
John McCallb268a282010-08-23 23:25:46 +00007778 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007779 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007780 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007781 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007782 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007783}
Mike Stump11289f42009-09-09 15:08:12 +00007784
7785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007787TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007788 // Implicit casts are eliminated during transformation, since they
7789 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007790 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007791}
Mike Stump11289f42009-09-09 15:08:12 +00007792
Douglas Gregora16548e2009-08-11 05:31:07 +00007793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007795TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007796 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7797 if (!Type)
7798 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007799
John McCalldadc5752010-08-24 06:29:42 +00007800 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007801 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007802 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007804
Douglas Gregora16548e2009-08-11 05:31:07 +00007805 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007806 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007807 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007808 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007809
John McCall97513962010-01-15 18:39:57 +00007810 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007811 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007812 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007813 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007814}
Mike Stump11289f42009-09-09 15:08:12 +00007815
Douglas Gregora16548e2009-08-11 05:31:07 +00007816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007817ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007818TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007819 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7820 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7821 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007823
John McCalldadc5752010-08-24 06:29:42 +00007824 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007825 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007827
Douglas Gregora16548e2009-08-11 05:31:07 +00007828 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007829 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007830 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007831 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007832
John McCall5d7aa7f2010-01-19 22:33:45 +00007833 // Note: the expression type doesn't necessarily match the
7834 // type-as-written, but that's okay, because it should always be
7835 // derivable from the initializer.
7836
John McCalle15bbff2010-01-18 19:35:47 +00007837 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007838 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007839 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007840}
Mike Stump11289f42009-09-09 15:08:12 +00007841
Douglas Gregora16548e2009-08-11 05:31:07 +00007842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007844TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007845 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007846 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007848
Douglas Gregora16548e2009-08-11 05:31:07 +00007849 if (!getDerived().AlwaysRebuild() &&
7850 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007851 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007852
Douglas Gregora16548e2009-08-11 05:31:07 +00007853 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007854 SourceLocation FakeOperatorLoc =
7855 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007856 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007857 E->getAccessorLoc(),
7858 E->getAccessor());
7859}
Mike Stump11289f42009-09-09 15:08:12 +00007860
Douglas Gregora16548e2009-08-11 05:31:07 +00007861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007862ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007863TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00007864 if (InitListExpr *Syntactic = E->getSyntacticForm())
7865 E = Syntactic;
7866
Douglas Gregora16548e2009-08-11 05:31:07 +00007867 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007868
Benjamin Kramerf0623432012-08-23 22:51:59 +00007869 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007870 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007871 Inits, &InitChanged))
7872 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007873
Richard Smith520449d2015-02-05 06:15:50 +00007874 if (!getDerived().AlwaysRebuild() && !InitChanged) {
7875 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
7876 // in some cases. We can't reuse it in general, because the syntactic and
7877 // semantic forms are linked, and we can't know that semantic form will
7878 // match even if the syntactic form does.
7879 }
Mike Stump11289f42009-09-09 15:08:12 +00007880
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007881 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007882 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007883}
Mike Stump11289f42009-09-09 15:08:12 +00007884
Douglas Gregora16548e2009-08-11 05:31:07 +00007885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007887TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007888 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007889
Douglas Gregorebe10102009-08-20 07:17:43 +00007890 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007891 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007892 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007894
Douglas Gregorebe10102009-08-20 07:17:43 +00007895 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007896 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007897 bool ExprChanged = false;
7898 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7899 DEnd = E->designators_end();
7900 D != DEnd; ++D) {
7901 if (D->isFieldDesignator()) {
7902 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7903 D->getDotLoc(),
7904 D->getFieldLoc()));
7905 continue;
7906 }
Mike Stump11289f42009-09-09 15:08:12 +00007907
Douglas Gregora16548e2009-08-11 05:31:07 +00007908 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007909 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007910 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007912
7913 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007914 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007915
Douglas Gregora16548e2009-08-11 05:31:07 +00007916 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007917 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007918 continue;
7919 }
Mike Stump11289f42009-09-09 15:08:12 +00007920
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007922 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007923 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7924 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007926
John McCalldadc5752010-08-24 06:29:42 +00007927 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007928 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007930
7931 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007932 End.get(),
7933 D->getLBracketLoc(),
7934 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007935
Douglas Gregora16548e2009-08-11 05:31:07 +00007936 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7937 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007938
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007939 ArrayExprs.push_back(Start.get());
7940 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007941 }
Mike Stump11289f42009-09-09 15:08:12 +00007942
Douglas Gregora16548e2009-08-11 05:31:07 +00007943 if (!getDerived().AlwaysRebuild() &&
7944 Init.get() == E->getInit() &&
7945 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007946 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007947
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007948 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007949 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007950 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007951}
Mike Stump11289f42009-09-09 15:08:12 +00007952
Douglas Gregora16548e2009-08-11 05:31:07 +00007953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007954ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007955TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007956 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007957 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007958
Douglas Gregor3da3c062009-10-28 00:29:27 +00007959 // FIXME: Will we ever have proper type location here? Will we actually
7960 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007961 QualType T = getDerived().TransformType(E->getType());
7962 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007964
Douglas Gregora16548e2009-08-11 05:31:07 +00007965 if (!getDerived().AlwaysRebuild() &&
7966 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007967 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007968
Douglas Gregora16548e2009-08-11 05:31:07 +00007969 return getDerived().RebuildImplicitValueInitExpr(T);
7970}
Mike Stump11289f42009-09-09 15:08:12 +00007971
Douglas Gregora16548e2009-08-11 05:31:07 +00007972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007973ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007974TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007975 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7976 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007978
John McCalldadc5752010-08-24 06:29:42 +00007979 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007980 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007982
Douglas Gregora16548e2009-08-11 05:31:07 +00007983 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007984 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007985 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007986 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007987
John McCallb268a282010-08-23 23:25:46 +00007988 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007989 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007990}
7991
7992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007993ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007994TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007995 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007996 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007997 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7998 &ArgumentChanged))
7999 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008000
Douglas Gregora16548e2009-08-11 05:31:07 +00008001 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008002 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008003 E->getRParenLoc());
8004}
Mike Stump11289f42009-09-09 15:08:12 +00008005
Douglas Gregora16548e2009-08-11 05:31:07 +00008006/// \brief Transform an address-of-label expression.
8007///
8008/// By default, the transformation of an address-of-label expression always
8009/// rebuilds the expression, so that the label identifier can be resolved to
8010/// the corresponding label statement by semantic analysis.
8011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008012ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008013TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008014 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8015 E->getLabel());
8016 if (!LD)
8017 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008018
Douglas Gregora16548e2009-08-11 05:31:07 +00008019 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008020 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008021}
Mike Stump11289f42009-09-09 15:08:12 +00008022
8023template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008024ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008025TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008026 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008027 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008028 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008029 if (SubStmt.isInvalid()) {
8030 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008031 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008032 }
Mike Stump11289f42009-09-09 15:08:12 +00008033
Douglas Gregora16548e2009-08-11 05:31:07 +00008034 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008035 SubStmt.get() == E->getSubStmt()) {
8036 // Calling this an 'error' is unintuitive, but it does the right thing.
8037 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008038 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008039 }
Mike Stump11289f42009-09-09 15:08:12 +00008040
8041 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008042 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008043 E->getRParenLoc());
8044}
Mike Stump11289f42009-09-09 15:08:12 +00008045
Douglas Gregora16548e2009-08-11 05:31:07 +00008046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008048TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008049 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008050 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008052
John McCalldadc5752010-08-24 06:29:42 +00008053 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008054 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008055 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008056
John McCalldadc5752010-08-24 06:29:42 +00008057 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008058 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008060
Douglas Gregora16548e2009-08-11 05:31:07 +00008061 if (!getDerived().AlwaysRebuild() &&
8062 Cond.get() == E->getCond() &&
8063 LHS.get() == E->getLHS() &&
8064 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008065 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008066
Douglas Gregora16548e2009-08-11 05:31:07 +00008067 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008068 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008069 E->getRParenLoc());
8070}
Mike Stump11289f42009-09-09 15:08:12 +00008071
Douglas Gregora16548e2009-08-11 05:31:07 +00008072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008074TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008075 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008076}
8077
8078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008080TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008081 switch (E->getOperator()) {
8082 case OO_New:
8083 case OO_Delete:
8084 case OO_Array_New:
8085 case OO_Array_Delete:
8086 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008087
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008088 case OO_Call: {
8089 // This is a call to an object's operator().
8090 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8091
8092 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008093 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008094 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008095 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008096
8097 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008098 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8099 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008100
8101 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008102 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008103 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008104 Args))
8105 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008106
John McCallb268a282010-08-23 23:25:46 +00008107 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008108 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008109 E->getLocEnd());
8110 }
8111
8112#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8113 case OO_##Name:
8114#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8115#include "clang/Basic/OperatorKinds.def"
8116 case OO_Subscript:
8117 // Handled below.
8118 break;
8119
8120 case OO_Conditional:
8121 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008122
8123 case OO_None:
8124 case NUM_OVERLOADED_OPERATORS:
8125 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008126 }
8127
John McCalldadc5752010-08-24 06:29:42 +00008128 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008129 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008131
Richard Smithdb2630f2012-10-21 03:28:35 +00008132 ExprResult First;
8133 if (E->getOperator() == OO_Amp)
8134 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8135 else
8136 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008138 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008139
John McCalldadc5752010-08-24 06:29:42 +00008140 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008141 if (E->getNumArgs() == 2) {
8142 Second = getDerived().TransformExpr(E->getArg(1));
8143 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008144 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008145 }
Mike Stump11289f42009-09-09 15:08:12 +00008146
Douglas Gregora16548e2009-08-11 05:31:07 +00008147 if (!getDerived().AlwaysRebuild() &&
8148 Callee.get() == E->getCallee() &&
8149 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008150 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008151 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008152
Lang Hames5de91cc2012-10-02 04:45:10 +00008153 Sema::FPContractStateRAII FPContractState(getSema());
8154 getSema().FPFeatures.fp_contract = E->isFPContractable();
8155
Douglas Gregora16548e2009-08-11 05:31:07 +00008156 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8157 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008158 Callee.get(),
8159 First.get(),
8160 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008161}
Mike Stump11289f42009-09-09 15:08:12 +00008162
Douglas Gregora16548e2009-08-11 05:31:07 +00008163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008165TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8166 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008167}
Mike Stump11289f42009-09-09 15:08:12 +00008168
Douglas Gregora16548e2009-08-11 05:31:07 +00008169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008170ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008171TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8172 // Transform the callee.
8173 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8174 if (Callee.isInvalid())
8175 return ExprError();
8176
8177 // Transform exec config.
8178 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8179 if (EC.isInvalid())
8180 return ExprError();
8181
8182 // Transform arguments.
8183 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008184 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008185 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008186 &ArgChanged))
8187 return ExprError();
8188
8189 if (!getDerived().AlwaysRebuild() &&
8190 Callee.get() == E->getCallee() &&
8191 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008192 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008193
8194 // FIXME: Wrong source location information for the '('.
8195 SourceLocation FakeLParenLoc
8196 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8197 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008198 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008199 E->getRParenLoc(), EC.get());
8200}
8201
8202template<typename Derived>
8203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008204TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008205 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8206 if (!Type)
8207 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008208
John McCalldadc5752010-08-24 06:29:42 +00008209 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008210 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008211 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008213
Douglas Gregora16548e2009-08-11 05:31:07 +00008214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008215 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008216 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008217 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008218 return getDerived().RebuildCXXNamedCastExpr(
8219 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8220 Type, E->getAngleBrackets().getEnd(),
8221 // FIXME. this should be '(' location
8222 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008223}
Mike Stump11289f42009-09-09 15:08:12 +00008224
Douglas Gregora16548e2009-08-11 05:31:07 +00008225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008227TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8228 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008229}
Mike Stump11289f42009-09-09 15:08:12 +00008230
8231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008233TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8234 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008235}
8236
Douglas Gregora16548e2009-08-11 05:31:07 +00008237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008238ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008239TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008240 CXXReinterpretCastExpr *E) {
8241 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008242}
Mike Stump11289f42009-09-09 15:08:12 +00008243
Douglas Gregora16548e2009-08-11 05:31:07 +00008244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008245ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008246TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8247 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008248}
Mike Stump11289f42009-09-09 15:08:12 +00008249
Douglas Gregora16548e2009-08-11 05:31:07 +00008250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008251ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008252TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008253 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008254 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8255 if (!Type)
8256 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008257
John McCalldadc5752010-08-24 06:29:42 +00008258 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008259 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008260 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008261 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008262
Douglas Gregora16548e2009-08-11 05:31:07 +00008263 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008264 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008265 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008266 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008267
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008268 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008269 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008270 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008271 E->getRParenLoc());
8272}
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008275ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008276TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008277 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008278 TypeSourceInfo *TInfo
8279 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8280 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008282
Douglas Gregora16548e2009-08-11 05:31:07 +00008283 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008284 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008285 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008286
Douglas Gregor9da64192010-04-26 22:37:10 +00008287 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8288 E->getLocStart(),
8289 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008290 E->getLocEnd());
8291 }
Mike Stump11289f42009-09-09 15:08:12 +00008292
Eli Friedman456f0182012-01-20 01:26:23 +00008293 // We don't know whether the subexpression is potentially evaluated until
8294 // after we perform semantic analysis. We speculatively assume it is
8295 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008297 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8298 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008299
John McCalldadc5752010-08-24 06:29:42 +00008300 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008301 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008303
Douglas Gregora16548e2009-08-11 05:31:07 +00008304 if (!getDerived().AlwaysRebuild() &&
8305 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008306 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008307
Douglas Gregor9da64192010-04-26 22:37:10 +00008308 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8309 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008310 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 E->getLocEnd());
8312}
8313
8314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008315ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008316TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8317 if (E->isTypeOperand()) {
8318 TypeSourceInfo *TInfo
8319 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8320 if (!TInfo)
8321 return ExprError();
8322
8323 if (!getDerived().AlwaysRebuild() &&
8324 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008325 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008326
Douglas Gregor69735112011-03-06 17:40:41 +00008327 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008328 E->getLocStart(),
8329 TInfo,
8330 E->getLocEnd());
8331 }
8332
Francois Pichet9f4f2072010-09-08 12:20:18 +00008333 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8334
8335 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8336 if (SubExpr.isInvalid())
8337 return ExprError();
8338
8339 if (!getDerived().AlwaysRebuild() &&
8340 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008341 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008342
8343 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8344 E->getLocStart(),
8345 SubExpr.get(),
8346 E->getLocEnd());
8347}
8348
8349template<typename Derived>
8350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008351TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008352 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008353}
Mike Stump11289f42009-09-09 15:08:12 +00008354
Douglas Gregora16548e2009-08-11 05:31:07 +00008355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008356ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008357TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008358 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008359 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008360}
Mike Stump11289f42009-09-09 15:08:12 +00008361
Douglas Gregora16548e2009-08-11 05:31:07 +00008362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008363ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008364TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008365 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008366
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008367 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8368 // Make sure that we capture 'this'.
8369 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008370 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008372
Douglas Gregorb15af892010-01-07 23:12:05 +00008373 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008374}
Mike Stump11289f42009-09-09 15:08:12 +00008375
Douglas Gregora16548e2009-08-11 05:31:07 +00008376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008378TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008379 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008380 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008382
Douglas Gregora16548e2009-08-11 05:31:07 +00008383 if (!getDerived().AlwaysRebuild() &&
8384 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008385 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008386
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008387 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8388 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008389}
Mike Stump11289f42009-09-09 15:08:12 +00008390
Douglas Gregora16548e2009-08-11 05:31:07 +00008391template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008392ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008393TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008394 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008395 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8396 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008397 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008398 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008399
Chandler Carruth794da4c2010-02-08 06:42:49 +00008400 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008401 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008402 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008403
Douglas Gregor033f6752009-12-23 23:03:06 +00008404 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008405}
Mike Stump11289f42009-09-09 15:08:12 +00008406
Douglas Gregora16548e2009-08-11 05:31:07 +00008407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008408ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008409TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8410 FieldDecl *Field
8411 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8412 E->getField()));
8413 if (!Field)
8414 return ExprError();
8415
8416 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008417 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008418
8419 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8420}
8421
8422template<typename Derived>
8423ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008424TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8425 CXXScalarValueInitExpr *E) {
8426 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8427 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008428 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008429
Douglas Gregora16548e2009-08-11 05:31:07 +00008430 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008431 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008432 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008433
Chad Rosier1dcde962012-08-08 18:46:20 +00008434 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008435 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008436 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008437}
Mike Stump11289f42009-09-09 15:08:12 +00008438
Douglas Gregora16548e2009-08-11 05:31:07 +00008439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008441TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008442 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008443 TypeSourceInfo *AllocTypeInfo
8444 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8445 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008447
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008449 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008450 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008452
Douglas Gregora16548e2009-08-11 05:31:07 +00008453 // Transform the placement arguments (if any).
8454 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008455 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008456 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008457 E->getNumPlacementArgs(), true,
8458 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008459 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008460
Sebastian Redl6047f072012-02-16 12:22:20 +00008461 // Transform the initializer (if any).
8462 Expr *OldInit = E->getInitializer();
8463 ExprResult NewInit;
8464 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008465 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008466 if (NewInit.isInvalid())
8467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008468
Sebastian Redl6047f072012-02-16 12:22:20 +00008469 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008470 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008471 if (E->getOperatorNew()) {
8472 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008473 getDerived().TransformDecl(E->getLocStart(),
8474 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008475 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008476 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008477 }
8478
Craig Topperc3ec1492014-05-26 06:22:03 +00008479 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008480 if (E->getOperatorDelete()) {
8481 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008482 getDerived().TransformDecl(E->getLocStart(),
8483 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008484 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008485 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008486 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008487
Douglas Gregora16548e2009-08-11 05:31:07 +00008488 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008489 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008491 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008492 OperatorNew == E->getOperatorNew() &&
8493 OperatorDelete == E->getOperatorDelete() &&
8494 !ArgumentChanged) {
8495 // Mark any declarations we need as referenced.
8496 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008497 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008498 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008499 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008500 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008501
Sebastian Redl6047f072012-02-16 12:22:20 +00008502 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008503 QualType ElementType
8504 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8505 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8506 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8507 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008508 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008509 }
8510 }
8511 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008512
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008513 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008514 }
Mike Stump11289f42009-09-09 15:08:12 +00008515
Douglas Gregor0744ef62010-09-07 21:49:58 +00008516 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008517 if (!ArraySize.get()) {
8518 // If no array size was specified, but the new expression was
8519 // instantiated with an array type (e.g., "new T" where T is
8520 // instantiated with "int[4]"), extract the outer bound from the
8521 // array type as our array size. We do this with constant and
8522 // dependently-sized array types.
8523 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8524 if (!ArrayT) {
8525 // Do nothing
8526 } else if (const ConstantArrayType *ConsArrayT
8527 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008528 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8529 SemaRef.Context.getSizeType(),
8530 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008531 AllocType = ConsArrayT->getElementType();
8532 } else if (const DependentSizedArrayType *DepArrayT
8533 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8534 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008535 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008536 AllocType = DepArrayT->getElementType();
8537 }
8538 }
8539 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008540
Douglas Gregora16548e2009-08-11 05:31:07 +00008541 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8542 E->isGlobalNew(),
8543 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008544 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008545 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008546 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008547 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008548 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008549 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008550 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008551 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008552}
Mike Stump11289f42009-09-09 15:08:12 +00008553
Douglas Gregora16548e2009-08-11 05:31:07 +00008554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008556TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008557 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008558 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008559 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008560
Douglas Gregord2d9da02010-02-26 00:38:10 +00008561 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008562 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008563 if (E->getOperatorDelete()) {
8564 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008565 getDerived().TransformDecl(E->getLocStart(),
8566 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008567 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008568 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008569 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008570
Douglas Gregora16548e2009-08-11 05:31:07 +00008571 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008572 Operand.get() == E->getArgument() &&
8573 OperatorDelete == E->getOperatorDelete()) {
8574 // Mark any declarations we need as referenced.
8575 // FIXME: instantiation-specific.
8576 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008577 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008578
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008579 if (!E->getArgument()->isTypeDependent()) {
8580 QualType Destroyed = SemaRef.Context.getBaseElementType(
8581 E->getDestroyedType());
8582 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8583 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008584 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008585 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008586 }
8587 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008588
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008589 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008590 }
Mike Stump11289f42009-09-09 15:08:12 +00008591
Douglas Gregora16548e2009-08-11 05:31:07 +00008592 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8593 E->isGlobalDelete(),
8594 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008595 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008596}
Mike Stump11289f42009-09-09 15:08:12 +00008597
Douglas Gregora16548e2009-08-11 05:31:07 +00008598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008599ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008600TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008601 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008602 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008603 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008605
John McCallba7bf592010-08-24 05:47:05 +00008606 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008607 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008608 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008609 E->getOperatorLoc(),
8610 E->isArrow()? tok::arrow : tok::period,
8611 ObjectTypePtr,
8612 MayBePseudoDestructor);
8613 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008614 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008615
John McCallba7bf592010-08-24 05:47:05 +00008616 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008617 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8618 if (QualifierLoc) {
8619 QualifierLoc
8620 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8621 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008622 return ExprError();
8623 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008624 CXXScopeSpec SS;
8625 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008626
Douglas Gregor678f90d2010-02-25 01:56:36 +00008627 PseudoDestructorTypeStorage Destroyed;
8628 if (E->getDestroyedTypeInfo()) {
8629 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008630 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008631 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008632 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008633 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008634 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008635 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008636 // We aren't likely to be able to resolve the identifier down to a type
8637 // now anyway, so just retain the identifier.
8638 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8639 E->getDestroyedTypeLoc());
8640 } else {
8641 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008642 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008643 *E->getDestroyedTypeIdentifier(),
8644 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008645 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008646 SS, ObjectTypePtr,
8647 false);
8648 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008649 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008650
Douglas Gregor678f90d2010-02-25 01:56:36 +00008651 Destroyed
8652 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8653 E->getDestroyedTypeLoc());
8654 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008655
Craig Topperc3ec1492014-05-26 06:22:03 +00008656 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008657 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008658 CXXScopeSpec EmptySS;
8659 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008660 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008661 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008662 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008663 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008664
John McCallb268a282010-08-23 23:25:46 +00008665 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008666 E->getOperatorLoc(),
8667 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008668 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008669 ScopeTypeInfo,
8670 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008671 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008672 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008673}
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregorad8a3362009-09-04 17:36:40 +00008675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008676ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008677TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008678 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008679 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8680 Sema::LookupOrdinaryName);
8681
8682 // Transform all the decls.
8683 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8684 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008685 NamedDecl *InstD = static_cast<NamedDecl*>(
8686 getDerived().TransformDecl(Old->getNameLoc(),
8687 *I));
John McCall84d87672009-12-10 09:41:52 +00008688 if (!InstD) {
8689 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8690 // This can happen because of dependent hiding.
8691 if (isa<UsingShadowDecl>(*I))
8692 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008693 else {
8694 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008695 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008696 }
John McCall84d87672009-12-10 09:41:52 +00008697 }
John McCalle66edc12009-11-24 19:00:30 +00008698
8699 // Expand using declarations.
8700 if (isa<UsingDecl>(InstD)) {
8701 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008702 for (auto *I : UD->shadows())
8703 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008704 continue;
8705 }
8706
8707 R.addDecl(InstD);
8708 }
8709
8710 // Resolve a kind, but don't do any further analysis. If it's
8711 // ambiguous, the callee needs to deal with it.
8712 R.resolveKind();
8713
8714 // Rebuild the nested-name qualifier, if present.
8715 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008716 if (Old->getQualifierLoc()) {
8717 NestedNameSpecifierLoc QualifierLoc
8718 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8719 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008720 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008721
Douglas Gregor0da1d432011-02-28 20:01:57 +00008722 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008723 }
8724
Douglas Gregor9262f472010-04-27 18:19:34 +00008725 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008726 CXXRecordDecl *NamingClass
8727 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8728 Old->getNameLoc(),
8729 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008730 if (!NamingClass) {
8731 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008732 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008734
Douglas Gregorda7be082010-04-27 16:10:10 +00008735 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008736 }
8737
Abramo Bagnara7945c982012-01-27 09:46:47 +00008738 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8739
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008740 // If we have neither explicit template arguments, nor the template keyword,
8741 // it's a normal declaration name.
8742 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008743 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8744
8745 // If we have template arguments, rebuild them, then rebuild the
8746 // templateid expression.
8747 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008748 if (Old->hasExplicitTemplateArgs() &&
8749 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008750 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008751 TransArgs)) {
8752 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008753 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008754 }
John McCalle66edc12009-11-24 19:00:30 +00008755
Abramo Bagnara7945c982012-01-27 09:46:47 +00008756 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008757 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008758}
Mike Stump11289f42009-09-09 15:08:12 +00008759
Douglas Gregora16548e2009-08-11 05:31:07 +00008760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008761ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008762TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8763 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008764 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008765 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8766 TypeSourceInfo *From = E->getArg(I);
8767 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008768 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008769 TypeLocBuilder TLB;
8770 TLB.reserve(FromTL.getFullDataSize());
8771 QualType To = getDerived().TransformType(TLB, FromTL);
8772 if (To.isNull())
8773 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008774
Douglas Gregor29c42f22012-02-24 07:38:34 +00008775 if (To == From->getType())
8776 Args.push_back(From);
8777 else {
8778 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8779 ArgChanged = true;
8780 }
8781 continue;
8782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008783
Douglas Gregor29c42f22012-02-24 07:38:34 +00008784 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008785
Douglas Gregor29c42f22012-02-24 07:38:34 +00008786 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008787 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008788 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8789 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8790 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008791
Douglas Gregor29c42f22012-02-24 07:38:34 +00008792 // Determine whether the set of unexpanded parameter packs can and should
8793 // be expanded.
8794 bool Expand = true;
8795 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008796 Optional<unsigned> OrigNumExpansions =
8797 ExpansionTL.getTypePtr()->getNumExpansions();
8798 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008799 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8800 PatternTL.getSourceRange(),
8801 Unexpanded,
8802 Expand, RetainExpansion,
8803 NumExpansions))
8804 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008805
Douglas Gregor29c42f22012-02-24 07:38:34 +00008806 if (!Expand) {
8807 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008808 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008809 // expansion.
8810 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008811
Douglas Gregor29c42f22012-02-24 07:38:34 +00008812 TypeLocBuilder TLB;
8813 TLB.reserve(From->getTypeLoc().getFullDataSize());
8814
8815 QualType To = getDerived().TransformType(TLB, PatternTL);
8816 if (To.isNull())
8817 return ExprError();
8818
Chad Rosier1dcde962012-08-08 18:46:20 +00008819 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008820 PatternTL.getSourceRange(),
8821 ExpansionTL.getEllipsisLoc(),
8822 NumExpansions);
8823 if (To.isNull())
8824 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008825
Douglas Gregor29c42f22012-02-24 07:38:34 +00008826 PackExpansionTypeLoc ToExpansionTL
8827 = TLB.push<PackExpansionTypeLoc>(To);
8828 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8829 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8830 continue;
8831 }
8832
8833 // Expand the pack expansion by substituting for each argument in the
8834 // pack(s).
8835 for (unsigned I = 0; I != *NumExpansions; ++I) {
8836 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8837 TypeLocBuilder TLB;
8838 TLB.reserve(PatternTL.getFullDataSize());
8839 QualType To = getDerived().TransformType(TLB, PatternTL);
8840 if (To.isNull())
8841 return ExprError();
8842
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008843 if (To->containsUnexpandedParameterPack()) {
8844 To = getDerived().RebuildPackExpansionType(To,
8845 PatternTL.getSourceRange(),
8846 ExpansionTL.getEllipsisLoc(),
8847 NumExpansions);
8848 if (To.isNull())
8849 return ExprError();
8850
8851 PackExpansionTypeLoc ToExpansionTL
8852 = TLB.push<PackExpansionTypeLoc>(To);
8853 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8854 }
8855
Douglas Gregor29c42f22012-02-24 07:38:34 +00008856 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8857 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008858
Douglas Gregor29c42f22012-02-24 07:38:34 +00008859 if (!RetainExpansion)
8860 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008861
Douglas Gregor29c42f22012-02-24 07:38:34 +00008862 // If we're supposed to retain a pack expansion, do so by temporarily
8863 // forgetting the partially-substituted parameter pack.
8864 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8865
8866 TypeLocBuilder TLB;
8867 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008868
Douglas Gregor29c42f22012-02-24 07:38:34 +00008869 QualType To = getDerived().TransformType(TLB, PatternTL);
8870 if (To.isNull())
8871 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008872
8873 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008874 PatternTL.getSourceRange(),
8875 ExpansionTL.getEllipsisLoc(),
8876 NumExpansions);
8877 if (To.isNull())
8878 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008879
Douglas Gregor29c42f22012-02-24 07:38:34 +00008880 PackExpansionTypeLoc ToExpansionTL
8881 = TLB.push<PackExpansionTypeLoc>(To);
8882 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8883 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008885
Douglas Gregor29c42f22012-02-24 07:38:34 +00008886 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008887 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008888
8889 return getDerived().RebuildTypeTrait(E->getTrait(),
8890 E->getLocStart(),
8891 Args,
8892 E->getLocEnd());
8893}
8894
8895template<typename Derived>
8896ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008897TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8898 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8899 if (!T)
8900 return ExprError();
8901
8902 if (!getDerived().AlwaysRebuild() &&
8903 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008904 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008905
8906 ExprResult SubExpr;
8907 {
8908 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8909 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8910 if (SubExpr.isInvalid())
8911 return ExprError();
8912
8913 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008914 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008915 }
8916
8917 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8918 E->getLocStart(),
8919 T,
8920 SubExpr.get(),
8921 E->getLocEnd());
8922}
8923
8924template<typename Derived>
8925ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008926TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8927 ExprResult SubExpr;
8928 {
8929 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8930 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8931 if (SubExpr.isInvalid())
8932 return ExprError();
8933
8934 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008935 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008936 }
8937
8938 return getDerived().RebuildExpressionTrait(
8939 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8940}
8941
Reid Kleckner32506ed2014-06-12 23:03:48 +00008942template <typename Derived>
8943ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8944 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8945 TypeSourceInfo **RecoveryTSI) {
8946 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8947 DRE, AddrTaken, RecoveryTSI);
8948
8949 // Propagate both errors and recovered types, which return ExprEmpty.
8950 if (!NewDRE.isUsable())
8951 return NewDRE;
8952
8953 // We got an expr, wrap it up in parens.
8954 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8955 return PE;
8956 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8957 PE->getRParen());
8958}
8959
8960template <typename Derived>
8961ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8962 DependentScopeDeclRefExpr *E) {
8963 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8964 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008965}
8966
8967template<typename Derived>
8968ExprResult
8969TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8970 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008971 bool IsAddressOfOperand,
8972 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008973 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008974 NestedNameSpecifierLoc QualifierLoc
8975 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8976 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008977 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008978 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008979
John McCall31f82722010-11-12 08:19:04 +00008980 // TODO: If this is a conversion-function-id, verify that the
8981 // destination type name (if present) resolves the same way after
8982 // instantiation as it did in the local scope.
8983
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008984 DeclarationNameInfo NameInfo
8985 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8986 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008988
John McCalle66edc12009-11-24 19:00:30 +00008989 if (!E->hasExplicitTemplateArgs()) {
8990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008991 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008992 // Note: it is sufficient to compare the Name component of NameInfo:
8993 // if name has not changed, DNLoc has not changed either.
8994 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008995 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008996
Reid Kleckner32506ed2014-06-12 23:03:48 +00008997 return getDerived().RebuildDependentScopeDeclRefExpr(
8998 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8999 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009000 }
John McCall6b51f282009-11-23 01:53:49 +00009001
9002 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009003 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9004 E->getNumTemplateArgs(),
9005 TransArgs))
9006 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009007
Reid Kleckner32506ed2014-06-12 23:03:48 +00009008 return getDerived().RebuildDependentScopeDeclRefExpr(
9009 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9010 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009011}
9012
9013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009014ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009015TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009016 // CXXConstructExprs other than for list-initialization and
9017 // CXXTemporaryObjectExpr are always implicit, so when we have
9018 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009019 if ((E->getNumArgs() == 1 ||
9020 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009021 (!getDerived().DropCallArgument(E->getArg(0))) &&
9022 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009023 return getDerived().TransformExpr(E->getArg(0));
9024
Douglas Gregora16548e2009-08-11 05:31:07 +00009025 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9026
9027 QualType T = getDerived().TransformType(E->getType());
9028 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009029 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009030
9031 CXXConstructorDecl *Constructor
9032 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009033 getDerived().TransformDecl(E->getLocStart(),
9034 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009035 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009036 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009037
Douglas Gregora16548e2009-08-11 05:31:07 +00009038 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009039 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009040 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009041 &ArgumentChanged))
9042 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009043
Douglas Gregora16548e2009-08-11 05:31:07 +00009044 if (!getDerived().AlwaysRebuild() &&
9045 T == E->getType() &&
9046 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009047 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009048 // Mark the constructor as referenced.
9049 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009050 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009051 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009052 }
Mike Stump11289f42009-09-09 15:08:12 +00009053
Douglas Gregordb121ba2009-12-14 16:27:04 +00009054 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9055 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009056 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009057 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009058 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009059 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009060 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009061 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009062 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009063}
Mike Stump11289f42009-09-09 15:08:12 +00009064
Douglas Gregora16548e2009-08-11 05:31:07 +00009065/// \brief Transform a C++ temporary-binding expression.
9066///
Douglas Gregor363b1512009-12-24 18:51:59 +00009067/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9068/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009071TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009072 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009073}
Mike Stump11289f42009-09-09 15:08:12 +00009074
John McCall5d413782010-12-06 08:20:24 +00009075/// \brief Transform a C++ expression that contains cleanups that should
9076/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009077///
John McCall5d413782010-12-06 08:20:24 +00009078/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009079/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009081ExprResult
John McCall5d413782010-12-06 08:20:24 +00009082TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009083 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009084}
Mike Stump11289f42009-09-09 15:08:12 +00009085
Douglas Gregora16548e2009-08-11 05:31:07 +00009086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009087ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009088TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009089 CXXTemporaryObjectExpr *E) {
9090 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9091 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009092 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009093
Douglas Gregora16548e2009-08-11 05:31:07 +00009094 CXXConstructorDecl *Constructor
9095 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009096 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009097 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009098 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009100
Douglas Gregora16548e2009-08-11 05:31:07 +00009101 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009102 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009103 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009104 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009105 &ArgumentChanged))
9106 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009107
Douglas Gregora16548e2009-08-11 05:31:07 +00009108 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009109 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009110 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009111 !ArgumentChanged) {
9112 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009113 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009114 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009116
Richard Smithd59b8322012-12-19 01:39:02 +00009117 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009118 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9119 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009120 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009121 E->getLocEnd());
9122}
Mike Stump11289f42009-09-09 15:08:12 +00009123
Douglas Gregora16548e2009-08-11 05:31:07 +00009124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009125ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009126TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009127 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009128 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009129 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009130 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9131 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009132 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009133 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009134 CEnd = E->capture_end();
9135 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009136 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009137 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009138 EnterExpressionEvaluationContext EEEC(getSema(),
9139 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009140 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9141 C->getCapturedVar()->getInit(),
9142 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009143
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009144 if (NewExprInitResult.isInvalid())
9145 return ExprError();
9146 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009147
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009148 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009149 QualType NewInitCaptureType =
9150 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9151 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009152 NewExprInit);
9153 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009154 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9155 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009156 }
9157
Faisal Vali2cba1332013-10-23 06:44:28 +00009158 // Transform the template parameters, and add them to the current
9159 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009160 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009161 E->getTemplateParameterList());
9162
Richard Smith01014ce2014-11-20 23:53:14 +00009163 // Transform the type of the original lambda's call operator.
9164 // The transformation MUST be done in the CurrentInstantiationScope since
9165 // it introduces a mapping of the original to the newly created
9166 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009167 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009168 {
9169 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9170 FunctionProtoTypeLoc OldCallOpFPTL =
9171 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009172
9173 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009174 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009175 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009176 QualType NewCallOpType = TransformFunctionProtoType(
9177 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009178 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9179 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9180 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009181 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009182 if (NewCallOpType.isNull())
9183 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009184 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9185 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009186 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009187
Richard Smithc38498f2015-04-27 21:27:54 +00009188 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9189 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9190 LSI->GLTemplateParameterList = TPL;
9191
Eli Friedmand564afb2012-09-19 01:18:11 +00009192 // Create the local class that will describe the lambda.
9193 CXXRecordDecl *Class
9194 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009195 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009196 /*KnownDependent=*/false,
9197 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009198 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9199
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009200 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009201 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9202 Class, E->getIntroducerRange(), NewCallOpTSI,
9203 E->getCallOperator()->getLocEnd(),
9204 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009205 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009206
Faisal Vali2cba1332013-10-23 06:44:28 +00009207 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009208 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009209
Douglas Gregorb4328232012-02-14 00:00:48 +00009210 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009211 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009212 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009213
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009214 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009215 getSema().buildLambdaScope(LSI, NewCallOperator,
9216 E->getIntroducerRange(),
9217 E->getCaptureDefault(),
9218 E->getCaptureDefaultLoc(),
9219 E->hasExplicitParameters(),
9220 E->hasExplicitResultType(),
9221 E->isMutable());
9222
9223 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009224
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009225 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009226 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009227 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009228 CEnd = E->capture_end();
9229 C != CEnd; ++C) {
9230 // When we hit the first implicit capture, tell Sema that we've finished
9231 // the list of explicit captures.
9232 if (!FinishedExplicitCaptures && C->isImplicit()) {
9233 getSema().finishLambdaExplicitCaptures(LSI);
9234 FinishedExplicitCaptures = true;
9235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009236
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009237 // Capturing 'this' is trivial.
9238 if (C->capturesThis()) {
9239 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9240 continue;
9241 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009242 // Captured expression will be recaptured during captured variables
9243 // rebuilding.
9244 if (C->capturesVLAType())
9245 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009246
Richard Smithba71c082013-05-16 06:20:58 +00009247 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009248 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009249 InitCaptureInfoTy InitExprTypePair =
9250 InitCaptureExprsAndTypes[C - E->capture_begin()];
9251 ExprResult Init = InitExprTypePair.first;
9252 QualType InitQualType = InitExprTypePair.second;
9253 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009254 Invalid = true;
9255 continue;
9256 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009257 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009258 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9259 OldVD->getLocation(), InitExprTypePair.second,
9260 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009261 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009262 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009263 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009264 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009265 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009266 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009267 continue;
9268 }
9269
9270 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9271
Douglas Gregor3e308b12012-02-14 19:27:52 +00009272 // Determine the capture kind for Sema.
9273 Sema::TryCaptureKind Kind
9274 = C->isImplicit()? Sema::TryCapture_Implicit
9275 : C->getCaptureKind() == LCK_ByCopy
9276 ? Sema::TryCapture_ExplicitByVal
9277 : Sema::TryCapture_ExplicitByRef;
9278 SourceLocation EllipsisLoc;
9279 if (C->isPackExpansion()) {
9280 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9281 bool ShouldExpand = false;
9282 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009283 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009284 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9285 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009286 Unexpanded,
9287 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009288 NumExpansions)) {
9289 Invalid = true;
9290 continue;
9291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009292
Douglas Gregor3e308b12012-02-14 19:27:52 +00009293 if (ShouldExpand) {
9294 // The transform has determined that we should perform an expansion;
9295 // transform and capture each of the arguments.
9296 // expansion of the pattern. Do so.
9297 VarDecl *Pack = C->getCapturedVar();
9298 for (unsigned I = 0; I != *NumExpansions; ++I) {
9299 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9300 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009301 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009302 Pack));
9303 if (!CapturedVar) {
9304 Invalid = true;
9305 continue;
9306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009307
Douglas Gregor3e308b12012-02-14 19:27:52 +00009308 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009309 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9310 }
Richard Smith9467be42014-06-06 17:33:35 +00009311
9312 // FIXME: Retain a pack expansion if RetainExpansion is true.
9313
Douglas Gregor3e308b12012-02-14 19:27:52 +00009314 continue;
9315 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009316
Douglas Gregor3e308b12012-02-14 19:27:52 +00009317 EllipsisLoc = C->getEllipsisLoc();
9318 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009319
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009320 // Transform the captured variable.
9321 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009322 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009323 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009324 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009325 Invalid = true;
9326 continue;
9327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009328
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009329 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009330 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009331 }
9332 if (!FinishedExplicitCaptures)
9333 getSema().finishLambdaExplicitCaptures(LSI);
9334
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009335 // Enter a new evaluation context to insulate the lambda from any
9336 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009337 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009338
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009339 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009340 StmtResult Body =
9341 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9342
9343 // ActOnLambda* will pop the function scope for us.
9344 FuncScopeCleanup.disable();
9345
Douglas Gregorb4328232012-02-14 00:00:48 +00009346 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009347 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009348 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009349 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009350 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009351 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009352
Richard Smithc38498f2015-04-27 21:27:54 +00009353 // Copy the LSI before ActOnFinishFunctionBody removes it.
9354 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9355 // the call operator.
9356 auto LSICopy = *LSI;
9357 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9358 /*IsInstantiation*/ true);
9359 SavedContext.pop();
9360
9361 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9362 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009363}
9364
9365template<typename Derived>
9366ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009367TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009368 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009369 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9370 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009371 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009372
Douglas Gregora16548e2009-08-11 05:31:07 +00009373 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009374 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009375 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009376 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009377 &ArgumentChanged))
9378 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009379
Douglas Gregora16548e2009-08-11 05:31:07 +00009380 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009381 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009382 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009383 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009384
Douglas Gregora16548e2009-08-11 05:31:07 +00009385 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009386 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009387 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009388 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009389 E->getRParenLoc());
9390}
Mike Stump11289f42009-09-09 15:08:12 +00009391
Douglas Gregora16548e2009-08-11 05:31:07 +00009392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009393ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009394TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009395 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009396 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009397 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009398 Expr *OldBase;
9399 QualType BaseType;
9400 QualType ObjectType;
9401 if (!E->isImplicitAccess()) {
9402 OldBase = E->getBase();
9403 Base = getDerived().TransformExpr(OldBase);
9404 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009405 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009406
John McCall2d74de92009-12-01 22:10:20 +00009407 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009408 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009409 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009410 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009411 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009412 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009413 ObjectTy,
9414 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009415 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009416 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009417
John McCallba7bf592010-08-24 05:47:05 +00009418 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009419 BaseType = ((Expr*) Base.get())->getType();
9420 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009421 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009422 BaseType = getDerived().TransformType(E->getBaseType());
9423 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9424 }
Mike Stump11289f42009-09-09 15:08:12 +00009425
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009426 // Transform the first part of the nested-name-specifier that qualifies
9427 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009428 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009429 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009430 E->getFirstQualifierFoundInScope(),
9431 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009432
Douglas Gregore16af532011-02-28 18:50:33 +00009433 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009434 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009435 QualifierLoc
9436 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9437 ObjectType,
9438 FirstQualifierInScope);
9439 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009440 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009441 }
Mike Stump11289f42009-09-09 15:08:12 +00009442
Abramo Bagnara7945c982012-01-27 09:46:47 +00009443 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9444
John McCall31f82722010-11-12 08:19:04 +00009445 // TODO: If this is a conversion-function-id, verify that the
9446 // destination type name (if present) resolves the same way after
9447 // instantiation as it did in the local scope.
9448
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009449 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009450 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009451 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009453
John McCall2d74de92009-12-01 22:10:20 +00009454 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009455 // This is a reference to a member without an explicitly-specified
9456 // template argument list. Optimize for this common case.
9457 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009458 Base.get() == OldBase &&
9459 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009460 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009461 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009462 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009463 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009464
John McCallb268a282010-08-23 23:25:46 +00009465 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009466 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009467 E->isArrow(),
9468 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009469 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009470 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009471 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009472 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009473 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009474 }
9475
John McCall6b51f282009-11-23 01:53:49 +00009476 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009477 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9478 E->getNumTemplateArgs(),
9479 TransArgs))
9480 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009481
John McCallb268a282010-08-23 23:25:46 +00009482 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009483 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009484 E->isArrow(),
9485 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009486 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009487 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009488 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009489 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009490 &TransArgs);
9491}
9492
9493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009495TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009496 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009497 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009498 QualType BaseType;
9499 if (!Old->isImplicitAccess()) {
9500 Base = getDerived().TransformExpr(Old->getBase());
9501 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009502 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009503 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009504 Old->isArrow());
9505 if (Base.isInvalid())
9506 return ExprError();
9507 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009508 } else {
9509 BaseType = getDerived().TransformType(Old->getBaseType());
9510 }
John McCall10eae182009-11-30 22:42:35 +00009511
Douglas Gregor0da1d432011-02-28 20:01:57 +00009512 NestedNameSpecifierLoc QualifierLoc;
9513 if (Old->getQualifierLoc()) {
9514 QualifierLoc
9515 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9516 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009517 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009518 }
9519
Abramo Bagnara7945c982012-01-27 09:46:47 +00009520 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9521
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009522 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009523 Sema::LookupOrdinaryName);
9524
9525 // Transform all the decls.
9526 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9527 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009528 NamedDecl *InstD = static_cast<NamedDecl*>(
9529 getDerived().TransformDecl(Old->getMemberLoc(),
9530 *I));
John McCall84d87672009-12-10 09:41:52 +00009531 if (!InstD) {
9532 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9533 // This can happen because of dependent hiding.
9534 if (isa<UsingShadowDecl>(*I))
9535 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009536 else {
9537 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009538 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009539 }
John McCall84d87672009-12-10 09:41:52 +00009540 }
John McCall10eae182009-11-30 22:42:35 +00009541
9542 // Expand using declarations.
9543 if (isa<UsingDecl>(InstD)) {
9544 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009545 for (auto *I : UD->shadows())
9546 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009547 continue;
9548 }
9549
9550 R.addDecl(InstD);
9551 }
9552
9553 R.resolveKind();
9554
Douglas Gregor9262f472010-04-27 18:19:34 +00009555 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009556 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009557 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009558 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009559 Old->getMemberLoc(),
9560 Old->getNamingClass()));
9561 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009562 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009563
Douglas Gregorda7be082010-04-27 16:10:10 +00009564 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009566
John McCall10eae182009-11-30 22:42:35 +00009567 TemplateArgumentListInfo TransArgs;
9568 if (Old->hasExplicitTemplateArgs()) {
9569 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9570 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009571 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9572 Old->getNumTemplateArgs(),
9573 TransArgs))
9574 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009575 }
John McCall38836f02010-01-15 08:34:02 +00009576
9577 // FIXME: to do this check properly, we will need to preserve the
9578 // first-qualifier-in-scope here, just in case we had a dependent
9579 // base (and therefore couldn't do the check) and a
9580 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009581 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009582
John McCallb268a282010-08-23 23:25:46 +00009583 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009584 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009585 Old->getOperatorLoc(),
9586 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009587 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009588 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009589 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009590 R,
9591 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009592 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009593}
9594
9595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009596ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009597TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009599 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9600 if (SubExpr.isInvalid())
9601 return ExprError();
9602
9603 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009604 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009605
9606 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9607}
9608
9609template<typename Derived>
9610ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009611TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009612 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9613 if (Pattern.isInvalid())
9614 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009615
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009616 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009617 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009618
Douglas Gregorb8840002011-01-14 21:20:45 +00009619 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9620 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009621}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009622
9623template<typename Derived>
9624ExprResult
9625TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9626 // If E is not value-dependent, then nothing will change when we transform it.
9627 // Note: This is an instantiation-centric view.
9628 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009629 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009630
9631 // Note: None of the implementations of TryExpandParameterPacks can ever
9632 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009633 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009634 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9635 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009636 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009637 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009638 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009639 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009640 ShouldExpand, RetainExpansion,
9641 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009642 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009643
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009644 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009645 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009646
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009647 NamedDecl *Pack = E->getPack();
9648 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009649 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009650 Pack));
9651 if (!Pack)
9652 return ExprError();
9653 }
9654
Chad Rosier1dcde962012-08-08 18:46:20 +00009655
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009656 // We now know the length of the parameter pack, so build a new expression
9657 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009658 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9659 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009660 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009661}
9662
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009663template<typename Derived>
9664ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009665TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9666 SubstNonTypeTemplateParmPackExpr *E) {
9667 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009668 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009669}
9670
9671template<typename Derived>
9672ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009673TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9674 SubstNonTypeTemplateParmExpr *E) {
9675 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009676 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009677}
9678
9679template<typename Derived>
9680ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009681TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9682 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009683 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009684}
9685
9686template<typename Derived>
9687ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009688TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9689 MaterializeTemporaryExpr *E) {
9690 return getDerived().TransformExpr(E->GetTemporaryExpr());
9691}
Chad Rosier1dcde962012-08-08 18:46:20 +00009692
Douglas Gregorfe314812011-06-21 17:03:29 +00009693template<typename Derived>
9694ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009695TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9696 Expr *Pattern = E->getPattern();
9697
9698 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9699 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9700 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9701
9702 // Determine whether the set of unexpanded parameter packs can and should
9703 // be expanded.
9704 bool Expand = true;
9705 bool RetainExpansion = false;
9706 Optional<unsigned> NumExpansions;
9707 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9708 Pattern->getSourceRange(),
9709 Unexpanded,
9710 Expand, RetainExpansion,
9711 NumExpansions))
9712 return true;
9713
9714 if (!Expand) {
9715 // Do not expand any packs here, just transform and rebuild a fold
9716 // expression.
9717 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9718
9719 ExprResult LHS =
9720 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9721 if (LHS.isInvalid())
9722 return true;
9723
9724 ExprResult RHS =
9725 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9726 if (RHS.isInvalid())
9727 return true;
9728
9729 if (!getDerived().AlwaysRebuild() &&
9730 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9731 return E;
9732
9733 return getDerived().RebuildCXXFoldExpr(
9734 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9735 RHS.get(), E->getLocEnd());
9736 }
9737
9738 // The transform has determined that we should perform an elementwise
9739 // expansion of the pattern. Do so.
9740 ExprResult Result = getDerived().TransformExpr(E->getInit());
9741 if (Result.isInvalid())
9742 return true;
9743 bool LeftFold = E->isLeftFold();
9744
9745 // If we're retaining an expansion for a right fold, it is the innermost
9746 // component and takes the init (if any).
9747 if (!LeftFold && RetainExpansion) {
9748 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9749
9750 ExprResult Out = getDerived().TransformExpr(Pattern);
9751 if (Out.isInvalid())
9752 return true;
9753
9754 Result = getDerived().RebuildCXXFoldExpr(
9755 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9756 Result.get(), E->getLocEnd());
9757 if (Result.isInvalid())
9758 return true;
9759 }
9760
9761 for (unsigned I = 0; I != *NumExpansions; ++I) {
9762 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9763 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9764 ExprResult Out = getDerived().TransformExpr(Pattern);
9765 if (Out.isInvalid())
9766 return true;
9767
9768 if (Out.get()->containsUnexpandedParameterPack()) {
9769 // We still have a pack; retain a pack expansion for this slice.
9770 Result = getDerived().RebuildCXXFoldExpr(
9771 E->getLocStart(),
9772 LeftFold ? Result.get() : Out.get(),
9773 E->getOperator(), E->getEllipsisLoc(),
9774 LeftFold ? Out.get() : Result.get(),
9775 E->getLocEnd());
9776 } else if (Result.isUsable()) {
9777 // We've got down to a single element; build a binary operator.
9778 Result = getDerived().RebuildBinaryOperator(
9779 E->getEllipsisLoc(), E->getOperator(),
9780 LeftFold ? Result.get() : Out.get(),
9781 LeftFold ? Out.get() : Result.get());
9782 } else
9783 Result = Out;
9784
9785 if (Result.isInvalid())
9786 return true;
9787 }
9788
9789 // If we're retaining an expansion for a left fold, it is the outermost
9790 // component and takes the complete expansion so far as its init (if any).
9791 if (LeftFold && RetainExpansion) {
9792 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9793
9794 ExprResult Out = getDerived().TransformExpr(Pattern);
9795 if (Out.isInvalid())
9796 return true;
9797
9798 Result = getDerived().RebuildCXXFoldExpr(
9799 E->getLocStart(), Result.get(),
9800 E->getOperator(), E->getEllipsisLoc(),
9801 Out.get(), E->getLocEnd());
9802 if (Result.isInvalid())
9803 return true;
9804 }
9805
9806 // If we had no init and an empty pack, and we're not retaining an expansion,
9807 // then produce a fallback value or error.
9808 if (Result.isUnset())
9809 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9810 E->getOperator());
9811
9812 return Result;
9813}
9814
9815template<typename Derived>
9816ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009817TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9818 CXXStdInitializerListExpr *E) {
9819 return getDerived().TransformExpr(E->getSubExpr());
9820}
9821
9822template<typename Derived>
9823ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009824TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009825 return SemaRef.MaybeBindToTemporary(E);
9826}
9827
9828template<typename Derived>
9829ExprResult
9830TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009831 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009832}
9833
9834template<typename Derived>
9835ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009836TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9837 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9838 if (SubExpr.isInvalid())
9839 return ExprError();
9840
9841 if (!getDerived().AlwaysRebuild() &&
9842 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009843 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009844
9845 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009846}
9847
9848template<typename Derived>
9849ExprResult
9850TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9851 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009852 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009853 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009854 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009855 /*IsCall=*/false, Elements, &ArgChanged))
9856 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009857
Ted Kremeneke65b0862012-03-06 20:05:56 +00009858 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9859 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009860
Ted Kremeneke65b0862012-03-06 20:05:56 +00009861 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9862 Elements.data(),
9863 Elements.size());
9864}
9865
9866template<typename Derived>
9867ExprResult
9868TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009869 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009870 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009871 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009872 bool ArgChanged = false;
9873 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9874 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009875
Ted Kremeneke65b0862012-03-06 20:05:56 +00009876 if (OrigElement.isPackExpansion()) {
9877 // This key/value element is a pack expansion.
9878 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9879 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9880 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9881 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9882
9883 // Determine whether the set of unexpanded parameter packs can
9884 // and should be expanded.
9885 bool Expand = true;
9886 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009887 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9888 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009889 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9890 OrigElement.Value->getLocEnd());
9891 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9892 PatternRange,
9893 Unexpanded,
9894 Expand, RetainExpansion,
9895 NumExpansions))
9896 return ExprError();
9897
9898 if (!Expand) {
9899 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009900 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009901 // expansion.
9902 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9903 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9904 if (Key.isInvalid())
9905 return ExprError();
9906
9907 if (Key.get() != OrigElement.Key)
9908 ArgChanged = true;
9909
9910 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9911 if (Value.isInvalid())
9912 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009913
Ted Kremeneke65b0862012-03-06 20:05:56 +00009914 if (Value.get() != OrigElement.Value)
9915 ArgChanged = true;
9916
Chad Rosier1dcde962012-08-08 18:46:20 +00009917 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009918 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9919 };
9920 Elements.push_back(Expansion);
9921 continue;
9922 }
9923
9924 // Record right away that the argument was changed. This needs
9925 // to happen even if the array expands to nothing.
9926 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009927
Ted Kremeneke65b0862012-03-06 20:05:56 +00009928 // The transform has determined that we should perform an elementwise
9929 // expansion of the pattern. Do so.
9930 for (unsigned I = 0; I != *NumExpansions; ++I) {
9931 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9932 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9933 if (Key.isInvalid())
9934 return ExprError();
9935
9936 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9937 if (Value.isInvalid())
9938 return ExprError();
9939
Chad Rosier1dcde962012-08-08 18:46:20 +00009940 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009941 Key.get(), Value.get(), SourceLocation(), NumExpansions
9942 };
9943
9944 // If any unexpanded parameter packs remain, we still have a
9945 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009946 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009947 if (Key.get()->containsUnexpandedParameterPack() ||
9948 Value.get()->containsUnexpandedParameterPack())
9949 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009950
Ted Kremeneke65b0862012-03-06 20:05:56 +00009951 Elements.push_back(Element);
9952 }
9953
Richard Smith9467be42014-06-06 17:33:35 +00009954 // FIXME: Retain a pack expansion if RetainExpansion is true.
9955
Ted Kremeneke65b0862012-03-06 20:05:56 +00009956 // We've finished with this pack expansion.
9957 continue;
9958 }
9959
9960 // Transform and check key.
9961 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9962 if (Key.isInvalid())
9963 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009964
Ted Kremeneke65b0862012-03-06 20:05:56 +00009965 if (Key.get() != OrigElement.Key)
9966 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009967
Ted Kremeneke65b0862012-03-06 20:05:56 +00009968 // Transform and check value.
9969 ExprResult Value
9970 = getDerived().TransformExpr(OrigElement.Value);
9971 if (Value.isInvalid())
9972 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009973
Ted Kremeneke65b0862012-03-06 20:05:56 +00009974 if (Value.get() != OrigElement.Value)
9975 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009976
9977 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009978 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009979 };
9980 Elements.push_back(Element);
9981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009982
Ted Kremeneke65b0862012-03-06 20:05:56 +00009983 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9984 return SemaRef.MaybeBindToTemporary(E);
9985
9986 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9987 Elements.data(),
9988 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009989}
9990
Mike Stump11289f42009-09-09 15:08:12 +00009991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009993TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009994 TypeSourceInfo *EncodedTypeInfo
9995 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9996 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009998
Douglas Gregora16548e2009-08-11 05:31:07 +00009999 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010000 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010001 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010002
10003 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010004 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010005 E->getRParenLoc());
10006}
Mike Stump11289f42009-09-09 15:08:12 +000010007
Douglas Gregora16548e2009-08-11 05:31:07 +000010008template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010009ExprResult TreeTransform<Derived>::
10010TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010011 // This is a kind of implicit conversion, and it needs to get dropped
10012 // and recomputed for the same general reasons that ImplicitCastExprs
10013 // do, as well a more specific one: this expression is only valid when
10014 // it appears *immediately* as an argument expression.
10015 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010016}
10017
10018template<typename Derived>
10019ExprResult TreeTransform<Derived>::
10020TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010021 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010022 = getDerived().TransformType(E->getTypeInfoAsWritten());
10023 if (!TSInfo)
10024 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010025
John McCall31168b02011-06-15 23:02:42 +000010026 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010027 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010028 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010029
John McCall31168b02011-06-15 23:02:42 +000010030 if (!getDerived().AlwaysRebuild() &&
10031 TSInfo == E->getTypeInfoAsWritten() &&
10032 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010033 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010034
John McCall31168b02011-06-15 23:02:42 +000010035 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010036 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010037 Result.get());
10038}
10039
10040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010042TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010043 // Transform arguments.
10044 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010045 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010046 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010047 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010048 &ArgChanged))
10049 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010050
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010051 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10052 // Class message: transform the receiver type.
10053 TypeSourceInfo *ReceiverTypeInfo
10054 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10055 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010056 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010057
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010058 // If nothing changed, just retain the existing message send.
10059 if (!getDerived().AlwaysRebuild() &&
10060 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010061 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010062
10063 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010064 SmallVector<SourceLocation, 16> SelLocs;
10065 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010066 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10067 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010068 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010069 E->getMethodDecl(),
10070 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010071 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010072 E->getRightLoc());
10073 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010074 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10075 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10076 // Build a new class message send to 'super'.
10077 SmallVector<SourceLocation, 16> SelLocs;
10078 E->getSelectorLocs(SelLocs);
10079 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10080 E->getSelector(),
10081 SelLocs,
10082 E->getMethodDecl(),
10083 E->getLeftLoc(),
10084 Args,
10085 E->getRightLoc());
10086 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010087
10088 // Instance message: transform the receiver
10089 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10090 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010091 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010092 = getDerived().TransformExpr(E->getInstanceReceiver());
10093 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010094 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010095
10096 // If nothing changed, just retain the existing message send.
10097 if (!getDerived().AlwaysRebuild() &&
10098 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010099 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010100
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010101 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010102 SmallVector<SourceLocation, 16> SelLocs;
10103 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010104 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010105 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010106 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010107 E->getMethodDecl(),
10108 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010109 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010110 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010111}
10112
Mike Stump11289f42009-09-09 15:08:12 +000010113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010115TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010116 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010117}
10118
Mike Stump11289f42009-09-09 15:08:12 +000010119template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010120ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010121TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010122 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010123}
10124
Mike Stump11289f42009-09-09 15:08:12 +000010125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010127TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010128 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010129 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010130 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010131 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010132
10133 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010134
Douglas Gregord51d90d2010-04-26 20:11:03 +000010135 // If nothing changed, just retain the existing expression.
10136 if (!getDerived().AlwaysRebuild() &&
10137 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010138 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010139
John McCallb268a282010-08-23 23:25:46 +000010140 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010141 E->getLocation(),
10142 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010143}
10144
Mike Stump11289f42009-09-09 15:08:12 +000010145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010147TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010148 // 'super' and types never change. Property never changes. Just
10149 // retain the existing expression.
10150 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010151 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010152
Douglas Gregor9faee212010-04-26 20:47:02 +000010153 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010154 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010155 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010156 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010157
Douglas Gregor9faee212010-04-26 20:47:02 +000010158 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010159
Douglas Gregor9faee212010-04-26 20:47:02 +000010160 // If nothing changed, just retain the existing expression.
10161 if (!getDerived().AlwaysRebuild() &&
10162 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010163 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010164
John McCallb7bd14f2010-12-02 01:19:52 +000010165 if (E->isExplicitProperty())
10166 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10167 E->getExplicitProperty(),
10168 E->getLocation());
10169
10170 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010171 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010172 E->getImplicitPropertyGetter(),
10173 E->getImplicitPropertySetter(),
10174 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010175}
10176
Mike Stump11289f42009-09-09 15:08:12 +000010177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010178ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010179TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10180 // Transform the base expression.
10181 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10182 if (Base.isInvalid())
10183 return ExprError();
10184
10185 // Transform the key expression.
10186 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10187 if (Key.isInvalid())
10188 return ExprError();
10189
10190 // If nothing changed, just retain the existing expression.
10191 if (!getDerived().AlwaysRebuild() &&
10192 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010193 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010194
Chad Rosier1dcde962012-08-08 18:46:20 +000010195 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010196 Base.get(), Key.get(),
10197 E->getAtIndexMethodDecl(),
10198 E->setAtIndexMethodDecl());
10199}
10200
10201template<typename Derived>
10202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010203TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010204 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010205 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010206 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010207 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010208
Douglas Gregord51d90d2010-04-26 20:11:03 +000010209 // If nothing changed, just retain the existing expression.
10210 if (!getDerived().AlwaysRebuild() &&
10211 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010212 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010213
John McCallb268a282010-08-23 23:25:46 +000010214 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010215 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010216 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010217}
10218
Mike Stump11289f42009-09-09 15:08:12 +000010219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010221TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010222 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010223 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010224 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010225 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010226 SubExprs, &ArgumentChanged))
10227 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010228
Douglas Gregora16548e2009-08-11 05:31:07 +000010229 if (!getDerived().AlwaysRebuild() &&
10230 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010231 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010232
Douglas Gregora16548e2009-08-11 05:31:07 +000010233 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010234 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010235 E->getRParenLoc());
10236}
10237
Mike Stump11289f42009-09-09 15:08:12 +000010238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010239ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010240TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10241 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10242 if (SrcExpr.isInvalid())
10243 return ExprError();
10244
10245 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10246 if (!Type)
10247 return ExprError();
10248
10249 if (!getDerived().AlwaysRebuild() &&
10250 Type == E->getTypeSourceInfo() &&
10251 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010252 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010253
10254 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10255 SrcExpr.get(), Type,
10256 E->getRParenLoc());
10257}
10258
10259template<typename Derived>
10260ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010261TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010262 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010263
Craig Topperc3ec1492014-05-26 06:22:03 +000010264 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010265 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10266
10267 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010268 blockScope->TheDecl->setBlockMissingReturnType(
10269 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010270
Chris Lattner01cf8db2011-07-20 06:58:45 +000010271 SmallVector<ParmVarDecl*, 4> params;
10272 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010273
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010274 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010275 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10276 oldBlock->param_begin(),
10277 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010278 nullptr, paramTypes, &params)) {
10279 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010280 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010281 }
John McCall490112f2011-02-04 18:33:18 +000010282
Jordan Rosea0a86be2013-03-08 22:25:36 +000010283 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010284 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010285 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010286
Jordan Rose5c382722013-03-08 21:51:21 +000010287 QualType functionType =
10288 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010289 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010290 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010291
10292 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010293 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010294 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010295
10296 if (!oldBlock->blockMissingReturnType()) {
10297 blockScope->HasImplicitReturnType = false;
10298 blockScope->ReturnType = exprResultType;
10299 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010300
John McCall3882ace2011-01-05 12:14:39 +000010301 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010302 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010303 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010304 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010305 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010306 }
John McCall3882ace2011-01-05 12:14:39 +000010307
John McCall490112f2011-02-04 18:33:18 +000010308#ifndef NDEBUG
10309 // In builds with assertions, make sure that we captured everything we
10310 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010311 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010312 for (const auto &I : oldBlock->captures()) {
10313 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010314
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010315 // Ignore parameter packs.
10316 if (isa<ParmVarDecl>(oldCapture) &&
10317 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10318 continue;
John McCall490112f2011-02-04 18:33:18 +000010319
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010320 VarDecl *newCapture =
10321 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10322 oldCapture));
10323 assert(blockScope->CaptureMap.count(newCapture));
10324 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010325 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010326 }
10327#endif
10328
10329 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010330 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010331}
10332
Mike Stump11289f42009-09-09 15:08:12 +000010333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010334ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010335TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010336 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010337}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010338
10339template<typename Derived>
10340ExprResult
10341TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010342 QualType RetTy = getDerived().TransformType(E->getType());
10343 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010344 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010345 SubExprs.reserve(E->getNumSubExprs());
10346 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10347 SubExprs, &ArgumentChanged))
10348 return ExprError();
10349
10350 if (!getDerived().AlwaysRebuild() &&
10351 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010352 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010353
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010354 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010355 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010356}
Chad Rosier1dcde962012-08-08 18:46:20 +000010357
Douglas Gregora16548e2009-08-11 05:31:07 +000010358//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010359// Type reconstruction
10360//===----------------------------------------------------------------------===//
10361
Mike Stump11289f42009-09-09 15:08:12 +000010362template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010363QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10364 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010365 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010366 getDerived().getBaseEntity());
10367}
10368
Mike Stump11289f42009-09-09 15:08:12 +000010369template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010370QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10371 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010372 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010373 getDerived().getBaseEntity());
10374}
10375
Mike Stump11289f42009-09-09 15:08:12 +000010376template<typename Derived>
10377QualType
John McCall70dd5f62009-10-30 00:06:24 +000010378TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10379 bool WrittenAsLValue,
10380 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010381 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010382 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010383}
10384
10385template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010386QualType
John McCall70dd5f62009-10-30 00:06:24 +000010387TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10388 QualType ClassType,
10389 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010390 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10391 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010392}
10393
10394template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010395QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010396TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10397 ArrayType::ArraySizeModifier SizeMod,
10398 const llvm::APInt *Size,
10399 Expr *SizeExpr,
10400 unsigned IndexTypeQuals,
10401 SourceRange BracketsRange) {
10402 if (SizeExpr || !Size)
10403 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10404 IndexTypeQuals, BracketsRange,
10405 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010406
10407 QualType Types[] = {
10408 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10409 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10410 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010411 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010412 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010413 QualType SizeType;
10414 for (unsigned I = 0; I != NumTypes; ++I)
10415 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10416 SizeType = Types[I];
10417 break;
10418 }
Mike Stump11289f42009-09-09 15:08:12 +000010419
Eli Friedman9562f392012-01-25 23:20:27 +000010420 // Note that we can return a VariableArrayType here in the case where
10421 // the element type was a dependent VariableArrayType.
10422 IntegerLiteral *ArraySize
10423 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10424 /*FIXME*/BracketsRange.getBegin());
10425 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010426 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010427 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010428}
Mike Stump11289f42009-09-09 15:08:12 +000010429
Douglas Gregord6ff3322009-08-04 16:50:30 +000010430template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010431QualType
10432TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010433 ArrayType::ArraySizeModifier SizeMod,
10434 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010435 unsigned IndexTypeQuals,
10436 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010437 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010438 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010439}
10440
10441template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010442QualType
Mike Stump11289f42009-09-09 15:08:12 +000010443TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010444 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010445 unsigned IndexTypeQuals,
10446 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010447 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010448 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010449}
Mike Stump11289f42009-09-09 15:08:12 +000010450
Douglas Gregord6ff3322009-08-04 16:50:30 +000010451template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010452QualType
10453TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010454 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010455 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010456 unsigned IndexTypeQuals,
10457 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010458 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010459 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010460 IndexTypeQuals, BracketsRange);
10461}
10462
10463template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010464QualType
10465TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010466 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010467 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010468 unsigned IndexTypeQuals,
10469 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010470 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010471 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010472 IndexTypeQuals, BracketsRange);
10473}
10474
10475template<typename Derived>
10476QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010477 unsigned NumElements,
10478 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010479 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010480 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010481}
Mike Stump11289f42009-09-09 15:08:12 +000010482
Douglas Gregord6ff3322009-08-04 16:50:30 +000010483template<typename Derived>
10484QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10485 unsigned NumElements,
10486 SourceLocation AttributeLoc) {
10487 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10488 NumElements, true);
10489 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010490 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10491 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010492 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010493}
Mike Stump11289f42009-09-09 15:08:12 +000010494
Douglas Gregord6ff3322009-08-04 16:50:30 +000010495template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010496QualType
10497TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010498 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010499 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010500 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010501}
Mike Stump11289f42009-09-09 15:08:12 +000010502
Douglas Gregord6ff3322009-08-04 16:50:30 +000010503template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010504QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10505 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010506 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010507 const FunctionProtoType::ExtProtoInfo &EPI) {
10508 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010509 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010510 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010511 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010512}
Mike Stump11289f42009-09-09 15:08:12 +000010513
Douglas Gregord6ff3322009-08-04 16:50:30 +000010514template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010515QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10516 return SemaRef.Context.getFunctionNoProtoType(T);
10517}
10518
10519template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010520QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10521 assert(D && "no decl found");
10522 if (D->isInvalidDecl()) return QualType();
10523
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010524 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010525 TypeDecl *Ty;
10526 if (isa<UsingDecl>(D)) {
10527 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010528 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010529 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10530
10531 // A valid resolved using typename decl points to exactly one type decl.
10532 assert(++Using->shadow_begin() == Using->shadow_end());
10533 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010534
John McCallb96ec562009-12-04 22:46:56 +000010535 } else {
10536 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10537 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10538 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10539 }
10540
10541 return SemaRef.Context.getTypeDeclType(Ty);
10542}
10543
10544template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010545QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10546 SourceLocation Loc) {
10547 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010548}
10549
10550template<typename Derived>
10551QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10552 return SemaRef.Context.getTypeOfType(Underlying);
10553}
10554
10555template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010556QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10557 SourceLocation Loc) {
10558 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010559}
10560
10561template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010562QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10563 UnaryTransformType::UTTKind UKind,
10564 SourceLocation Loc) {
10565 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10566}
10567
10568template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010569QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010570 TemplateName Template,
10571 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010572 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010573 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010574}
Mike Stump11289f42009-09-09 15:08:12 +000010575
Douglas Gregor1135c352009-08-06 05:28:30 +000010576template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010577QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10578 SourceLocation KWLoc) {
10579 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10580}
10581
10582template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010583TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010584TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010585 bool TemplateKW,
10586 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010587 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010588 Template);
10589}
10590
10591template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010592TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010593TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10594 const IdentifierInfo &Name,
10595 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010596 QualType ObjectType,
10597 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010598 UnqualifiedId TemplateName;
10599 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010600 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010601 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010602 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010603 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010604 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010605 /*EnteringContext=*/false,
10606 Template);
John McCall31f82722010-11-12 08:19:04 +000010607 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010608}
Mike Stump11289f42009-09-09 15:08:12 +000010609
Douglas Gregora16548e2009-08-11 05:31:07 +000010610template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010611TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010612TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010613 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010614 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010615 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010616 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010617 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010618 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010619 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010620 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010621 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010622 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010623 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010624 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010625 /*EnteringContext=*/false,
10626 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010627 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010628}
Chad Rosier1dcde962012-08-08 18:46:20 +000010629
Douglas Gregor71395fa2009-11-04 00:56:37 +000010630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010631ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010632TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10633 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010634 Expr *OrigCallee,
10635 Expr *First,
10636 Expr *Second) {
10637 Expr *Callee = OrigCallee->IgnoreParenCasts();
10638 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010639
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010640 if (First->getObjectKind() == OK_ObjCProperty) {
10641 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10642 if (BinaryOperator::isAssignmentOp(Opc))
10643 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10644 First, Second);
10645 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10646 if (Result.isInvalid())
10647 return ExprError();
10648 First = Result.get();
10649 }
10650
10651 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10652 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10653 if (Result.isInvalid())
10654 return ExprError();
10655 Second = Result.get();
10656 }
10657
Douglas Gregora16548e2009-08-11 05:31:07 +000010658 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010659 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010660 if (!First->getType()->isOverloadableType() &&
10661 !Second->getType()->isOverloadableType())
10662 return getSema().CreateBuiltinArraySubscriptExpr(First,
10663 Callee->getLocStart(),
10664 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010665 } else if (Op == OO_Arrow) {
10666 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010667 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10668 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010669 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010670 // The argument is not of overloadable type, so try to create a
10671 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010672 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010673 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010674
John McCallb268a282010-08-23 23:25:46 +000010675 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010676 }
10677 } else {
John McCallb268a282010-08-23 23:25:46 +000010678 if (!First->getType()->isOverloadableType() &&
10679 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010680 // Neither of the arguments is an overloadable type, so try to
10681 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010682 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010683 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010684 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010685 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010687
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010688 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010689 }
10690 }
Mike Stump11289f42009-09-09 15:08:12 +000010691
10692 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010693 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010694 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010695
John McCallb268a282010-08-23 23:25:46 +000010696 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010697 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010698 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010699 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010700 // If we've resolved this to a particular non-member function, just call
10701 // that function. If we resolved it to a member function,
10702 // CreateOverloaded* will find that function for us.
10703 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10704 if (!isa<CXXMethodDecl>(ND))
10705 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010706 }
Mike Stump11289f42009-09-09 15:08:12 +000010707
Douglas Gregora16548e2009-08-11 05:31:07 +000010708 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010709 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010710 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010711
Douglas Gregora16548e2009-08-11 05:31:07 +000010712 // Create the overloaded operator invocation for unary operators.
10713 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010714 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010715 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010716 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010717 }
Mike Stump11289f42009-09-09 15:08:12 +000010718
Douglas Gregore9d62932011-07-15 16:25:15 +000010719 if (Op == OO_Subscript) {
10720 SourceLocation LBrace;
10721 SourceLocation RBrace;
10722
10723 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010724 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010725 LBrace = SourceLocation::getFromRawEncoding(
10726 NameLoc.CXXOperatorName.BeginOpNameLoc);
10727 RBrace = SourceLocation::getFromRawEncoding(
10728 NameLoc.CXXOperatorName.EndOpNameLoc);
10729 } else {
10730 LBrace = Callee->getLocStart();
10731 RBrace = OpLoc;
10732 }
10733
10734 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10735 First, Second);
10736 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010737
Douglas Gregora16548e2009-08-11 05:31:07 +000010738 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010739 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010740 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010741 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10742 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010744
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010745 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010746}
Mike Stump11289f42009-09-09 15:08:12 +000010747
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010748template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010749ExprResult
John McCallb268a282010-08-23 23:25:46 +000010750TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010751 SourceLocation OperatorLoc,
10752 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010753 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010754 TypeSourceInfo *ScopeType,
10755 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010756 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010757 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010758 QualType BaseType = Base->getType();
10759 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010760 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010761 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010762 !BaseType->getAs<PointerType>()->getPointeeType()
10763 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010764 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000010765 return SemaRef.BuildPseudoDestructorExpr(
10766 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
10767 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010768 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010769
Douglas Gregor678f90d2010-02-25 01:56:36 +000010770 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010771 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10772 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10773 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10774 NameInfo.setNamedTypeInfo(DestroyedType);
10775
Richard Smith8e4a3862012-05-15 06:15:11 +000010776 // The scope type is now known to be a valid nested name specifier
10777 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010778 if (ScopeType) {
10779 if (!ScopeType->getType()->getAs<TagType>()) {
10780 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10781 diag::err_expected_class_or_namespace)
10782 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10783 return ExprError();
10784 }
10785 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10786 CCLoc);
10787 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010788
Abramo Bagnara7945c982012-01-27 09:46:47 +000010789 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010790 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010791 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010792 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010793 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010794 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010795 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010796}
10797
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010798template<typename Derived>
10799StmtResult
10800TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010801 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010802 CapturedDecl *CD = S->getCapturedDecl();
10803 unsigned NumParams = CD->getNumParams();
10804 unsigned ContextParamPos = CD->getContextParamPosition();
10805 SmallVector<Sema::CapturedParamNameType, 4> Params;
10806 for (unsigned I = 0; I < NumParams; ++I) {
10807 if (I != ContextParamPos) {
10808 Params.push_back(
10809 std::make_pair(
10810 CD->getParam(I)->getName(),
10811 getDerived().TransformType(CD->getParam(I)->getType())));
10812 } else {
10813 Params.push_back(std::make_pair(StringRef(), QualType()));
10814 }
10815 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010816 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010817 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010818 StmtResult Body;
10819 {
10820 Sema::CompoundScopeRAII CompoundScope(getSema());
10821 Body = getDerived().TransformStmt(S->getCapturedStmt());
10822 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010823
10824 if (Body.isInvalid()) {
10825 getSema().ActOnCapturedRegionError();
10826 return StmtError();
10827 }
10828
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010829 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010830}
10831
Douglas Gregord6ff3322009-08-04 16:50:30 +000010832} // end namespace clang
10833
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010834#endif