blob: df0e4b316d7b3dc5104ac98608ff37c59abc96c1 [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);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000622
623 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000624 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000625 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
626 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 /// \brief Build a new array type given the element type, size
694 /// modifier, size of the array (if known), size expression, and index type
695 /// qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 QualType RebuildArrayType(QualType ElementType,
701 ArrayType::ArraySizeModifier SizeMod,
702 const llvm::APInt *Size,
703 Expr *SizeExpr,
704 unsigned IndexTypeQuals,
705 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000706
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// \brief Build a new constant array type given the element type, size
708 /// modifier, (known) size of the array, and index type qualifiers.
709 ///
710 /// By default, performs semantic analysis when building the array type.
711 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000712 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 ArrayType::ArraySizeModifier SizeMod,
714 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000715 unsigned IndexTypeQuals,
716 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 /// \brief Build a new incomplete array type given the element type, size
719 /// modifier, and index type qualifiers.
720 ///
721 /// By default, performs semantic analysis when building the array type.
722 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000723 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727
Mike Stump11289f42009-09-09 15:08:12 +0000728 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 /// size modifier, size expression, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000735 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
738
Mike Stump11289f42009-09-09 15:08:12 +0000739 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// size modifier, size expression, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000746 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 unsigned IndexTypeQuals,
748 SourceRange BracketsRange);
749
750 /// \brief Build a new vector type given the element type and
751 /// number of elements.
752 ///
753 /// By default, performs semantic analysis when building the vector type.
754 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000755 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000756 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 /// \brief Build a new extended vector type given the element type and
759 /// number of elements.
760 ///
761 /// By default, performs semantic analysis when building the vector type.
762 /// Subclasses may override this routine to provide different behavior.
763 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
764 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000765
766 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000767 /// given the element type and number of elements.
768 ///
769 /// By default, performs semantic analysis when building the vector type.
770 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000771 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000772 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000773 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775 /// \brief Build a new function type.
776 ///
777 /// By default, performs semantic analysis when building the function type.
778 /// Subclasses may override this routine to provide different behavior.
779 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000780 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000781 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000782
John McCall550e0c22009-10-21 00:40:46 +0000783 /// \brief Build a new unprototyped function type.
784 QualType RebuildFunctionNoProtoType(QualType ResultType);
785
John McCallb96ec562009-12-04 22:46:56 +0000786 /// \brief Rebuild an unresolved typename type, given the decl that
787 /// the UnresolvedUsingTypenameDecl was transformed to.
788 QualType RebuildUnresolvedUsingType(Decl *D);
789
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000791 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000792 return SemaRef.Context.getTypeDeclType(Typedef);
793 }
794
795 /// \brief Build a new class/struct/union type.
796 QualType RebuildRecordType(RecordDecl *Record) {
797 return SemaRef.Context.getTypeDeclType(Record);
798 }
799
800 /// \brief Build a new Enum type.
801 QualType RebuildEnumType(EnumDecl *Enum) {
802 return SemaRef.Context.getTypeDeclType(Enum);
803 }
John McCallfcc33b02009-09-05 00:15:47 +0000804
Mike Stump11289f42009-09-09 15:08:12 +0000805 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000806 ///
807 /// By default, performs semantic analysis when building the typeof type.
808 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000809 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810
Mike Stump11289f42009-09-09 15:08:12 +0000811 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000812 ///
813 /// By default, builds a new TypeOfType with the given underlying type.
814 QualType RebuildTypeOfType(QualType Underlying);
815
Alexis Hunte852b102011-05-24 22:41:36 +0000816 /// \brief Build a new unary transform type.
817 QualType RebuildUnaryTransformType(QualType BaseType,
818 UnaryTransformType::UTTKind UKind,
819 SourceLocation Loc);
820
Richard Smith74aeef52013-04-26 16:15:35 +0000821 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 ///
823 /// By default, performs semantic analysis when building the decltype type.
824 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000825 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000826
Richard Smith74aeef52013-04-26 16:15:35 +0000827 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000828 ///
829 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000830 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000831 // Note, IsDependent is always false here: we implicitly convert an 'auto'
832 // which has been deduced to a dependent type into an undeduced 'auto', so
833 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000834 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
835 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000836 }
837
Douglas Gregord6ff3322009-08-04 16:50:30 +0000838 /// \brief Build a new template specialization type.
839 ///
840 /// By default, performs semantic analysis when building the template
841 /// specialization type. Subclasses may override this routine to provide
842 /// different behavior.
843 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000844 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000846
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000847 /// \brief Build a new parenthesized type.
848 ///
849 /// By default, builds a new ParenType type from the inner type.
850 /// Subclasses may override this routine to provide different behavior.
851 QualType RebuildParenType(QualType InnerType) {
852 return SemaRef.Context.getParenType(InnerType);
853 }
854
Douglas Gregord6ff3322009-08-04 16:50:30 +0000855 /// \brief Build a new qualified name type.
856 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000857 /// By default, builds a new ElaboratedType type from the keyword,
858 /// the nested-name-specifier and the named type.
859 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000860 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
861 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000862 NestedNameSpecifierLoc QualifierLoc,
863 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000864 return SemaRef.Context.getElaboratedType(Keyword,
865 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000866 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000867 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000868
869 /// \brief Build a new typename type that refers to a template-id.
870 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000871 /// By default, builds a new DependentNameType type from the
872 /// nested-name-specifier and the given type. Subclasses may override
873 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000874 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 ElaboratedTypeKeyword Keyword,
876 NestedNameSpecifierLoc QualifierLoc,
877 const IdentifierInfo *Name,
878 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000879 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000880 // Rebuild the template name.
881 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000882 CXXScopeSpec SS;
883 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000884 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000885 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
886 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000887
Douglas Gregora7a795b2011-03-01 20:11:18 +0000888 if (InstName.isNull())
889 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000890
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 // If it's still dependent, make a dependent specialization.
892 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000893 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
894 QualifierLoc.getNestedNameSpecifier(),
895 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000897
Douglas Gregora7a795b2011-03-01 20:11:18 +0000898 // Otherwise, make an elaborated type wrapping a non-dependent
899 // specialization.
900 QualType T =
901 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
902 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000903
Craig Topperc3ec1492014-05-26 06:22:03 +0000904 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000905 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000906
907 return SemaRef.Context.getElaboratedType(Keyword,
908 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 T);
910 }
911
Douglas Gregord6ff3322009-08-04 16:50:30 +0000912 /// \brief Build a new typename type that refers to an identifier.
913 ///
914 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000915 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000916 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000917 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000918 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000919 NestedNameSpecifierLoc QualifierLoc,
920 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000921 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000922 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000923 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000924
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000925 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 // If the name is still dependent, just build a new dependent name type.
927 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000928 return SemaRef.Context.getDependentNameType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000930 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 }
932
Abramo Bagnara6150c882010-05-11 21:36:43 +0000933 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000934 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000935 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000936
937 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
938
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000940 // into a non-dependent elaborated-type-specifier. Find the tag we're
941 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
944 if (!DC)
945 return QualType();
946
John McCallbf8c5192010-05-27 06:40:31 +0000947 if (SemaRef.RequireCompleteDeclContext(SS, DC))
948 return QualType();
949
Craig Topperc3ec1492014-05-26 06:22:03 +0000950 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000951 SemaRef.LookupQualifiedName(Result, DC);
952 switch (Result.getResultKind()) {
953 case LookupResult::NotFound:
954 case LookupResult::NotFoundInCurrentInstantiation:
955 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000956
Douglas Gregore677daf2010-03-31 22:19:08 +0000957 case LookupResult::Found:
958 Tag = Result.getAsSingle<TagDecl>();
959 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000960
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 case LookupResult::FoundOverloaded:
962 case LookupResult::FoundUnresolvedValue:
963 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000964
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 case LookupResult::Ambiguous:
966 // Let the LookupResult structure handle ambiguities.
967 return QualType();
968 }
969
970 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000971 // Check where the name exists but isn't a tag type and use that to emit
972 // better diagnostics.
973 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
974 SemaRef.LookupQualifiedName(Result, DC);
975 switch (Result.getResultKind()) {
976 case LookupResult::Found:
977 case LookupResult::FoundOverloaded:
978 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000979 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000980 unsigned Kind = 0;
981 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000982 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
983 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
985 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
986 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000987 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000988 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000989 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000990 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000991 break;
992 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000993 return QualType();
994 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000995
Richard Trieucaa33d32011-06-10 03:11:26 +0000996 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
997 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000998 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000999 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1000 return QualType();
1001 }
1002
1003 // Build the elaborated-type-specifier type.
1004 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001005 return SemaRef.Context.getElaboratedType(Keyword,
1006 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001007 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001008 }
Mike Stump11289f42009-09-09 15:08:12 +00001009
Douglas Gregor822d0302011-01-12 17:07:58 +00001010 /// \brief Build a new pack expansion type.
1011 ///
1012 /// By default, builds a new PackExpansionType type from the given pattern.
1013 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001014 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001015 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001016 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001017 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001018 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1019 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001020 }
1021
Eli Friedman0dfb8892011-10-06 23:00:33 +00001022 /// \brief Build a new atomic type given its value type.
1023 ///
1024 /// By default, performs semantic analysis when building the atomic type.
1025 /// Subclasses may override this routine to provide different behavior.
1026 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1027
Douglas Gregor71dc5092009-08-06 06:41:21 +00001028 /// \brief Build a new template name given a nested name specifier, a flag
1029 /// indicating whether the "template" keyword was provided, and the template
1030 /// that the template name refers to.
1031 ///
1032 /// By default, builds the new template name directly. Subclasses may override
1033 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001034 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001035 bool TemplateKW,
1036 TemplateDecl *Template);
1037
Douglas Gregor71dc5092009-08-06 06:41:21 +00001038 /// \brief Build a new template name given a nested name specifier and the
1039 /// name that is referred to as a template.
1040 ///
1041 /// By default, performs semantic analysis to determine whether the name can
1042 /// be resolved to a specific template, then builds the appropriate kind of
1043 /// template name. Subclasses may override this routine to provide different
1044 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001045 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1046 const IdentifierInfo &Name,
1047 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001048 QualType ObjectType,
1049 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregor71395fa2009-11-04 00:56:37 +00001051 /// \brief Build a new template name given a nested name specifier and the
1052 /// overloaded operator name that is referred to as a template.
1053 ///
1054 /// By default, performs semantic analysis to determine whether the name can
1055 /// be resolved to a specific template, then builds the appropriate kind of
1056 /// template name. Subclasses may override this routine to provide different
1057 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001058 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001059 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001060 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001061 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001062
1063 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001064 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001065 ///
1066 /// By default, performs semantic analysis to determine whether the name can
1067 /// be resolved to a specific template, then builds the appropriate kind of
1068 /// template name. Subclasses may override this routine to provide different
1069 /// behavior.
1070 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1071 const TemplateArgument &ArgPack) {
1072 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1073 }
1074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new compound statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 MultiStmtArg Statements,
1081 SourceLocation RBraceLoc,
1082 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001083 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 IsStmtExpr);
1085 }
1086
1087 /// \brief Build a new case statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001091 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001092 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001094 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001096 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 ColonLoc);
1098 }
Mike Stump11289f42009-09-09 15:08:12 +00001099
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 /// \brief Attach the body to a new case statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001104 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001105 getSema().ActOnCaseStmtBody(S, Body);
1106 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 }
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 /// \brief Build a new default statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001113 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Stmt *SubStmt) {
1116 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001117 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 }
Mike Stump11289f42009-09-09 15:08:12 +00001119
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 /// \brief Build a new label statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001124 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1125 SourceLocation ColonLoc, Stmt *SubStmt) {
1126 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001127 }
Mike Stump11289f42009-09-09 15:08:12 +00001128
Richard Smithc202b282012-04-14 00:33:13 +00001129 /// \brief Build a new label statement.
1130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001133 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1134 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001135 Stmt *SubStmt) {
1136 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1137 }
1138
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 /// \brief Build a new "if" statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001143 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001144 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001146 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 }
Mike Stump11289f42009-09-09 15:08:12 +00001148
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 /// \brief Start building a new switch statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001153 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001154 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001155 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001156 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 /// \brief Attach the body to the switch statement.
1160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001163 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001164 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001165 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 }
1167
1168 /// \brief Build a new while statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1173 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001174 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001175 }
Mike Stump11289f42009-09-09 15:08:12 +00001176
Douglas Gregorebe10102009-08-20 07:17:43 +00001177 /// \brief Build a new do-while statement.
1178 ///
1179 /// By default, performs semantic analysis to build the new statement.
1180 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001181 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001182 SourceLocation WhileLoc, SourceLocation LParenLoc,
1183 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001184 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1185 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 }
1187
1188 /// \brief Build a new for statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001192 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001193 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001194 VarDecl *CondVar, Sema::FullExprArg Inc,
1195 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001196 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001197 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 /// \brief Build a new goto statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001204 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1205 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001206 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new indirect goto statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001213 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001214 SourceLocation StarLoc,
1215 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001216 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 /// \brief Build a new return statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001223 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001224 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 }
Mike Stump11289f42009-09-09 15:08:12 +00001226
Douglas Gregorebe10102009-08-20 07:17:43 +00001227 /// \brief Build a new declaration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001231 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001232 SourceLocation StartLoc, SourceLocation EndLoc) {
1233 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001234 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 }
Mike Stump11289f42009-09-09 15:08:12 +00001236
Anders Carlssonaaeef072010-01-24 05:50:09 +00001237 /// \brief Build a new inline asm statement.
1238 ///
1239 /// By default, performs semantic analysis to build the new statement.
1240 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001241 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1242 bool IsVolatile, unsigned NumOutputs,
1243 unsigned NumInputs, IdentifierInfo **Names,
1244 MultiExprArg Constraints, MultiExprArg Exprs,
1245 Expr *AsmString, MultiExprArg Clobbers,
1246 SourceLocation RParenLoc) {
1247 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1248 NumInputs, Names, Constraints, Exprs,
1249 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001250 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001251
Chad Rosier32503022012-06-11 20:47:18 +00001252 /// \brief Build a new MS style inline asm statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001256 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001257 ArrayRef<Token> AsmToks,
1258 StringRef AsmString,
1259 unsigned NumOutputs, unsigned NumInputs,
1260 ArrayRef<StringRef> Constraints,
1261 ArrayRef<StringRef> Clobbers,
1262 ArrayRef<Expr*> Exprs,
1263 SourceLocation EndLoc) {
1264 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1265 NumOutputs, NumInputs,
1266 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001267 }
1268
James Dennett2a4d13c2012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001273 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001274 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001275 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001277 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001278 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 }
1280
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001281 /// \brief Rebuild an Objective-C exception declaration.
1282 ///
1283 /// By default, performs semantic analysis to build the new declaration.
1284 /// Subclasses may override this routine to provide different behavior.
1285 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1286 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001287 return getSema().BuildObjCExceptionDecl(TInfo, T,
1288 ExceptionDecl->getInnerLocStart(),
1289 ExceptionDecl->getLocation(),
1290 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001292
James Dennett2a4d13c2012-06-15 07:13:21 +00001293 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001294 ///
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001297 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001298 SourceLocation RParenLoc,
1299 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001300 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001301 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001302 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001304
James Dennett2a4d13c2012-06-15 07:13:21 +00001305 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001306 ///
1307 /// By default, performs semantic analysis to build the new statement.
1308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001309 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001310 Stmt *Body) {
1311 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001319 Expr *Operand) {
1320 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001322
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001323 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001324 ///
1325 /// By default, performs semantic analysis to build the new statement.
1326 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001327 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001328 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001329 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001330 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001331 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001332 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1333 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001334 }
1335
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001336 /// \brief Build a new OpenMP 'if' clause.
1337 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001338 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001339 /// Subclasses may override this routine to provide different behavior.
1340 OMPClause *RebuildOMPIfClause(Expr *Condition,
1341 SourceLocation StartLoc,
1342 SourceLocation LParenLoc,
1343 SourceLocation EndLoc) {
1344 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1345 LParenLoc, EndLoc);
1346 }
1347
Alexey Bataev3778b602014-07-17 07:32:53 +00001348 /// \brief Build a new OpenMP 'final' clause.
1349 ///
1350 /// By default, performs semantic analysis to build the new OpenMP clause.
1351 /// Subclasses may override this routine to provide different behavior.
1352 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1353 SourceLocation LParenLoc,
1354 SourceLocation EndLoc) {
1355 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1356 EndLoc);
1357 }
1358
Alexey Bataev568a8332014-03-06 06:15:19 +00001359 /// \brief Build a new OpenMP 'num_threads' clause.
1360 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001361 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001362 /// Subclasses may override this routine to provide different behavior.
1363 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1364 SourceLocation StartLoc,
1365 SourceLocation LParenLoc,
1366 SourceLocation EndLoc) {
1367 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1368 LParenLoc, EndLoc);
1369 }
1370
Alexey Bataev62c87d22014-03-21 04:51:18 +00001371 /// \brief Build a new OpenMP 'safelen' clause.
1372 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001373 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001374 /// Subclasses may override this routine to provide different behavior.
1375 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1376 SourceLocation LParenLoc,
1377 SourceLocation EndLoc) {
1378 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1379 }
1380
Alexander Musman8bd31e62014-05-27 15:12:19 +00001381 /// \brief Build a new OpenMP 'collapse' clause.
1382 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001383 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001384 /// Subclasses may override this routine to provide different behavior.
1385 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1386 SourceLocation LParenLoc,
1387 SourceLocation EndLoc) {
1388 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1389 EndLoc);
1390 }
1391
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001392 /// \brief Build a new OpenMP 'default' clause.
1393 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001394 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001395 /// Subclasses may override this routine to provide different behavior.
1396 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1397 SourceLocation KindKwLoc,
1398 SourceLocation StartLoc,
1399 SourceLocation LParenLoc,
1400 SourceLocation EndLoc) {
1401 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1402 StartLoc, LParenLoc, EndLoc);
1403 }
1404
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001405 /// \brief Build a new OpenMP 'proc_bind' clause.
1406 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001407 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001408 /// Subclasses may override this routine to provide different behavior.
1409 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1410 SourceLocation KindKwLoc,
1411 SourceLocation StartLoc,
1412 SourceLocation LParenLoc,
1413 SourceLocation EndLoc) {
1414 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1415 StartLoc, LParenLoc, EndLoc);
1416 }
1417
Alexey Bataev56dafe82014-06-20 07:16:17 +00001418 /// \brief Build a new OpenMP 'schedule' clause.
1419 ///
1420 /// By default, performs semantic analysis to build the new OpenMP clause.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1423 Expr *ChunkSize,
1424 SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation KindLoc,
1427 SourceLocation CommaLoc,
1428 SourceLocation EndLoc) {
1429 return getSema().ActOnOpenMPScheduleClause(
1430 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1431 }
1432
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001433 /// \brief Build a new OpenMP 'private' clause.
1434 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001435 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001436 /// Subclasses may override this routine to provide different behavior.
1437 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1438 SourceLocation StartLoc,
1439 SourceLocation LParenLoc,
1440 SourceLocation EndLoc) {
1441 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1442 EndLoc);
1443 }
1444
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001445 /// \brief Build a new OpenMP 'firstprivate' clause.
1446 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001447 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001448 /// Subclasses may override this routine to provide different behavior.
1449 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1450 SourceLocation StartLoc,
1451 SourceLocation LParenLoc,
1452 SourceLocation EndLoc) {
1453 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1454 EndLoc);
1455 }
1456
Alexander Musman1bb328c2014-06-04 13:06:39 +00001457 /// \brief Build a new OpenMP 'lastprivate' clause.
1458 ///
1459 /// By default, performs semantic analysis to build the new OpenMP clause.
1460 /// Subclasses may override this routine to provide different behavior.
1461 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1462 SourceLocation StartLoc,
1463 SourceLocation LParenLoc,
1464 SourceLocation EndLoc) {
1465 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1466 EndLoc);
1467 }
1468
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001469 /// \brief Build a new OpenMP 'shared' clause.
1470 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001471 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001472 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001473 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 SourceLocation EndLoc) {
1477 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1478 EndLoc);
1479 }
1480
Alexey Bataevc5e02582014-06-16 07:08:35 +00001481 /// \brief Build a new OpenMP 'reduction' clause.
1482 ///
1483 /// By default, performs semantic analysis to build the new statement.
1484 /// Subclasses may override this routine to provide different behavior.
1485 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1486 SourceLocation StartLoc,
1487 SourceLocation LParenLoc,
1488 SourceLocation ColonLoc,
1489 SourceLocation EndLoc,
1490 CXXScopeSpec &ReductionIdScopeSpec,
1491 const DeclarationNameInfo &ReductionId) {
1492 return getSema().ActOnOpenMPReductionClause(
1493 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1494 ReductionId);
1495 }
1496
Alexander Musman8dba6642014-04-22 13:09:42 +00001497 /// \brief Build a new OpenMP 'linear' clause.
1498 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001499 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001500 /// Subclasses may override this routine to provide different behavior.
1501 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1502 SourceLocation StartLoc,
1503 SourceLocation LParenLoc,
1504 SourceLocation ColonLoc,
1505 SourceLocation EndLoc) {
1506 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1507 ColonLoc, EndLoc);
1508 }
1509
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001510 /// \brief Build a new OpenMP 'aligned' clause.
1511 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001512 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001513 /// Subclasses may override this routine to provide different behavior.
1514 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1515 SourceLocation StartLoc,
1516 SourceLocation LParenLoc,
1517 SourceLocation ColonLoc,
1518 SourceLocation EndLoc) {
1519 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1520 LParenLoc, ColonLoc, EndLoc);
1521 }
1522
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001523 /// \brief Build a new OpenMP 'copyin' clause.
1524 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001525 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001526 /// Subclasses may override this routine to provide different behavior.
1527 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1528 SourceLocation StartLoc,
1529 SourceLocation LParenLoc,
1530 SourceLocation EndLoc) {
1531 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1532 EndLoc);
1533 }
1534
Alexey Bataevbae9a792014-06-27 10:37:06 +00001535 /// \brief Build a new OpenMP 'copyprivate' clause.
1536 ///
1537 /// By default, performs semantic analysis to build the new OpenMP clause.
1538 /// Subclasses may override this routine to provide different behavior.
1539 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1540 SourceLocation StartLoc,
1541 SourceLocation LParenLoc,
1542 SourceLocation EndLoc) {
1543 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1544 EndLoc);
1545 }
1546
Alexey Bataev6125da92014-07-21 11:26:11 +00001547 /// \brief Build a new OpenMP 'flush' pseudo clause.
1548 ///
1549 /// By default, performs semantic analysis to build the new OpenMP clause.
1550 /// Subclasses may override this routine to provide different behavior.
1551 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1552 SourceLocation StartLoc,
1553 SourceLocation LParenLoc,
1554 SourceLocation EndLoc) {
1555 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1556 EndLoc);
1557 }
1558
James Dennett2a4d13c2012-06-15 07:13:21 +00001559 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001560 ///
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
1563 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1564 Expr *object) {
1565 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1566 }
1567
James Dennett2a4d13c2012-06-15 07:13:21 +00001568 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001569 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001570 /// By default, performs semantic analysis to build the new statement.
1571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001573 Expr *Object, Stmt *Body) {
1574 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001575 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001576
James Dennett2a4d13c2012-06-15 07:13:21 +00001577 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001578 ///
1579 /// By default, performs semantic analysis to build the new statement.
1580 /// Subclasses may override this routine to provide different behavior.
1581 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1582 Stmt *Body) {
1583 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1584 }
John McCall53848232011-07-27 01:07:15 +00001585
Douglas Gregorf68a5082010-04-22 23:10:45 +00001586 /// \brief Build a new Objective-C fast enumeration statement.
1587 ///
1588 /// By default, performs semantic analysis to build the new statement.
1589 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001590 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001591 Stmt *Element,
1592 Expr *Collection,
1593 SourceLocation RParenLoc,
1594 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001595 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001596 Element,
John McCallb268a282010-08-23 23:25:46 +00001597 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001598 RParenLoc);
1599 if (ForEachStmt.isInvalid())
1600 return StmtError();
1601
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001602 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001604
Douglas Gregorebe10102009-08-20 07:17:43 +00001605 /// \brief Build a new C++ exception declaration.
1606 ///
1607 /// By default, performs semantic analysis to build the new decaration.
1608 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001609 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001610 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001611 SourceLocation StartLoc,
1612 SourceLocation IdLoc,
1613 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001614 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001615 StartLoc, IdLoc, Id);
1616 if (Var)
1617 getSema().CurContext->addDecl(Var);
1618 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001619 }
1620
1621 /// \brief Build a new C++ catch statement.
1622 ///
1623 /// By default, performs semantic analysis to build the new statement.
1624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001625 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001626 VarDecl *ExceptionDecl,
1627 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001628 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1629 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001630 }
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregorebe10102009-08-20 07:17:43 +00001632 /// \brief Build a new C++ try statement.
1633 ///
1634 /// By default, performs semantic analysis to build the new statement.
1635 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001636 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1637 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001638 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001639 }
Mike Stump11289f42009-09-09 15:08:12 +00001640
Richard Smith02e85f32011-04-14 22:09:26 +00001641 /// \brief Build a new C++0x range-based for statement.
1642 ///
1643 /// By default, performs semantic analysis to build the new statement.
1644 /// Subclasses may override this routine to provide different behavior.
1645 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1646 SourceLocation ColonLoc,
1647 Stmt *Range, Stmt *BeginEnd,
1648 Expr *Cond, Expr *Inc,
1649 Stmt *LoopVar,
1650 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001651 // If we've just learned that the range is actually an Objective-C
1652 // collection, treat this as an Objective-C fast enumeration loop.
1653 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1654 if (RangeStmt->isSingleDecl()) {
1655 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001656 if (RangeVar->isInvalidDecl())
1657 return StmtError();
1658
Douglas Gregorf7106af2013-04-08 18:40:13 +00001659 Expr *RangeExpr = RangeVar->getInit();
1660 if (!RangeExpr->isTypeDependent() &&
1661 RangeExpr->getType()->isObjCObjectPointerType())
1662 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1663 RParenLoc);
1664 }
1665 }
1666 }
1667
Richard Smith02e85f32011-04-14 22:09:26 +00001668 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001669 Cond, Inc, LoopVar, RParenLoc,
1670 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001671 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001672
1673 /// \brief Build a new C++0x range-based for statement.
1674 ///
1675 /// By default, performs semantic analysis to build the new statement.
1676 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001677 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001678 bool IsIfExists,
1679 NestedNameSpecifierLoc QualifierLoc,
1680 DeclarationNameInfo NameInfo,
1681 Stmt *Nested) {
1682 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1683 QualifierLoc, NameInfo, Nested);
1684 }
1685
Richard Smith02e85f32011-04-14 22:09:26 +00001686 /// \brief Attach body to a C++0x range-based for statement.
1687 ///
1688 /// By default, performs semantic analysis to finish the new statement.
1689 /// Subclasses may override this routine to provide different behavior.
1690 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1691 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1692 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001693
David Majnemerfad8f482013-10-15 09:33:02 +00001694 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001695 Stmt *TryBlock, Stmt *Handler) {
1696 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001697 }
1698
David Majnemerfad8f482013-10-15 09:33:02 +00001699 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001700 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001701 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001702 }
1703
David Majnemerfad8f482013-10-15 09:33:02 +00001704 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001705 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001706 }
1707
Alexey Bataevec474782014-10-09 08:45:04 +00001708 /// \brief Build a new predefined expression.
1709 ///
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
1712 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1713 PredefinedExpr::IdentType IT) {
1714 return getSema().BuildPredefinedExpr(Loc, IT);
1715 }
1716
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 /// \brief Build a new expression that references a declaration.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001721 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001722 LookupResult &R,
1723 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001724 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1725 }
1726
1727
1728 /// \brief Build a new expression that references a declaration.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001732 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001733 ValueDecl *VD,
1734 const DeclarationNameInfo &NameInfo,
1735 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001736 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001737 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001738
1739 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001740
1741 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 }
Mike Stump11289f42009-09-09 15:08:12 +00001743
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001745 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001748 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001750 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
1752
Douglas Gregorad8a3362009-09-04 17:36:40 +00001753 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001758 SourceLocation OperatorLoc,
1759 bool isArrow,
1760 CXXScopeSpec &SS,
1761 TypeSourceInfo *ScopeType,
1762 SourceLocation CCLoc,
1763 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001764 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001765
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001767 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// By default, performs semantic analysis to build the new expression.
1769 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001770 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001771 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001772 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001773 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 }
Mike Stump11289f42009-09-09 15:08:12 +00001775
Douglas Gregor882211c2010-04-28 22:16:22 +00001776 /// \brief Build a new builtin offsetof expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001781 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001782 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001783 unsigned NumComponents,
1784 SourceLocation RParenLoc) {
1785 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1786 NumComponents, RParenLoc);
1787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001788
1789 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001790 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001791 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001794 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1795 SourceLocation OpLoc,
1796 UnaryExprOrTypeTrait ExprKind,
1797 SourceRange R) {
1798 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 }
1800
Peter Collingbournee190dee2011-03-11 19:24:49 +00001801 /// \brief Build a new sizeof, alignof or vec step expression with an
1802 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001803 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001806 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1807 UnaryExprOrTypeTrait ExprKind,
1808 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001809 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001810 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001813
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001814 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 }
Mike Stump11289f42009-09-09 15:08:12 +00001816
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001818 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001823 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001825 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001826 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 RBracketLoc);
1828 }
1829
1830 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001831 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001836 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001837 Expr *ExecConfig = nullptr) {
1838 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001839 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 }
1841
1842 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001843 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001847 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001848 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001849 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001850 const DeclarationNameInfo &MemberNameInfo,
1851 ValueDecl *Member,
1852 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001853 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001854 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001855 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1856 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001857 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001858 // We have a reference to an unnamed field. This is always the
1859 // base of an anonymous struct/union member access, i.e. the
1860 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001861 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001862 assert(Member->getType()->isRecordType() &&
1863 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001864
Richard Smithcab9a7d2011-10-26 19:06:56 +00001865 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001866 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001867 QualifierLoc.getNestedNameSpecifier(),
1868 FoundDecl, Member);
1869 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001870 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001871 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001872 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001873 MemberExpr *ME = new (getSema().Context)
1874 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1875 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001876 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001877 }
Mike Stump11289f42009-09-09 15:08:12 +00001878
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001879 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001880 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001881
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001882 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001883 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001884
John McCall16df1e52010-03-30 21:47:33 +00001885 // FIXME: this involves duplicating earlier analysis in a lot of
1886 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001887 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001888 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001889 R.resolveKind();
1890
John McCallb268a282010-08-23 23:25:46 +00001891 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001892 SS, TemplateKWLoc,
1893 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001894 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 }
Mike Stump11289f42009-09-09 15:08:12 +00001896
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001898 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 /// By default, performs semantic analysis to build the new expression.
1900 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001901 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001902 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001903 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001904 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 }
1906
1907 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001908 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001911 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001912 SourceLocation QuestionLoc,
1913 Expr *LHS,
1914 SourceLocation ColonLoc,
1915 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001916 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1917 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 }
1919
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001921 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001924 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001925 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001927 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001928 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001929 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 }
Mike Stump11289f42009-09-09 15:08:12 +00001931
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001933 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001936 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001937 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001939 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001940 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001941 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 }
Mike Stump11289f42009-09-09 15:08:12 +00001943
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001945 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001948 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 SourceLocation OpLoc,
1950 SourceLocation AccessorLoc,
1951 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001952
John McCall10eae182009-11-30 22:42:35 +00001953 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001954 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001955 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001956 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001957 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001958 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001959 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001960 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 }
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001964 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001967 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001968 MultiExprArg Inits,
1969 SourceLocation RBraceLoc,
1970 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001971 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001972 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001973 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001974 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001975
Douglas Gregord3d93062009-11-09 17:16:50 +00001976 // Patch in the result type we were given, which may have been computed
1977 // when the initial InitListExpr was built.
1978 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1979 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001980 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 }
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001984 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 MultiExprArg ArrayExprs,
1989 SourceLocation EqualOrColonLoc,
1990 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001991 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001992 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001994 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001996 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001997
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001998 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 }
Mike Stump11289f42009-09-09 15:08:12 +00002000
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002002 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 /// By default, builds the implicit value initialization without performing
2004 /// any semantic analysis. Subclasses may override this routine to provide
2005 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002006 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002007 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002015 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002016 SourceLocation RParenLoc) {
2017 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002018 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002019 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 }
2021
2022 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002023 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002026 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002027 MultiExprArg SubExprs,
2028 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002029 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 }
Mike Stump11289f42009-09-09 15:08:12 +00002031
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002033 ///
2034 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 /// rather than attempting to map the label statement itself.
2036 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002037 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002038 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002039 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002047 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002049 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 }
Mike Stump11289f42009-09-09 15:08:12 +00002051
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// \brief Build a new __builtin_choose_expr expression.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002056 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002057 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 SourceLocation RParenLoc) {
2059 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002060 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 RParenLoc);
2062 }
Mike Stump11289f42009-09-09 15:08:12 +00002063
Peter Collingbourne91147592011-04-15 00:35:48 +00002064 /// \brief Build a new generic selection expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
2068 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2069 SourceLocation DefaultLoc,
2070 SourceLocation RParenLoc,
2071 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002072 ArrayRef<TypeSourceInfo *> Types,
2073 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002074 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002075 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002076 }
2077
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 /// \brief Build a new overloaded operator call expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// The semantic analysis provides the behavior of template instantiation,
2082 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002083 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 /// argument-dependent lookup, etc. Subclasses may override this routine to
2085 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002086 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002088 Expr *Callee,
2089 Expr *First,
2090 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002091
2092 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 /// reinterpret_cast.
2094 ///
2095 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002096 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002098 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 Stmt::StmtClass Class,
2100 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002101 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 SourceLocation RAngleLoc,
2103 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002104 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 SourceLocation RParenLoc) {
2106 switch (Class) {
2107 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002108 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002109 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002110 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002111
2112 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002113 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002114 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002115 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002116
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002118 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002119 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002120 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002122
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002124 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002125 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002126 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002129 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 }
Mike Stump11289f42009-09-09 15:08:12 +00002132
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 /// \brief Build a new C++ static_cast expression.
2134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002139 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 SourceLocation RAngleLoc,
2141 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002144 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002145 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002146 SourceRange(LAngleLoc, RAngleLoc),
2147 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 }
2149
2150 /// \brief Build a new C++ dynamic_cast expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002154 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002156 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 SourceLocation RAngleLoc,
2158 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002159 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002161 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002162 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002163 SourceRange(LAngleLoc, RAngleLoc),
2164 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 }
2166
2167 /// \brief Build a new C++ reinterpret_cast expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002171 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002173 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 SourceLocation RAngleLoc,
2175 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002176 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002178 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002179 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002180 SourceRange(LAngleLoc, RAngleLoc),
2181 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 }
2183
2184 /// \brief Build a new C++ const_cast expression.
2185 ///
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002190 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SourceLocation RAngleLoc,
2192 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002193 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002195 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002196 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002197 SourceRange(LAngleLoc, RAngleLoc),
2198 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 }
Mike Stump11289f42009-09-09 15:08:12 +00002200
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 /// \brief Build a new C++ functional-style cast expression.
2202 ///
2203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002205 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2206 SourceLocation LParenLoc,
2207 Expr *Sub,
2208 SourceLocation RParenLoc) {
2209 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002210 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 RParenLoc);
2212 }
Mike Stump11289f42009-09-09 15:08:12 +00002213
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 /// \brief Build a new C++ typeid(type) expression.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002218 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002219 SourceLocation TypeidLoc,
2220 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002222 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002223 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 }
Mike Stump11289f42009-09-09 15:08:12 +00002225
Francois Pichet9f4f2072010-09-08 12:20:18 +00002226
Douglas Gregora16548e2009-08-11 05:31:07 +00002227 /// \brief Build a new C++ typeid(expr) expression.
2228 ///
2229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002231 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002232 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002233 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002235 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002236 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002237 }
2238
Francois Pichet9f4f2072010-09-08 12:20:18 +00002239 /// \brief Build a new C++ __uuidof(type) expression.
2240 ///
2241 /// By default, performs semantic analysis to build the new expression.
2242 /// Subclasses may override this routine to provide different behavior.
2243 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2244 SourceLocation TypeidLoc,
2245 TypeSourceInfo *Operand,
2246 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002247 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002248 RParenLoc);
2249 }
2250
2251 /// \brief Build a new C++ __uuidof(expr) expression.
2252 ///
2253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
2255 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2256 SourceLocation TypeidLoc,
2257 Expr *Operand,
2258 SourceLocation RParenLoc) {
2259 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2260 RParenLoc);
2261 }
2262
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 /// \brief Build a new C++ "this" expression.
2264 ///
2265 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002266 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002268 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002269 QualType ThisType,
2270 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002271 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002272 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 }
2274
2275 /// \brief Build a new C++ throw expression.
2276 ///
2277 /// By default, performs semantic analysis to build the new expression.
2278 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002279 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2280 bool IsThrownVariableInScope) {
2281 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 }
2283
2284 /// \brief Build a new C++ default-argument expression.
2285 ///
2286 /// By default, builds a new default-argument expression, which does not
2287 /// require any semantic analysis. Subclasses may override this routine to
2288 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002289 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002290 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002291 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 }
2293
Richard Smith852c9db2013-04-20 22:23:05 +00002294 /// \brief Build a new C++11 default-initialization expression.
2295 ///
2296 /// By default, builds a new default field initialization expression, which
2297 /// does not require any semantic analysis. Subclasses may override this
2298 /// routine to provide different behavior.
2299 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2300 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002301 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002302 }
2303
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 /// \brief Build a new C++ zero-initialization expression.
2305 ///
2306 /// By default, performs semantic analysis to build the new expression.
2307 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002308 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2309 SourceLocation LParenLoc,
2310 SourceLocation RParenLoc) {
2311 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002312 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 }
Mike Stump11289f42009-09-09 15:08:12 +00002314
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 /// \brief Build a new C++ "new" expression.
2316 ///
2317 /// By default, performs semantic analysis to build the new expression.
2318 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002319 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002320 bool UseGlobal,
2321 SourceLocation PlacementLParen,
2322 MultiExprArg PlacementArgs,
2323 SourceLocation PlacementRParen,
2324 SourceRange TypeIdParens,
2325 QualType AllocatedType,
2326 TypeSourceInfo *AllocatedTypeInfo,
2327 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002328 SourceRange DirectInitRange,
2329 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002330 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002332 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002334 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002335 AllocatedType,
2336 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002337 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002338 DirectInitRange,
2339 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 }
Mike Stump11289f42009-09-09 15:08:12 +00002341
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 /// \brief Build a new C++ "delete" expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002346 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 bool IsGlobalDelete,
2348 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002349 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002351 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 }
Mike Stump11289f42009-09-09 15:08:12 +00002353
Douglas Gregor29c42f22012-02-24 07:38:34 +00002354 /// \brief Build a new type trait expression.
2355 ///
2356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
2358 ExprResult RebuildTypeTrait(TypeTrait Trait,
2359 SourceLocation StartLoc,
2360 ArrayRef<TypeSourceInfo *> Args,
2361 SourceLocation RParenLoc) {
2362 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002364
John Wiegley6242b6a2011-04-28 00:16:57 +00002365 /// \brief Build a new array type trait expression.
2366 ///
2367 /// By default, performs semantic analysis to build the new expression.
2368 /// Subclasses may override this routine to provide different behavior.
2369 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2370 SourceLocation StartLoc,
2371 TypeSourceInfo *TSInfo,
2372 Expr *DimExpr,
2373 SourceLocation RParenLoc) {
2374 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2375 }
2376
John Wiegleyf9f65842011-04-25 06:54:41 +00002377 /// \brief Build a new expression trait expression.
2378 ///
2379 /// By default, performs semantic analysis to build the new expression.
2380 /// Subclasses may override this routine to provide different behavior.
2381 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2382 SourceLocation StartLoc,
2383 Expr *Queried,
2384 SourceLocation RParenLoc) {
2385 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2386 }
2387
Mike Stump11289f42009-09-09 15:08:12 +00002388 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 /// expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002393 ExprResult RebuildDependentScopeDeclRefExpr(
2394 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002395 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002396 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002397 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002398 bool IsAddressOfOperand,
2399 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002401 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002402
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002403 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002404 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2405 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002406
Reid Kleckner32506ed2014-06-12 23:03:48 +00002407 return getSema().BuildQualifiedDeclarationNameExpr(
2408 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 }
2410
2411 /// \brief Build a new template-id expression.
2412 ///
2413 /// By default, performs semantic analysis to build the new expression.
2414 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002415 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002416 SourceLocation TemplateKWLoc,
2417 LookupResult &R,
2418 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002419 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002420 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2421 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 }
2423
2424 /// \brief Build a new object-construction expression.
2425 ///
2426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002428 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002429 SourceLocation Loc,
2430 CXXConstructorDecl *Constructor,
2431 bool IsElidable,
2432 MultiExprArg Args,
2433 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002434 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002435 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002436 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002437 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002438 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002439 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002440 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002441 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002442 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002443
Douglas Gregordb121ba2009-12-14 16:27:04 +00002444 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002445 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002446 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002447 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002448 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002449 RequiresZeroInit, ConstructKind,
2450 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 }
2452
2453 /// \brief Build a new object-construction expression.
2454 ///
2455 /// By default, performs semantic analysis to build the new expression.
2456 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002457 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2458 SourceLocation LParenLoc,
2459 MultiExprArg Args,
2460 SourceLocation RParenLoc) {
2461 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002462 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002463 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 RParenLoc);
2465 }
2466
2467 /// \brief Build a new object-construction expression.
2468 ///
2469 /// By default, performs semantic analysis to build the new expression.
2470 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002471 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2472 SourceLocation LParenLoc,
2473 MultiExprArg Args,
2474 SourceLocation RParenLoc) {
2475 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002477 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 RParenLoc);
2479 }
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregora16548e2009-08-11 05:31:07 +00002481 /// \brief Build a new member reference expression.
2482 ///
2483 /// By default, performs semantic analysis to build the new expression.
2484 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002485 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002486 QualType BaseType,
2487 bool IsArrow,
2488 SourceLocation OperatorLoc,
2489 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002490 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002491 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002492 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002493 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002495 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002496
John McCallb268a282010-08-23 23:25:46 +00002497 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002498 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002499 SS, TemplateKWLoc,
2500 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002501 MemberNameInfo,
2502 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 }
2504
John McCall10eae182009-11-30 22:42:35 +00002505 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002506 ///
2507 /// By default, performs semantic analysis to build the new expression.
2508 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002509 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2510 SourceLocation OperatorLoc,
2511 bool IsArrow,
2512 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002513 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002514 NamedDecl *FirstQualifierInScope,
2515 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002516 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002517 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002518 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002519
John McCallb268a282010-08-23 23:25:46 +00002520 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002521 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002522 SS, TemplateKWLoc,
2523 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002524 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002525 }
Mike Stump11289f42009-09-09 15:08:12 +00002526
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002527 /// \brief Build a new noexcept expression.
2528 ///
2529 /// By default, performs semantic analysis to build the new expression.
2530 /// Subclasses may override this routine to provide different behavior.
2531 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2532 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2533 }
2534
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002535 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2537 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002538 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002539 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002540 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002541 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2542 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002543 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002544
2545 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2546 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002547 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002548 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002549
Patrick Beard0caa3942012-04-19 00:25:12 +00002550 /// \brief Build a new Objective-C boxed expression.
2551 ///
2552 /// By default, performs semantic analysis to build the new expression.
2553 /// Subclasses may override this routine to provide different behavior.
2554 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2555 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2556 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002557
Ted Kremeneke65b0862012-03-06 20:05:56 +00002558 /// \brief Build a new Objective-C array literal.
2559 ///
2560 /// By default, performs semantic analysis to build the new expression.
2561 /// Subclasses may override this routine to provide different behavior.
2562 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2563 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002564 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002565 MultiExprArg(Elements, NumElements));
2566 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002567
2568 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002569 Expr *Base, Expr *Key,
2570 ObjCMethodDecl *getterMethod,
2571 ObjCMethodDecl *setterMethod) {
2572 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2573 getterMethod, setterMethod);
2574 }
2575
2576 /// \brief Build a new Objective-C dictionary literal.
2577 ///
2578 /// By default, performs semantic analysis to build the new expression.
2579 /// Subclasses may override this routine to provide different behavior.
2580 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2581 ObjCDictionaryElement *Elements,
2582 unsigned NumElements) {
2583 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002585
James Dennett2a4d13c2012-06-15 07:13:21 +00002586 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 ///
2588 /// By default, performs semantic analysis to build the new expression.
2589 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002590 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002591 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002593 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002594 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002595
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002596 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002597 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002598 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002599 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002600 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002601 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002602 MultiExprArg Args,
2603 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2605 ReceiverTypeInfo->getType(),
2606 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002607 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002608 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002609 }
2610
2611 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002612 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002613 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002614 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002615 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002616 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002617 MultiExprArg Args,
2618 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002619 return SemaRef.BuildInstanceMessage(Receiver,
2620 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002621 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002622 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002623 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002624 }
2625
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002626 /// \brief Build a new Objective-C instance/class message to 'super'.
2627 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2628 Selector Sel,
2629 ArrayRef<SourceLocation> SelectorLocs,
2630 ObjCMethodDecl *Method,
2631 SourceLocation LBracLoc,
2632 MultiExprArg Args,
2633 SourceLocation RBracLoc) {
2634 ObjCInterfaceDecl *Class = Method->getClassInterface();
2635 QualType ReceiverTy = SemaRef.Context.getObjCInterfaceType(Class);
2636
2637 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2638 ReceiverTy,
2639 SuperLoc,
2640 Sel, Method, LBracLoc, SelectorLocs,
2641 RBracLoc, Args)
2642 : SemaRef.BuildClassMessage(nullptr,
2643 ReceiverTy,
2644 SuperLoc,
2645 Sel, Method, LBracLoc, SelectorLocs,
2646 RBracLoc, Args);
2647
2648
2649 }
2650
Douglas Gregord51d90d2010-04-26 20:11:03 +00002651 /// \brief Build a new Objective-C ivar reference expression.
2652 ///
2653 /// By default, performs semantic analysis to build the new expression.
2654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002655 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002656 SourceLocation IvarLoc,
2657 bool IsArrow, bool IsFreeIvar) {
2658 // FIXME: We lose track of the IsFreeIvar bit.
2659 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002660 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2661 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002662 /*FIXME:*/IvarLoc, IsArrow,
2663 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002664 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002665 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002666 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002667 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002668
2669 /// \brief Build a new Objective-C property reference expression.
2670 ///
2671 /// By default, performs semantic analysis to build the new expression.
2672 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002673 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002674 ObjCPropertyDecl *Property,
2675 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002676 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002677 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2678 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2679 /*FIXME:*/PropertyLoc,
2680 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002681 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002682 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002683 NameInfo,
2684 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002686
John McCallb7bd14f2010-12-02 01:19:52 +00002687 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002688 ///
2689 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002690 /// Subclasses may override this routine to provide different behavior.
2691 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2692 ObjCMethodDecl *Getter,
2693 ObjCMethodDecl *Setter,
2694 SourceLocation PropertyLoc) {
2695 // Since these expressions can only be value-dependent, we do not
2696 // need to perform semantic analysis again.
2697 return Owned(
2698 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2699 VK_LValue, OK_ObjCProperty,
2700 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002701 }
2702
Douglas Gregord51d90d2010-04-26 20:11:03 +00002703 /// \brief Build a new Objective-C "isa" expression.
2704 ///
2705 /// By default, performs semantic analysis to build the new expression.
2706 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002707 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002708 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002709 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002710 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2711 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002712 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002713 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002714 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002715 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002716 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002718
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 /// \brief Build a new shuffle vector expression.
2720 ///
2721 /// By default, performs semantic analysis to build the new expression.
2722 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002723 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002724 MultiExprArg SubExprs,
2725 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002726 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002727 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2729 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2730 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002731 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002732
Douglas Gregora16548e2009-08-11 05:31:07 +00002733 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002734 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002735 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2736 SemaRef.Context.BuiltinFnTy,
2737 VK_RValue, BuiltinLoc);
2738 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2739 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002740 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002741
2742 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002743 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002744 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002745 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002746
Douglas Gregora16548e2009-08-11 05:31:07 +00002747 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002748 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002749 }
John McCall31f82722010-11-12 08:19:04 +00002750
Hal Finkelc4d7c822013-09-18 03:29:45 +00002751 /// \brief Build a new convert vector expression.
2752 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2753 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2754 SourceLocation RParenLoc) {
2755 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2756 BuiltinLoc, RParenLoc);
2757 }
2758
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002759 /// \brief Build a new template argument pack expansion.
2760 ///
2761 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002762 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002763 /// different behavior.
2764 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002765 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002766 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002767 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002768 case TemplateArgument::Expression: {
2769 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002770 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2771 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002772 if (Result.isInvalid())
2773 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002774
Douglas Gregor98318c22011-01-03 21:37:45 +00002775 return TemplateArgumentLoc(Result.get(), Result.get());
2776 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002777
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002778 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002779 return TemplateArgumentLoc(TemplateArgument(
2780 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002781 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002782 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002783 Pattern.getTemplateNameLoc(),
2784 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002785
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002786 case TemplateArgument::Null:
2787 case TemplateArgument::Integral:
2788 case TemplateArgument::Declaration:
2789 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002790 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002791 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002792 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002793
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002794 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002795 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002796 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002797 EllipsisLoc,
2798 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002799 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2800 Expansion);
2801 break;
2802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002803
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002804 return TemplateArgumentLoc();
2805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002806
Douglas Gregor968f23a2011-01-03 19:31:53 +00002807 /// \brief Build a new expression pack expansion.
2808 ///
2809 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002810 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002811 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002812 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002813 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002814 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002815 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002816
Richard Smith0f0af192014-11-08 05:07:16 +00002817 /// \brief Build a new C++1z fold-expression.
2818 ///
2819 /// By default, performs semantic analysis in order to build a new fold
2820 /// expression.
2821 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2822 BinaryOperatorKind Operator,
2823 SourceLocation EllipsisLoc, Expr *RHS,
2824 SourceLocation RParenLoc) {
2825 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2826 RHS, RParenLoc);
2827 }
2828
2829 /// \brief Build an empty C++1z fold-expression with the given operator.
2830 ///
2831 /// By default, produces the fallback value for the fold-expression, or
2832 /// produce an error if there is no fallback value.
2833 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2834 BinaryOperatorKind Operator) {
2835 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2836 }
2837
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002838 /// \brief Build a new atomic operation expression.
2839 ///
2840 /// By default, performs semantic analysis to build the new expression.
2841 /// Subclasses may override this routine to provide different behavior.
2842 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2843 MultiExprArg SubExprs,
2844 QualType RetTy,
2845 AtomicExpr::AtomicOp Op,
2846 SourceLocation RParenLoc) {
2847 // Just create the expression; there is not any interesting semantic
2848 // analysis here because we can't actually build an AtomicExpr until
2849 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002850 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002851 RParenLoc);
2852 }
2853
John McCall31f82722010-11-12 08:19:04 +00002854private:
Douglas Gregor14454802011-02-25 02:25:35 +00002855 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2856 QualType ObjectType,
2857 NamedDecl *FirstQualifierInScope,
2858 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002859
2860 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2861 QualType ObjectType,
2862 NamedDecl *FirstQualifierInScope,
2863 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002864
2865 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2866 NamedDecl *FirstQualifierInScope,
2867 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002868};
Douglas Gregora16548e2009-08-11 05:31:07 +00002869
Douglas Gregorebe10102009-08-20 07:17:43 +00002870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002871StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002872 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002873 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002874
Douglas Gregorebe10102009-08-20 07:17:43 +00002875 switch (S->getStmtClass()) {
2876 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002877
Douglas Gregorebe10102009-08-20 07:17:43 +00002878 // Transform individual statement nodes
2879#define STMT(Node, Parent) \
2880 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002881#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002882#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002883#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002884
Douglas Gregorebe10102009-08-20 07:17:43 +00002885 // Transform expressions by calling TransformExpr.
2886#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002887#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002888#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002889#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002890 {
John McCalldadc5752010-08-24 06:29:42 +00002891 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002892 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002893 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002894
Richard Smith945f8d32013-01-14 22:39:08 +00002895 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002896 }
Mike Stump11289f42009-09-09 15:08:12 +00002897 }
2898
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002899 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002900}
Mike Stump11289f42009-09-09 15:08:12 +00002901
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002902template<typename Derived>
2903OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2904 if (!S)
2905 return S;
2906
2907 switch (S->getClauseKind()) {
2908 default: break;
2909 // Transform individual clause nodes
2910#define OPENMP_CLAUSE(Name, Class) \
2911 case OMPC_ ## Name : \
2912 return getDerived().Transform ## Class(cast<Class>(S));
2913#include "clang/Basic/OpenMPKinds.def"
2914 }
2915
2916 return S;
2917}
2918
Mike Stump11289f42009-09-09 15:08:12 +00002919
Douglas Gregore922c772009-08-04 22:27:00 +00002920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002921ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002922 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002923 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002924
2925 switch (E->getStmtClass()) {
2926 case Stmt::NoStmtClass: break;
2927#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002928#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002929#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002930 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002931#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002932 }
2933
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002934 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002935}
2936
2937template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002938ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002939 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002940 // Initializers are instantiated like expressions, except that various outer
2941 // layers are stripped.
2942 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002943 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002944
2945 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2946 Init = ExprTemp->getSubExpr();
2947
Richard Smithe6ca4752013-05-30 22:40:16 +00002948 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2949 Init = MTE->GetTemporaryExpr();
2950
Richard Smithd59b8322012-12-19 01:39:02 +00002951 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2952 Init = Binder->getSubExpr();
2953
2954 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2955 Init = ICE->getSubExprAsWritten();
2956
Richard Smithcc1b96d2013-06-12 22:31:48 +00002957 if (CXXStdInitializerListExpr *ILE =
2958 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002959 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002960
Richard Smithc6abd962014-07-25 01:12:44 +00002961 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002962 // InitListExprs. Other forms of copy-initialization will be a no-op if
2963 // the initializer is already the right type.
2964 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002965 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002966 return getDerived().TransformExpr(Init);
2967
2968 // Revert value-initialization back to empty parens.
2969 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2970 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002971 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002972 Parens.getEnd());
2973 }
2974
2975 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2976 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002977 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002978 SourceLocation());
2979
2980 // Revert initialization by constructor back to a parenthesized or braced list
2981 // of expressions. Any other form of initializer can just be reused directly.
2982 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002983 return getDerived().TransformExpr(Init);
2984
Richard Smithf8adcdc2014-07-17 05:12:35 +00002985 // If the initialization implicitly converted an initializer list to a
2986 // std::initializer_list object, unwrap the std::initializer_list too.
2987 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002988 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002989
Richard Smithd59b8322012-12-19 01:39:02 +00002990 SmallVector<Expr*, 8> NewArgs;
2991 bool ArgChanged = false;
2992 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002993 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002994 return ExprError();
2995
2996 // If this was list initialization, revert to list form.
2997 if (Construct->isListInitialization())
2998 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2999 Construct->getLocEnd(),
3000 Construct->getType());
3001
Richard Smithd59b8322012-12-19 01:39:02 +00003002 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003003 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003004 if (Parens.isInvalid()) {
3005 // This was a variable declaration's initialization for which no initializer
3006 // was specified.
3007 assert(NewArgs.empty() &&
3008 "no parens or braces but have direct init with arguments?");
3009 return ExprEmpty();
3010 }
Richard Smithd59b8322012-12-19 01:39:02 +00003011 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3012 Parens.getEnd());
3013}
3014
3015template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003016bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3017 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003018 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003019 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003020 bool *ArgChanged) {
3021 for (unsigned I = 0; I != NumInputs; ++I) {
3022 // If requested, drop call arguments that need to be dropped.
3023 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3024 if (ArgChanged)
3025 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003026
Douglas Gregora3efea12011-01-03 19:04:46 +00003027 break;
3028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003029
Douglas Gregor968f23a2011-01-03 19:31:53 +00003030 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3031 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003032
Chris Lattner01cf8db2011-07-20 06:58:45 +00003033 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003034 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3035 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003036
Douglas Gregor968f23a2011-01-03 19:31:53 +00003037 // Determine whether the set of unexpanded parameter packs can and should
3038 // be expanded.
3039 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003040 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003041 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3042 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003043 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3044 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003045 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003046 Expand, RetainExpansion,
3047 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003048 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003049
Douglas Gregor968f23a2011-01-03 19:31:53 +00003050 if (!Expand) {
3051 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003052 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003053 // expansion.
3054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3055 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3056 if (OutPattern.isInvalid())
3057 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003058
3059 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003060 Expansion->getEllipsisLoc(),
3061 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003062 if (Out.isInvalid())
3063 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003064
Douglas Gregor968f23a2011-01-03 19:31:53 +00003065 if (ArgChanged)
3066 *ArgChanged = true;
3067 Outputs.push_back(Out.get());
3068 continue;
3069 }
John McCall542e7c62011-07-06 07:30:07 +00003070
3071 // Record right away that the argument was changed. This needs
3072 // to happen even if the array expands to nothing.
3073 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003074
Douglas Gregor968f23a2011-01-03 19:31:53 +00003075 // The transform has determined that we should perform an elementwise
3076 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003077 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003078 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3079 ExprResult Out = getDerived().TransformExpr(Pattern);
3080 if (Out.isInvalid())
3081 return true;
3082
Richard Smith9467be42014-06-06 17:33:35 +00003083 // FIXME: Can this happen? We should not try to expand the pack
3084 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003085 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003086 Out = getDerived().RebuildPackExpansion(
3087 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003088 if (Out.isInvalid())
3089 return true;
3090 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003091
Douglas Gregor968f23a2011-01-03 19:31:53 +00003092 Outputs.push_back(Out.get());
3093 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003094
Richard Smith9467be42014-06-06 17:33:35 +00003095 // If we're supposed to retain a pack expansion, do so by temporarily
3096 // forgetting the partially-substituted parameter pack.
3097 if (RetainExpansion) {
3098 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3099
3100 ExprResult Out = getDerived().TransformExpr(Pattern);
3101 if (Out.isInvalid())
3102 return true;
3103
3104 Out = getDerived().RebuildPackExpansion(
3105 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3106 if (Out.isInvalid())
3107 return true;
3108
3109 Outputs.push_back(Out.get());
3110 }
3111
Douglas Gregor968f23a2011-01-03 19:31:53 +00003112 continue;
3113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003114
Richard Smithd59b8322012-12-19 01:39:02 +00003115 ExprResult Result =
3116 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3117 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003118 if (Result.isInvalid())
3119 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003120
Douglas Gregora3efea12011-01-03 19:04:46 +00003121 if (Result.get() != Inputs[I] && ArgChanged)
3122 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
3124 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003125 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003126
Douglas Gregora3efea12011-01-03 19:04:46 +00003127 return false;
3128}
3129
3130template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003131NestedNameSpecifierLoc
3132TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3133 NestedNameSpecifierLoc NNS,
3134 QualType ObjectType,
3135 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003136 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003137 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003138 Qualifier = Qualifier.getPrefix())
3139 Qualifiers.push_back(Qualifier);
3140
3141 CXXScopeSpec SS;
3142 while (!Qualifiers.empty()) {
3143 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3144 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003145
Douglas Gregor14454802011-02-25 02:25:35 +00003146 switch (QNNS->getKind()) {
3147 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003148 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003149 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003150 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003151 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003152 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003153 FirstQualifierInScope, false))
3154 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003155
Douglas Gregor14454802011-02-25 02:25:35 +00003156 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003157
Douglas Gregor14454802011-02-25 02:25:35 +00003158 case NestedNameSpecifier::Namespace: {
3159 NamespaceDecl *NS
3160 = cast_or_null<NamespaceDecl>(
3161 getDerived().TransformDecl(
3162 Q.getLocalBeginLoc(),
3163 QNNS->getAsNamespace()));
3164 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3165 break;
3166 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003167
Douglas Gregor14454802011-02-25 02:25:35 +00003168 case NestedNameSpecifier::NamespaceAlias: {
3169 NamespaceAliasDecl *Alias
3170 = cast_or_null<NamespaceAliasDecl>(
3171 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3172 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003173 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003174 Q.getLocalEndLoc());
3175 break;
3176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003177
Douglas Gregor14454802011-02-25 02:25:35 +00003178 case NestedNameSpecifier::Global:
3179 // There is no meaningful transformation that one could perform on the
3180 // global scope.
3181 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3182 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003183
Nikola Smiljanic67860242014-09-26 00:28:20 +00003184 case NestedNameSpecifier::Super: {
3185 CXXRecordDecl *RD =
3186 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3187 SourceLocation(), QNNS->getAsRecordDecl()));
3188 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3189 break;
3190 }
3191
Douglas Gregor14454802011-02-25 02:25:35 +00003192 case NestedNameSpecifier::TypeSpecWithTemplate:
3193 case NestedNameSpecifier::TypeSpec: {
3194 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3195 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003196
Douglas Gregor14454802011-02-25 02:25:35 +00003197 if (!TL)
3198 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003199
Douglas Gregor14454802011-02-25 02:25:35 +00003200 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003201 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003202 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003203 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003204 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003205 if (TL.getType()->isEnumeralType())
3206 SemaRef.Diag(TL.getBeginLoc(),
3207 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003208 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3209 Q.getLocalEndLoc());
3210 break;
3211 }
Richard Trieude756fb2011-05-07 01:36:37 +00003212 // If the nested-name-specifier is an invalid type def, don't emit an
3213 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003214 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3215 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003216 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003217 << TL.getType() << SS.getRange();
3218 }
Douglas Gregor14454802011-02-25 02:25:35 +00003219 return NestedNameSpecifierLoc();
3220 }
Douglas Gregore16af532011-02-28 18:50:33 +00003221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003222
Douglas Gregore16af532011-02-28 18:50:33 +00003223 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003224 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003225 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003226 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003227
Douglas Gregor14454802011-02-25 02:25:35 +00003228 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003229 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003230 !getDerived().AlwaysRebuild())
3231 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
3233 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003234 // nested-name-specifier, do so.
3235 if (SS.location_size() == NNS.getDataLength() &&
3236 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3237 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3238
3239 // Allocate new nested-name-specifier location information.
3240 return SS.getWithLocInContext(SemaRef.Context);
3241}
3242
3243template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003244DeclarationNameInfo
3245TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003246::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003247 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003248 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003249 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003250
3251 switch (Name.getNameKind()) {
3252 case DeclarationName::Identifier:
3253 case DeclarationName::ObjCZeroArgSelector:
3254 case DeclarationName::ObjCOneArgSelector:
3255 case DeclarationName::ObjCMultiArgSelector:
3256 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003257 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003258 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003259 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003260
Douglas Gregorf816bd72009-09-03 22:13:48 +00003261 case DeclarationName::CXXConstructorName:
3262 case DeclarationName::CXXDestructorName:
3263 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003264 TypeSourceInfo *NewTInfo;
3265 CanQualType NewCanTy;
3266 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003267 NewTInfo = getDerived().TransformType(OldTInfo);
3268 if (!NewTInfo)
3269 return DeclarationNameInfo();
3270 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003271 }
3272 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003273 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003274 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003275 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003276 if (NewT.isNull())
3277 return DeclarationNameInfo();
3278 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3279 }
Mike Stump11289f42009-09-09 15:08:12 +00003280
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003281 DeclarationName NewName
3282 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3283 NewCanTy);
3284 DeclarationNameInfo NewNameInfo(NameInfo);
3285 NewNameInfo.setName(NewName);
3286 NewNameInfo.setNamedTypeInfo(NewTInfo);
3287 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003288 }
Mike Stump11289f42009-09-09 15:08:12 +00003289 }
3290
David Blaikie83d382b2011-09-23 05:06:16 +00003291 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003292}
3293
3294template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003295TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003296TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3297 TemplateName Name,
3298 SourceLocation NameLoc,
3299 QualType ObjectType,
3300 NamedDecl *FirstQualifierInScope) {
3301 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3302 TemplateDecl *Template = QTN->getTemplateDecl();
3303 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregor9db53502011-03-02 18:07:45 +00003305 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003306 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003307 Template));
3308 if (!TransTemplate)
3309 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor9db53502011-03-02 18:07:45 +00003311 if (!getDerived().AlwaysRebuild() &&
3312 SS.getScopeRep() == QTN->getQualifier() &&
3313 TransTemplate == Template)
3314 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003315
Douglas Gregor9db53502011-03-02 18:07:45 +00003316 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3317 TransTemplate);
3318 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003319
Douglas Gregor9db53502011-03-02 18:07:45 +00003320 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3321 if (SS.getScopeRep()) {
3322 // These apply to the scope specifier, not the template.
3323 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003324 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003325 }
3326
Douglas Gregor9db53502011-03-02 18:07:45 +00003327 if (!getDerived().AlwaysRebuild() &&
3328 SS.getScopeRep() == DTN->getQualifier() &&
3329 ObjectType.isNull())
3330 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003331
Douglas Gregor9db53502011-03-02 18:07:45 +00003332 if (DTN->isIdentifier()) {
3333 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003334 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003335 NameLoc,
3336 ObjectType,
3337 FirstQualifierInScope);
3338 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Douglas Gregor9db53502011-03-02 18:07:45 +00003340 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3341 ObjectType);
3342 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003343
Douglas Gregor9db53502011-03-02 18:07:45 +00003344 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3345 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003346 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003347 Template));
3348 if (!TransTemplate)
3349 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Douglas Gregor9db53502011-03-02 18:07:45 +00003351 if (!getDerived().AlwaysRebuild() &&
3352 TransTemplate == Template)
3353 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003354
Douglas Gregor9db53502011-03-02 18:07:45 +00003355 return TemplateName(TransTemplate);
3356 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor9db53502011-03-02 18:07:45 +00003358 if (SubstTemplateTemplateParmPackStorage *SubstPack
3359 = Name.getAsSubstTemplateTemplateParmPack()) {
3360 TemplateTemplateParmDecl *TransParam
3361 = cast_or_null<TemplateTemplateParmDecl>(
3362 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3363 if (!TransParam)
3364 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003365
Douglas Gregor9db53502011-03-02 18:07:45 +00003366 if (!getDerived().AlwaysRebuild() &&
3367 TransParam == SubstPack->getParameterPack())
3368 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
3370 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003371 SubstPack->getArgumentPack());
3372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregor9db53502011-03-02 18:07:45 +00003374 // These should be getting filtered out before they reach the AST.
3375 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003376}
3377
3378template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003379void TreeTransform<Derived>::InventTemplateArgumentLoc(
3380 const TemplateArgument &Arg,
3381 TemplateArgumentLoc &Output) {
3382 SourceLocation Loc = getDerived().getBaseLocation();
3383 switch (Arg.getKind()) {
3384 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003385 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003386 break;
3387
3388 case TemplateArgument::Type:
3389 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003390 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003391
John McCall0ad16662009-10-29 08:12:44 +00003392 break;
3393
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003394 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003395 case TemplateArgument::TemplateExpansion: {
3396 NestedNameSpecifierLocBuilder Builder;
3397 TemplateName Template = Arg.getAsTemplate();
3398 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3399 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3400 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3401 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor9d802122011-03-02 17:09:35 +00003403 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003404 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003405 Builder.getWithLocInContext(SemaRef.Context),
3406 Loc);
3407 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003408 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003409 Builder.getWithLocInContext(SemaRef.Context),
3410 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003412 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003413 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003414
John McCall0ad16662009-10-29 08:12:44 +00003415 case TemplateArgument::Expression:
3416 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3417 break;
3418
3419 case TemplateArgument::Declaration:
3420 case TemplateArgument::Integral:
3421 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003422 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003423 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003424 break;
3425 }
3426}
3427
3428template<typename Derived>
3429bool TreeTransform<Derived>::TransformTemplateArgument(
3430 const TemplateArgumentLoc &Input,
3431 TemplateArgumentLoc &Output) {
3432 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003433 switch (Arg.getKind()) {
3434 case TemplateArgument::Null:
3435 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003436 case TemplateArgument::Pack:
3437 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003438 case TemplateArgument::NullPtr:
3439 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregore922c772009-08-04 22:27:00 +00003441 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003442 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003443 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003444 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003445
3446 DI = getDerived().TransformType(DI);
3447 if (!DI) return true;
3448
3449 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3450 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003451 }
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003453 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003454 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3455 if (QualifierLoc) {
3456 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3457 if (!QualifierLoc)
3458 return true;
3459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
Douglas Gregordf846d12011-03-02 18:46:51 +00003461 CXXScopeSpec SS;
3462 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003463 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003464 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3465 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003466 if (Template.isNull())
3467 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003468
Douglas Gregor9d802122011-03-02 17:09:35 +00003469 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003470 Input.getTemplateNameLoc());
3471 return false;
3472 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003473
3474 case TemplateArgument::TemplateExpansion:
3475 llvm_unreachable("Caller should expand pack expansions");
3476
Douglas Gregore922c772009-08-04 22:27:00 +00003477 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003478 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003479 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003480 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003481
John McCall0ad16662009-10-29 08:12:44 +00003482 Expr *InputExpr = Input.getSourceExpression();
3483 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3484
Chris Lattnercdb591a2011-04-25 20:37:58 +00003485 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003486 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003487 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003488 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003489 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003490 }
Douglas Gregore922c772009-08-04 22:27:00 +00003491 }
Mike Stump11289f42009-09-09 15:08:12 +00003492
Douglas Gregore922c772009-08-04 22:27:00 +00003493 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003494 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003495}
3496
Douglas Gregorfe921a72010-12-20 23:36:19 +00003497/// \brief Iterator adaptor that invents template argument location information
3498/// for each of the template arguments in its underlying iterator.
3499template<typename Derived, typename InputIterator>
3500class TemplateArgumentLocInventIterator {
3501 TreeTransform<Derived> &Self;
3502 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003503
Douglas Gregorfe921a72010-12-20 23:36:19 +00003504public:
3505 typedef TemplateArgumentLoc value_type;
3506 typedef TemplateArgumentLoc reference;
3507 typedef typename std::iterator_traits<InputIterator>::difference_type
3508 difference_type;
3509 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003510
Douglas Gregorfe921a72010-12-20 23:36:19 +00003511 class pointer {
3512 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Douglas Gregorfe921a72010-12-20 23:36:19 +00003514 public:
3515 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregorfe921a72010-12-20 23:36:19 +00003517 const TemplateArgumentLoc *operator->() const { return &Arg; }
3518 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregorfe921a72010-12-20 23:36:19 +00003520 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregorfe921a72010-12-20 23:36:19 +00003522 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3523 InputIterator Iter)
3524 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregorfe921a72010-12-20 23:36:19 +00003526 TemplateArgumentLocInventIterator &operator++() {
3527 ++Iter;
3528 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003529 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003530
Douglas Gregorfe921a72010-12-20 23:36:19 +00003531 TemplateArgumentLocInventIterator operator++(int) {
3532 TemplateArgumentLocInventIterator Old(*this);
3533 ++(*this);
3534 return Old;
3535 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003536
Douglas Gregorfe921a72010-12-20 23:36:19 +00003537 reference operator*() const {
3538 TemplateArgumentLoc Result;
3539 Self.InventTemplateArgumentLoc(*Iter, Result);
3540 return Result;
3541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregorfe921a72010-12-20 23:36:19 +00003543 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +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 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003549
Douglas Gregorfe921a72010-12-20 23:36:19 +00003550 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3551 const TemplateArgumentLocInventIterator &Y) {
3552 return X.Iter != Y.Iter;
3553 }
3554};
Chad Rosier1dcde962012-08-08 18:46:20 +00003555
Douglas Gregor42cafa82010-12-20 17:42:22 +00003556template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003557template<typename InputIterator>
3558bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3559 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003560 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003561 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003562 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003563 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003565 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3566 // Unpack argument packs, which we translate them into separate
3567 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003568 // FIXME: We could do much better if we could guarantee that the
3569 // TemplateArgumentLocInfo for the pack expansion would be usable for
3570 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003571 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003572 TemplateArgument::pack_iterator>
3573 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003574 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003575 In.getArgument().pack_begin()),
3576 PackLocIterator(*this,
3577 In.getArgument().pack_end()),
3578 Outputs))
3579 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003581 continue;
3582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003583
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003584 if (In.getArgument().isPackExpansion()) {
3585 // We have a pack expansion, for which we will be substituting into
3586 // the pattern.
3587 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003588 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003589 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003590 = getSema().getTemplateArgumentPackExpansionPattern(
3591 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Chris Lattner01cf8db2011-07-20 06:58:45 +00003593 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003594 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3595 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003597 // Determine whether the set of unexpanded parameter packs can and should
3598 // be expanded.
3599 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003600 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003601 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003602 if (getDerived().TryExpandParameterPacks(Ellipsis,
3603 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003604 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003605 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003606 RetainExpansion,
3607 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003608 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003609
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003610 if (!Expand) {
3611 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003612 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003613 // expansion.
3614 TemplateArgumentLoc OutPattern;
3615 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3616 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3617 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003619 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3620 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003621 if (Out.getArgument().isNull())
3622 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003623
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003624 Outputs.addArgument(Out);
3625 continue;
3626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003628 // The transform has determined that we should perform an elementwise
3629 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003630 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003631 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3632
3633 if (getDerived().TransformTemplateArgument(Pattern, Out))
3634 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003636 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003637 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3638 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003639 if (Out.getArgument().isNull())
3640 return true;
3641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003642
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003643 Outputs.addArgument(Out);
3644 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor48d24112011-01-10 20:53:55 +00003646 // If we're supposed to retain a pack expansion, do so by temporarily
3647 // forgetting the partially-substituted parameter pack.
3648 if (RetainExpansion) {
3649 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003650
Douglas Gregor48d24112011-01-10 20:53:55 +00003651 if (getDerived().TransformTemplateArgument(Pattern, Out))
3652 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003654 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3655 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003656 if (Out.getArgument().isNull())
3657 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor48d24112011-01-10 20:53:55 +00003659 Outputs.addArgument(Out);
3660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003661
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003662 continue;
3663 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003664
3665 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003666 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003667 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003668
Douglas Gregor42cafa82010-12-20 17:42:22 +00003669 Outputs.addArgument(Out);
3670 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003671
Douglas Gregor42cafa82010-12-20 17:42:22 +00003672 return false;
3673
3674}
3675
Douglas Gregord6ff3322009-08-04 16:50:30 +00003676//===----------------------------------------------------------------------===//
3677// Type transformation
3678//===----------------------------------------------------------------------===//
3679
3680template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003681QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003682 if (getDerived().AlreadyTransformed(T))
3683 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003684
John McCall550e0c22009-10-21 00:40:46 +00003685 // Temporary workaround. All of these transformations should
3686 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003687 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3688 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003689
John McCall31f82722010-11-12 08:19:04 +00003690 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003691
John McCall550e0c22009-10-21 00:40:46 +00003692 if (!NewDI)
3693 return QualType();
3694
3695 return NewDI->getType();
3696}
3697
3698template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003699TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003700 // Refine the base location to the type's location.
3701 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3702 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003703 if (getDerived().AlreadyTransformed(DI->getType()))
3704 return DI;
3705
3706 TypeLocBuilder TLB;
3707
3708 TypeLoc TL = DI->getTypeLoc();
3709 TLB.reserve(TL.getFullDataSize());
3710
John McCall31f82722010-11-12 08:19:04 +00003711 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003712 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003713 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003714
John McCallbcd03502009-12-07 02:54:59 +00003715 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003716}
3717
3718template<typename Derived>
3719QualType
John McCall31f82722010-11-12 08:19:04 +00003720TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003721 switch (T.getTypeLocClass()) {
3722#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003723#define TYPELOC(CLASS, PARENT) \
3724 case TypeLoc::CLASS: \
3725 return getDerived().Transform##CLASS##Type(TLB, \
3726 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003727#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003728 }
Mike Stump11289f42009-09-09 15:08:12 +00003729
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003730 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003731}
3732
3733/// FIXME: By default, this routine adds type qualifiers only to types
3734/// that can have qualifiers, and silently suppresses those qualifiers
3735/// that are not permitted (e.g., qualifiers on reference or function
3736/// types). This is the right thing for template instantiation, but
3737/// probably not for other clients.
3738template<typename Derived>
3739QualType
3740TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003741 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003742 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003743
John McCall31f82722010-11-12 08:19:04 +00003744 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003745 if (Result.isNull())
3746 return QualType();
3747
3748 // Silently suppress qualifiers if the result type can't be qualified.
3749 // FIXME: this is the right thing for template instantiation, but
3750 // probably not for other clients.
3751 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003752 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003753
John McCall31168b02011-06-15 23:02:42 +00003754 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003755 // resulting type.
3756 if (Quals.hasObjCLifetime()) {
3757 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3758 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003759 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003760 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003761 // A lifetime qualifier applied to a substituted template parameter
3762 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003763 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003764 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003765 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3766 QualType Replacement = SubstTypeParam->getReplacementType();
3767 Qualifiers Qs = Replacement.getQualifiers();
3768 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003769 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003770 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3771 Qs);
3772 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003773 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003774 Replacement);
3775 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003776 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3777 // 'auto' types behave the same way as template parameters.
3778 QualType Deduced = AutoTy->getDeducedType();
3779 Qualifiers Qs = Deduced.getQualifiers();
3780 Qs.removeObjCLifetime();
3781 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3782 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003783 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3784 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003785 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003786 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003787 // Otherwise, complain about the addition of a qualifier to an
3788 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003789 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003790 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003791 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003792
Douglas Gregore46db902011-06-17 22:11:49 +00003793 Quals.removeObjCLifetime();
3794 }
3795 }
3796 }
John McCallcb0f89a2010-06-05 06:41:15 +00003797 if (!Quals.empty()) {
3798 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003799 // BuildQualifiedType might not add qualifiers if they are invalid.
3800 if (Result.hasLocalQualifiers())
3801 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003802 // No location information to preserve.
3803 }
John McCall550e0c22009-10-21 00:40:46 +00003804
3805 return Result;
3806}
3807
Douglas Gregor14454802011-02-25 02:25:35 +00003808template<typename Derived>
3809TypeLoc
3810TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3811 QualType ObjectType,
3812 NamedDecl *UnqualLookup,
3813 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003814 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003815 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003817 TypeSourceInfo *TSI =
3818 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3819 if (TSI)
3820 return TSI->getTypeLoc();
3821 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003822}
3823
Douglas Gregor579c15f2011-03-02 18:32:08 +00003824template<typename Derived>
3825TypeSourceInfo *
3826TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3827 QualType ObjectType,
3828 NamedDecl *UnqualLookup,
3829 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003830 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003831 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003832
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003833 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3834 UnqualLookup, SS);
3835}
3836
3837template <typename Derived>
3838TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3839 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3840 CXXScopeSpec &SS) {
3841 QualType T = TL.getType();
3842 assert(!getDerived().AlreadyTransformed(T));
3843
Douglas Gregor579c15f2011-03-02 18:32:08 +00003844 TypeLocBuilder TLB;
3845 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003846
Douglas Gregor579c15f2011-03-02 18:32:08 +00003847 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003848 TemplateSpecializationTypeLoc SpecTL =
3849 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003850
Douglas Gregor579c15f2011-03-02 18:32:08 +00003851 TemplateName Template
3852 = getDerived().TransformTemplateName(SS,
3853 SpecTL.getTypePtr()->getTemplateName(),
3854 SpecTL.getTemplateNameLoc(),
3855 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003856 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003857 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003858
3859 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003860 Template);
3861 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003862 DependentTemplateSpecializationTypeLoc SpecTL =
3863 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003864
Douglas Gregor579c15f2011-03-02 18:32:08 +00003865 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003866 = getDerived().RebuildTemplateName(SS,
3867 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003868 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003869 ObjectType, UnqualLookup);
3870 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003871 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003872
3873 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003874 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003875 Template,
3876 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003877 } else {
3878 // Nothing special needs to be done for these.
3879 Result = getDerived().TransformType(TLB, TL);
3880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
3882 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003883 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003884
Douglas Gregor579c15f2011-03-02 18:32:08 +00003885 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3886}
3887
John McCall550e0c22009-10-21 00:40:46 +00003888template <class TyLoc> static inline
3889QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3890 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3891 NewT.setNameLoc(T.getNameLoc());
3892 return T.getType();
3893}
3894
John McCall550e0c22009-10-21 00:40:46 +00003895template<typename Derived>
3896QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003897 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003898 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3899 NewT.setBuiltinLoc(T.getBuiltinLoc());
3900 if (T.needsExtraLocalData())
3901 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3902 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003903}
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003906QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003907 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003908 // FIXME: recurse?
3909 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003910}
Mike Stump11289f42009-09-09 15:08:12 +00003911
Reid Kleckner0503a872013-12-05 01:23:43 +00003912template <typename Derived>
3913QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3914 AdjustedTypeLoc TL) {
3915 // Adjustments applied during transformation are handled elsewhere.
3916 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3917}
3918
Douglas Gregord6ff3322009-08-04 16:50:30 +00003919template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003920QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3921 DecayedTypeLoc TL) {
3922 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3923 if (OriginalType.isNull())
3924 return QualType();
3925
3926 QualType Result = TL.getType();
3927 if (getDerived().AlwaysRebuild() ||
3928 OriginalType != TL.getOriginalLoc().getType())
3929 Result = SemaRef.Context.getDecayedType(OriginalType);
3930 TLB.push<DecayedTypeLoc>(Result);
3931 // Nothing to set for DecayedTypeLoc.
3932 return Result;
3933}
3934
3935template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003936QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003937 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003938 QualType PointeeType
3939 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003940 if (PointeeType.isNull())
3941 return QualType();
3942
3943 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003944 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003945 // A dependent pointer type 'T *' has is being transformed such
3946 // that an Objective-C class type is being replaced for 'T'. The
3947 // resulting pointer type is an ObjCObjectPointerType, not a
3948 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003949 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003950
John McCall8b07ec22010-05-15 11:32:37 +00003951 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3952 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003953 return Result;
3954 }
John McCall31f82722010-11-12 08:19:04 +00003955
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003956 if (getDerived().AlwaysRebuild() ||
3957 PointeeType != TL.getPointeeLoc().getType()) {
3958 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3959 if (Result.isNull())
3960 return QualType();
3961 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003962
John McCall31168b02011-06-15 23:02:42 +00003963 // Objective-C ARC can add lifetime qualifiers to the type that we're
3964 // pointing to.
3965 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003966
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003967 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3968 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003969 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003970}
Mike Stump11289f42009-09-09 15:08:12 +00003971
3972template<typename Derived>
3973QualType
John McCall550e0c22009-10-21 00:40:46 +00003974TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003975 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003976 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003977 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3978 if (PointeeType.isNull())
3979 return QualType();
3980
3981 QualType Result = TL.getType();
3982 if (getDerived().AlwaysRebuild() ||
3983 PointeeType != TL.getPointeeLoc().getType()) {
3984 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003985 TL.getSigilLoc());
3986 if (Result.isNull())
3987 return QualType();
3988 }
3989
Douglas Gregor049211a2010-04-22 16:50:51 +00003990 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003991 NewT.setSigilLoc(TL.getSigilLoc());
3992 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003993}
3994
John McCall70dd5f62009-10-30 00:06:24 +00003995/// Transforms a reference type. Note that somewhat paradoxically we
3996/// don't care whether the type itself is an l-value type or an r-value
3997/// type; we only care if the type was *written* as an l-value type
3998/// or an r-value type.
3999template<typename Derived>
4000QualType
4001TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004002 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004003 const ReferenceType *T = TL.getTypePtr();
4004
4005 // Note that this works with the pointee-as-written.
4006 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4007 if (PointeeType.isNull())
4008 return QualType();
4009
4010 QualType Result = TL.getType();
4011 if (getDerived().AlwaysRebuild() ||
4012 PointeeType != T->getPointeeTypeAsWritten()) {
4013 Result = getDerived().RebuildReferenceType(PointeeType,
4014 T->isSpelledAsLValue(),
4015 TL.getSigilLoc());
4016 if (Result.isNull())
4017 return QualType();
4018 }
4019
John McCall31168b02011-06-15 23:02:42 +00004020 // Objective-C ARC can add lifetime qualifiers to the type that we're
4021 // referring to.
4022 TLB.TypeWasModifiedSafely(
4023 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4024
John McCall70dd5f62009-10-30 00:06:24 +00004025 // r-value references can be rebuilt as l-value references.
4026 ReferenceTypeLoc NewTL;
4027 if (isa<LValueReferenceType>(Result))
4028 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4029 else
4030 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4031 NewTL.setSigilLoc(TL.getSigilLoc());
4032
4033 return Result;
4034}
4035
Mike Stump11289f42009-09-09 15:08:12 +00004036template<typename Derived>
4037QualType
John McCall550e0c22009-10-21 00:40:46 +00004038TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004039 LValueReferenceTypeLoc TL) {
4040 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004041}
4042
Mike Stump11289f42009-09-09 15:08:12 +00004043template<typename Derived>
4044QualType
John McCall550e0c22009-10-21 00:40:46 +00004045TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004046 RValueReferenceTypeLoc TL) {
4047 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004048}
Mike Stump11289f42009-09-09 15:08:12 +00004049
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004051QualType
John McCall550e0c22009-10-21 00:40:46 +00004052TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004053 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004054 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055 if (PointeeType.isNull())
4056 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004057
Abramo Bagnara509357842011-03-05 14:42:21 +00004058 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004059 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004060 if (OldClsTInfo) {
4061 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4062 if (!NewClsTInfo)
4063 return QualType();
4064 }
4065
4066 const MemberPointerType *T = TL.getTypePtr();
4067 QualType OldClsType = QualType(T->getClass(), 0);
4068 QualType NewClsType;
4069 if (NewClsTInfo)
4070 NewClsType = NewClsTInfo->getType();
4071 else {
4072 NewClsType = getDerived().TransformType(OldClsType);
4073 if (NewClsType.isNull())
4074 return QualType();
4075 }
Mike Stump11289f42009-09-09 15:08:12 +00004076
John McCall550e0c22009-10-21 00:40:46 +00004077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() ||
4079 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004080 NewClsType != OldClsType) {
4081 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004082 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004083 if (Result.isNull())
4084 return QualType();
4085 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004086
Reid Kleckner0503a872013-12-05 01:23:43 +00004087 // If we had to adjust the pointee type when building a member pointer, make
4088 // sure to push TypeLoc info for it.
4089 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4090 if (MPT && PointeeType != MPT->getPointeeType()) {
4091 assert(isa<AdjustedType>(MPT->getPointeeType()));
4092 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4093 }
4094
John McCall550e0c22009-10-21 00:40:46 +00004095 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4096 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004097 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004098
4099 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004100}
4101
Mike Stump11289f42009-09-09 15:08:12 +00004102template<typename Derived>
4103QualType
John McCall550e0c22009-10-21 00:40:46 +00004104TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004105 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004106 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004107 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108 if (ElementType.isNull())
4109 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004110
John McCall550e0c22009-10-21 00:40:46 +00004111 QualType Result = TL.getType();
4112 if (getDerived().AlwaysRebuild() ||
4113 ElementType != T->getElementType()) {
4114 Result = getDerived().RebuildConstantArrayType(ElementType,
4115 T->getSizeModifier(),
4116 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004117 T->getIndexTypeCVRQualifiers(),
4118 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004119 if (Result.isNull())
4120 return QualType();
4121 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004122
4123 // We might have either a ConstantArrayType or a VariableArrayType now:
4124 // a ConstantArrayType is allowed to have an element type which is a
4125 // VariableArrayType if the type is dependent. Fortunately, all array
4126 // types have the same location layout.
4127 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004128 NewTL.setLBracketLoc(TL.getLBracketLoc());
4129 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004130
John McCall550e0c22009-10-21 00:40:46 +00004131 Expr *Size = TL.getSizeExpr();
4132 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004133 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4134 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004135 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4136 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004137 }
4138 NewTL.setSizeExpr(Size);
4139
4140 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004141}
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregord6ff3322009-08-04 16:50:30 +00004143template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004144QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004145 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004146 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004147 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004148 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149 if (ElementType.isNull())
4150 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004151
John McCall550e0c22009-10-21 00:40:46 +00004152 QualType Result = TL.getType();
4153 if (getDerived().AlwaysRebuild() ||
4154 ElementType != T->getElementType()) {
4155 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004156 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004157 T->getIndexTypeCVRQualifiers(),
4158 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004159 if (Result.isNull())
4160 return QualType();
4161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004162
John McCall550e0c22009-10-21 00:40:46 +00004163 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4164 NewTL.setLBracketLoc(TL.getLBracketLoc());
4165 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004166 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004167
4168 return Result;
4169}
4170
4171template<typename Derived>
4172QualType
4173TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004174 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004175 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004176 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4177 if (ElementType.isNull())
4178 return QualType();
4179
John McCalldadc5752010-08-24 06:29:42 +00004180 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004181 = getDerived().TransformExpr(T->getSizeExpr());
4182 if (SizeResult.isInvalid())
4183 return QualType();
4184
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004185 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004186
4187 QualType Result = TL.getType();
4188 if (getDerived().AlwaysRebuild() ||
4189 ElementType != T->getElementType() ||
4190 Size != T->getSizeExpr()) {
4191 Result = getDerived().RebuildVariableArrayType(ElementType,
4192 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004193 Size,
John McCall550e0c22009-10-21 00:40:46 +00004194 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004195 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004196 if (Result.isNull())
4197 return QualType();
4198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004199
Serge Pavlov774c6d02014-02-06 03:49:11 +00004200 // We might have constant size array now, but fortunately it has the same
4201 // location layout.
4202 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004203 NewTL.setLBracketLoc(TL.getLBracketLoc());
4204 NewTL.setRBracketLoc(TL.getRBracketLoc());
4205 NewTL.setSizeExpr(Size);
4206
4207 return Result;
4208}
4209
4210template<typename Derived>
4211QualType
4212TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004213 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004214 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004215 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4216 if (ElementType.isNull())
4217 return QualType();
4218
Richard Smith764d2fe2011-12-20 02:08:33 +00004219 // Array bounds are constant expressions.
4220 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4221 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004222
John McCall33ddac02011-01-19 10:06:00 +00004223 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4224 Expr *origSize = TL.getSizeExpr();
4225 if (!origSize) origSize = T->getSizeExpr();
4226
4227 ExprResult sizeResult
4228 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004229 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004230 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004231 return QualType();
4232
John McCall33ddac02011-01-19 10:06:00 +00004233 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004234
4235 QualType Result = TL.getType();
4236 if (getDerived().AlwaysRebuild() ||
4237 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004238 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004239 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4240 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004241 size,
John McCall550e0c22009-10-21 00:40:46 +00004242 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004243 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004244 if (Result.isNull())
4245 return QualType();
4246 }
John McCall550e0c22009-10-21 00:40:46 +00004247
4248 // We might have any sort of array type now, but fortunately they
4249 // all have the same location layout.
4250 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4251 NewTL.setLBracketLoc(TL.getLBracketLoc());
4252 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004253 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004254
4255 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004256}
Mike Stump11289f42009-09-09 15:08:12 +00004257
4258template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004259QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004260 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004261 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004262 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004263
4264 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265 QualType ElementType = getDerived().TransformType(T->getElementType());
4266 if (ElementType.isNull())
4267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004268
Richard Smith764d2fe2011-12-20 02:08:33 +00004269 // Vector sizes are constant expressions.
4270 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4271 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004272
John McCalldadc5752010-08-24 06:29:42 +00004273 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004274 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275 if (Size.isInvalid())
4276 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004277
John McCall550e0c22009-10-21 00:40:46 +00004278 QualType Result = TL.getType();
4279 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004280 ElementType != T->getElementType() ||
4281 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004282 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004283 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004284 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004285 if (Result.isNull())
4286 return QualType();
4287 }
John McCall550e0c22009-10-21 00:40:46 +00004288
4289 // Result might be dependent or not.
4290 if (isa<DependentSizedExtVectorType>(Result)) {
4291 DependentSizedExtVectorTypeLoc NewTL
4292 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4293 NewTL.setNameLoc(TL.getNameLoc());
4294 } else {
4295 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4296 NewTL.setNameLoc(TL.getNameLoc());
4297 }
4298
4299 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004300}
Mike Stump11289f42009-09-09 15:08:12 +00004301
4302template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004303QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004304 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004305 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004306 QualType ElementType = getDerived().TransformType(T->getElementType());
4307 if (ElementType.isNull())
4308 return QualType();
4309
John McCall550e0c22009-10-21 00:40:46 +00004310 QualType Result = TL.getType();
4311 if (getDerived().AlwaysRebuild() ||
4312 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004313 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004314 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004315 if (Result.isNull())
4316 return QualType();
4317 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004318
John McCall550e0c22009-10-21 00:40:46 +00004319 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4320 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004321
John McCall550e0c22009-10-21 00:40:46 +00004322 return Result;
4323}
4324
4325template<typename Derived>
4326QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004327 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004328 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004329 QualType ElementType = getDerived().TransformType(T->getElementType());
4330 if (ElementType.isNull())
4331 return QualType();
4332
4333 QualType Result = TL.getType();
4334 if (getDerived().AlwaysRebuild() ||
4335 ElementType != T->getElementType()) {
4336 Result = getDerived().RebuildExtVectorType(ElementType,
4337 T->getNumElements(),
4338 /*FIXME*/ SourceLocation());
4339 if (Result.isNull())
4340 return QualType();
4341 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004342
John McCall550e0c22009-10-21 00:40:46 +00004343 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4344 NewTL.setNameLoc(TL.getNameLoc());
4345
4346 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004347}
Mike Stump11289f42009-09-09 15:08:12 +00004348
David Blaikie05785d12013-02-20 22:23:23 +00004349template <typename Derived>
4350ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4351 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4352 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004353 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004354 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004355
Douglas Gregor715e4612011-01-14 22:40:04 +00004356 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004357 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004358 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004359 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004360 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004361
Douglas Gregor715e4612011-01-14 22:40:04 +00004362 TypeLocBuilder TLB;
4363 TypeLoc NewTL = OldDI->getTypeLoc();
4364 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004365
4366 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004367 OldExpansionTL.getPatternLoc());
4368 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004369 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004370
4371 Result = RebuildPackExpansionType(Result,
4372 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004373 OldExpansionTL.getEllipsisLoc(),
4374 NumExpansions);
4375 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004376 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004377
Douglas Gregor715e4612011-01-14 22:40:04 +00004378 PackExpansionTypeLoc NewExpansionTL
4379 = TLB.push<PackExpansionTypeLoc>(Result);
4380 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4381 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4382 } else
4383 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004384 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004385 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004386
John McCall8fb0d9d2011-05-01 22:35:37 +00004387 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004388 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004389
4390 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4391 OldParm->getDeclContext(),
4392 OldParm->getInnerLocStart(),
4393 OldParm->getLocation(),
4394 OldParm->getIdentifier(),
4395 NewDI->getType(),
4396 NewDI,
4397 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004398 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004399 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4400 OldParm->getFunctionScopeIndex() + indexAdjustment);
4401 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004402}
4403
4404template<typename Derived>
4405bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004406 TransformFunctionTypeParams(SourceLocation Loc,
4407 ParmVarDecl **Params, unsigned NumParams,
4408 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004409 SmallVectorImpl<QualType> &OutParamTypes,
4410 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004411 int indexAdjustment = 0;
4412
Douglas Gregordd472162011-01-07 00:20:55 +00004413 for (unsigned i = 0; i != NumParams; ++i) {
4414 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004415 assert(OldParm->getFunctionScopeIndex() == i);
4416
David Blaikie05785d12013-02-20 22:23:23 +00004417 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004418 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004419 if (OldParm->isParameterPack()) {
4420 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004421 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004422
Douglas Gregor5499af42011-01-05 23:12:31 +00004423 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004424 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004425 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004426 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4427 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004428 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4429
Douglas Gregor5499af42011-01-05 23:12:31 +00004430 // Determine whether we should expand the parameter packs.
4431 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004432 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004433 Optional<unsigned> OrigNumExpansions =
4434 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004435 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004436 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4437 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004438 Unexpanded,
4439 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004440 RetainExpansion,
4441 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004442 return true;
4443 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004444
Douglas Gregor5499af42011-01-05 23:12:31 +00004445 if (ShouldExpand) {
4446 // Expand the function parameter pack into multiple, separate
4447 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004448 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004449 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004451 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004452 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004453 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004454 OrigNumExpansions,
4455 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004456 if (!NewParm)
4457 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004458
Douglas Gregordd472162011-01-07 00:20:55 +00004459 OutParamTypes.push_back(NewParm->getType());
4460 if (PVars)
4461 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004462 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004463
4464 // If we're supposed to retain a pack expansion, do so by temporarily
4465 // forgetting the partially-substituted parameter pack.
4466 if (RetainExpansion) {
4467 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004468 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004469 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004470 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004471 OrigNumExpansions,
4472 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004473 if (!NewParm)
4474 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004475
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004476 OutParamTypes.push_back(NewParm->getType());
4477 if (PVars)
4478 PVars->push_back(NewParm);
4479 }
4480
John McCall8fb0d9d2011-05-01 22:35:37 +00004481 // The next parameter should have the same adjustment as the
4482 // last thing we pushed, but we post-incremented indexAdjustment
4483 // on every push. Also, if we push nothing, the adjustment should
4484 // go down by one.
4485 indexAdjustment--;
4486
Douglas Gregor5499af42011-01-05 23:12:31 +00004487 // We're done with the pack expansion.
4488 continue;
4489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004490
4491 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004492 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004493 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4494 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004495 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004496 NumExpansions,
4497 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004498 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004499 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004500 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004501 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004502
John McCall58f10c32010-03-11 09:03:00 +00004503 if (!NewParm)
4504 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004505
Douglas Gregordd472162011-01-07 00:20:55 +00004506 OutParamTypes.push_back(NewParm->getType());
4507 if (PVars)
4508 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004509 continue;
4510 }
John McCall58f10c32010-03-11 09:03:00 +00004511
4512 // Deal with the possibility that we don't have a parameter
4513 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004514 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004515 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004516 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004517 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004518 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004519 = dyn_cast<PackExpansionType>(OldType)) {
4520 // We have a function parameter pack that may need to be expanded.
4521 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004522 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004523 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004524
Douglas Gregor5499af42011-01-05 23:12:31 +00004525 // Determine whether we should expand the parameter packs.
4526 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004527 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004528 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004529 Unexpanded,
4530 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004531 RetainExpansion,
4532 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004533 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004534 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004535
Douglas Gregor5499af42011-01-05 23:12:31 +00004536 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004537 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004538 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004539 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004540 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4541 QualType NewType = getDerived().TransformType(Pattern);
4542 if (NewType.isNull())
4543 return true;
John McCall58f10c32010-03-11 09:03:00 +00004544
Douglas Gregordd472162011-01-07 00:20:55 +00004545 OutParamTypes.push_back(NewType);
4546 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004547 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004548 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004549
Douglas Gregor5499af42011-01-05 23:12:31 +00004550 // We're done with the pack expansion.
4551 continue;
4552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004553
Douglas Gregor48d24112011-01-10 20:53:55 +00004554 // If we're supposed to retain a pack expansion, do so by temporarily
4555 // forgetting the partially-substituted parameter pack.
4556 if (RetainExpansion) {
4557 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4558 QualType NewType = getDerived().TransformType(Pattern);
4559 if (NewType.isNull())
4560 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004561
Douglas Gregor48d24112011-01-10 20:53:55 +00004562 OutParamTypes.push_back(NewType);
4563 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004564 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004565 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004566
Chad Rosier1dcde962012-08-08 18:46:20 +00004567 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004568 // expansion.
4569 OldType = Expansion->getPattern();
4570 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004571 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4572 NewType = getDerived().TransformType(OldType);
4573 } else {
4574 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004576
Douglas Gregor5499af42011-01-05 23:12:31 +00004577 if (NewType.isNull())
4578 return true;
4579
4580 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004581 NewType = getSema().Context.getPackExpansionType(NewType,
4582 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004583
Douglas Gregordd472162011-01-07 00:20:55 +00004584 OutParamTypes.push_back(NewType);
4585 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004586 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004587 }
4588
John McCall8fb0d9d2011-05-01 22:35:37 +00004589#ifndef NDEBUG
4590 if (PVars) {
4591 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4592 if (ParmVarDecl *parm = (*PVars)[i])
4593 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004594 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004595#endif
4596
4597 return false;
4598}
John McCall58f10c32010-03-11 09:03:00 +00004599
4600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004601QualType
John McCall550e0c22009-10-21 00:40:46 +00004602TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004603 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004604 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004605 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004606 return getDerived().TransformFunctionProtoType(
4607 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004608 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4609 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4610 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004611 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004612}
4613
Richard Smith2e321552014-11-12 02:00:47 +00004614template<typename Derived> template<typename Fn>
4615QualType TreeTransform<Derived>::TransformFunctionProtoType(
4616 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4617 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004618 // Transform the parameters and return type.
4619 //
Richard Smithf623c962012-04-17 00:58:00 +00004620 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004621 // When the function has a trailing return type, we instantiate the
4622 // parameters before the return type, since the return type can then refer
4623 // to the parameters themselves (via decltype, sizeof, etc.).
4624 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004625 SmallVector<QualType, 4> ParamTypes;
4626 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004627 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004628
Douglas Gregor7fb25412010-10-01 18:44:50 +00004629 QualType ResultType;
4630
Richard Smith1226c602012-08-14 22:51:13 +00004631 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004632 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004633 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004634 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004635 return QualType();
4636
Douglas Gregor3024f072012-04-16 07:05:22 +00004637 {
4638 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004639 // If a declaration declares a member function or member function
4640 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004641 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004642 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004643 // declarator.
4644 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004645
Alp Toker42a16a62014-01-25 23:51:36 +00004646 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004647 if (ResultType.isNull())
4648 return QualType();
4649 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004650 }
4651 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004652 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004653 if (ResultType.isNull())
4654 return QualType();
4655
Alp Toker9cacbab2014-01-20 20:26:09 +00004656 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004657 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004658 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004659 return QualType();
4660 }
4661
Richard Smith2e321552014-11-12 02:00:47 +00004662 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4663
4664 bool EPIChanged = false;
4665 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4666 return QualType();
4667
4668 // FIXME: Need to transform ConsumedParameters for variadic template
4669 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004670
John McCall550e0c22009-10-21 00:40:46 +00004671 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004672 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004673 T->getNumParams() != ParamTypes.size() ||
4674 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004675 ParamTypes.begin()) || EPIChanged) {
4676 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004677 if (Result.isNull())
4678 return QualType();
4679 }
Mike Stump11289f42009-09-09 15:08:12 +00004680
John McCall550e0c22009-10-21 00:40:46 +00004681 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004682 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004683 NewTL.setLParenLoc(TL.getLParenLoc());
4684 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004685 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004686 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4687 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004688
4689 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004690}
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregord6ff3322009-08-04 16:50:30 +00004692template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004693bool TreeTransform<Derived>::TransformExceptionSpec(
4694 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4695 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4696 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4697
4698 // Instantiate a dynamic noexcept expression, if any.
4699 if (ESI.Type == EST_ComputedNoexcept) {
4700 EnterExpressionEvaluationContext Unevaluated(getSema(),
4701 Sema::ConstantEvaluated);
4702 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4703 if (NoexceptExpr.isInvalid())
4704 return true;
4705
4706 NoexceptExpr = getSema().CheckBooleanCondition(
4707 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4708 if (NoexceptExpr.isInvalid())
4709 return true;
4710
4711 if (!NoexceptExpr.get()->isValueDependent()) {
4712 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4713 NoexceptExpr.get(), nullptr,
4714 diag::err_noexcept_needs_constant_expression,
4715 /*AllowFold*/false);
4716 if (NoexceptExpr.isInvalid())
4717 return true;
4718 }
4719
4720 if (ESI.NoexceptExpr != NoexceptExpr.get())
4721 Changed = true;
4722 ESI.NoexceptExpr = NoexceptExpr.get();
4723 }
4724
4725 if (ESI.Type != EST_Dynamic)
4726 return false;
4727
4728 // Instantiate a dynamic exception specification's type.
4729 for (QualType T : ESI.Exceptions) {
4730 if (const PackExpansionType *PackExpansion =
4731 T->getAs<PackExpansionType>()) {
4732 Changed = true;
4733
4734 // We have a pack expansion. Instantiate it.
4735 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4736 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4737 Unexpanded);
4738 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4739
4740 // Determine whether the set of unexpanded parameter packs can and
4741 // should
4742 // be expanded.
4743 bool Expand = false;
4744 bool RetainExpansion = false;
4745 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4746 // FIXME: Track the location of the ellipsis (and track source location
4747 // information for the types in the exception specification in general).
4748 if (getDerived().TryExpandParameterPacks(
4749 Loc, SourceRange(), Unexpanded, Expand,
4750 RetainExpansion, NumExpansions))
4751 return true;
4752
4753 if (!Expand) {
4754 // We can't expand this pack expansion into separate arguments yet;
4755 // just substitute into the pattern and create a new pack expansion
4756 // type.
4757 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4758 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4759 if (U.isNull())
4760 return true;
4761
4762 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4763 Exceptions.push_back(U);
4764 continue;
4765 }
4766
4767 // Substitute into the pack expansion pattern for each slice of the
4768 // pack.
4769 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4770 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4771
4772 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4773 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4774 return true;
4775
4776 Exceptions.push_back(U);
4777 }
4778 } else {
4779 QualType U = getDerived().TransformType(T);
4780 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4781 return true;
4782 if (T != U)
4783 Changed = true;
4784
4785 Exceptions.push_back(U);
4786 }
4787 }
4788
4789 ESI.Exceptions = Exceptions;
4790 return false;
4791}
4792
4793template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004794QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004795 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004796 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004797 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004798 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004799 if (ResultType.isNull())
4800 return QualType();
4801
4802 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004803 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004804 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4805
4806 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004807 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004808 NewTL.setLParenLoc(TL.getLParenLoc());
4809 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004810 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004811
4812 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004813}
Mike Stump11289f42009-09-09 15:08:12 +00004814
John McCallb96ec562009-12-04 22:46:56 +00004815template<typename Derived> QualType
4816TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004817 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004818 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004819 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004820 if (!D)
4821 return QualType();
4822
4823 QualType Result = TL.getType();
4824 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4825 Result = getDerived().RebuildUnresolvedUsingType(D);
4826 if (Result.isNull())
4827 return QualType();
4828 }
4829
4830 // We might get an arbitrary type spec type back. We should at
4831 // least always get a type spec type, though.
4832 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4833 NewTL.setNameLoc(TL.getNameLoc());
4834
4835 return Result;
4836}
4837
Douglas Gregord6ff3322009-08-04 16:50:30 +00004838template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004839QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004840 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004841 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004842 TypedefNameDecl *Typedef
4843 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4844 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004845 if (!Typedef)
4846 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004847
John McCall550e0c22009-10-21 00:40:46 +00004848 QualType Result = TL.getType();
4849 if (getDerived().AlwaysRebuild() ||
4850 Typedef != T->getDecl()) {
4851 Result = getDerived().RebuildTypedefType(Typedef);
4852 if (Result.isNull())
4853 return QualType();
4854 }
Mike Stump11289f42009-09-09 15:08:12 +00004855
John McCall550e0c22009-10-21 00:40:46 +00004856 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4857 NewTL.setNameLoc(TL.getNameLoc());
4858
4859 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregord6ff3322009-08-04 16:50:30 +00004862template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004863QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004864 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004865 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004866 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4867 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004868
John McCalldadc5752010-08-24 06:29:42 +00004869 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004870 if (E.isInvalid())
4871 return QualType();
4872
Eli Friedmane4f22df2012-02-29 04:03:55 +00004873 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4874 if (E.isInvalid())
4875 return QualType();
4876
John McCall550e0c22009-10-21 00:40:46 +00004877 QualType Result = TL.getType();
4878 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004879 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004880 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004881 if (Result.isNull())
4882 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004883 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004884 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004885
John McCall550e0c22009-10-21 00:40:46 +00004886 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004887 NewTL.setTypeofLoc(TL.getTypeofLoc());
4888 NewTL.setLParenLoc(TL.getLParenLoc());
4889 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004890
4891 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892}
Mike Stump11289f42009-09-09 15:08:12 +00004893
4894template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004895QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004896 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004897 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4898 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4899 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004900 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004901
John McCall550e0c22009-10-21 00:40:46 +00004902 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004903 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4904 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004905 if (Result.isNull())
4906 return QualType();
4907 }
Mike Stump11289f42009-09-09 15:08:12 +00004908
John McCall550e0c22009-10-21 00:40:46 +00004909 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004910 NewTL.setTypeofLoc(TL.getTypeofLoc());
4911 NewTL.setLParenLoc(TL.getLParenLoc());
4912 NewTL.setRParenLoc(TL.getRParenLoc());
4913 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004914
4915 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004916}
Mike Stump11289f42009-09-09 15:08:12 +00004917
4918template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004919QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004920 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004921 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004922
Douglas Gregore922c772009-08-04 22:27:00 +00004923 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004924 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4925 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004926
John McCalldadc5752010-08-24 06:29:42 +00004927 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004928 if (E.isInvalid())
4929 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004930
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004931 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004932 if (E.isInvalid())
4933 return QualType();
4934
John McCall550e0c22009-10-21 00:40:46 +00004935 QualType Result = TL.getType();
4936 if (getDerived().AlwaysRebuild() ||
4937 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004938 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004939 if (Result.isNull())
4940 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004941 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004942 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004943
John McCall550e0c22009-10-21 00:40:46 +00004944 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4945 NewTL.setNameLoc(TL.getNameLoc());
4946
4947 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004948}
4949
4950template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004951QualType TreeTransform<Derived>::TransformUnaryTransformType(
4952 TypeLocBuilder &TLB,
4953 UnaryTransformTypeLoc TL) {
4954 QualType Result = TL.getType();
4955 if (Result->isDependentType()) {
4956 const UnaryTransformType *T = TL.getTypePtr();
4957 QualType NewBase =
4958 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4959 Result = getDerived().RebuildUnaryTransformType(NewBase,
4960 T->getUTTKind(),
4961 TL.getKWLoc());
4962 if (Result.isNull())
4963 return QualType();
4964 }
4965
4966 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4967 NewTL.setKWLoc(TL.getKWLoc());
4968 NewTL.setParensRange(TL.getParensRange());
4969 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4970 return Result;
4971}
4972
4973template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004974QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4975 AutoTypeLoc TL) {
4976 const AutoType *T = TL.getTypePtr();
4977 QualType OldDeduced = T->getDeducedType();
4978 QualType NewDeduced;
4979 if (!OldDeduced.isNull()) {
4980 NewDeduced = getDerived().TransformType(OldDeduced);
4981 if (NewDeduced.isNull())
4982 return QualType();
4983 }
4984
4985 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004986 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4987 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004988 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004989 if (Result.isNull())
4990 return QualType();
4991 }
4992
4993 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4994 NewTL.setNameLoc(TL.getNameLoc());
4995
4996 return Result;
4997}
4998
4999template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005000QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005001 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005002 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005003 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005004 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5005 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005006 if (!Record)
5007 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005008
John McCall550e0c22009-10-21 00:40:46 +00005009 QualType Result = TL.getType();
5010 if (getDerived().AlwaysRebuild() ||
5011 Record != T->getDecl()) {
5012 Result = getDerived().RebuildRecordType(Record);
5013 if (Result.isNull())
5014 return QualType();
5015 }
Mike Stump11289f42009-09-09 15:08:12 +00005016
John McCall550e0c22009-10-21 00:40:46 +00005017 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5018 NewTL.setNameLoc(TL.getNameLoc());
5019
5020 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
5023template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005024QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005025 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005026 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005027 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005028 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5029 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005030 if (!Enum)
5031 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005032
John McCall550e0c22009-10-21 00:40:46 +00005033 QualType Result = TL.getType();
5034 if (getDerived().AlwaysRebuild() ||
5035 Enum != T->getDecl()) {
5036 Result = getDerived().RebuildEnumType(Enum);
5037 if (Result.isNull())
5038 return QualType();
5039 }
Mike Stump11289f42009-09-09 15:08:12 +00005040
John McCall550e0c22009-10-21 00:40:46 +00005041 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5042 NewTL.setNameLoc(TL.getNameLoc());
5043
5044 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005045}
John McCallfcc33b02009-09-05 00:15:47 +00005046
John McCalle78aac42010-03-10 03:28:59 +00005047template<typename Derived>
5048QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5049 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005050 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005051 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5052 TL.getTypePtr()->getDecl());
5053 if (!D) return QualType();
5054
5055 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5056 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5057 return T;
5058}
5059
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060template<typename Derived>
5061QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005062 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005063 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005064 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005065}
5066
Mike Stump11289f42009-09-09 15:08:12 +00005067template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005068QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005069 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005070 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005071 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005072
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005073 // Substitute into the replacement type, which itself might involve something
5074 // that needs to be transformed. This only tends to occur with default
5075 // template arguments of template template parameters.
5076 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5077 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5078 if (Replacement.isNull())
5079 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005080
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005081 // Always canonicalize the replacement type.
5082 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5083 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005084 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005085 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005086
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005087 // Propagate type-source information.
5088 SubstTemplateTypeParmTypeLoc NewTL
5089 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5090 NewTL.setNameLoc(TL.getNameLoc());
5091 return Result;
5092
John McCallcebee162009-10-18 09:09:24 +00005093}
5094
5095template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005096QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5097 TypeLocBuilder &TLB,
5098 SubstTemplateTypeParmPackTypeLoc TL) {
5099 return TransformTypeSpecType(TLB, TL);
5100}
5101
5102template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005103QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005104 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005105 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005106 const TemplateSpecializationType *T = TL.getTypePtr();
5107
Douglas Gregordf846d12011-03-02 18:46:51 +00005108 // The nested-name-specifier never matters in a TemplateSpecializationType,
5109 // because we can't have a dependent nested-name-specifier anyway.
5110 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005111 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005112 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5113 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005114 if (Template.isNull())
5115 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005116
John McCall31f82722010-11-12 08:19:04 +00005117 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5118}
5119
Eli Friedman0dfb8892011-10-06 23:00:33 +00005120template<typename Derived>
5121QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5122 AtomicTypeLoc TL) {
5123 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5124 if (ValueType.isNull())
5125 return QualType();
5126
5127 QualType Result = TL.getType();
5128 if (getDerived().AlwaysRebuild() ||
5129 ValueType != TL.getValueLoc().getType()) {
5130 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5131 if (Result.isNull())
5132 return QualType();
5133 }
5134
5135 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5136 NewTL.setKWLoc(TL.getKWLoc());
5137 NewTL.setLParenLoc(TL.getLParenLoc());
5138 NewTL.setRParenLoc(TL.getRParenLoc());
5139
5140 return Result;
5141}
5142
Chad Rosier1dcde962012-08-08 18:46:20 +00005143 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005144 /// container that provides a \c getArgLoc() member function.
5145 ///
5146 /// This iterator is intended to be used with the iterator form of
5147 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5148 template<typename ArgLocContainer>
5149 class TemplateArgumentLocContainerIterator {
5150 ArgLocContainer *Container;
5151 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005152
Douglas Gregorfe921a72010-12-20 23:36:19 +00005153 public:
5154 typedef TemplateArgumentLoc value_type;
5155 typedef TemplateArgumentLoc reference;
5156 typedef int difference_type;
5157 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005158
Douglas Gregorfe921a72010-12-20 23:36:19 +00005159 class pointer {
5160 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005161
Douglas Gregorfe921a72010-12-20 23:36:19 +00005162 public:
5163 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005164
Douglas Gregorfe921a72010-12-20 23:36:19 +00005165 const TemplateArgumentLoc *operator->() const {
5166 return &Arg;
5167 }
5168 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005169
5170
Douglas Gregorfe921a72010-12-20 23:36:19 +00005171 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005172
Douglas Gregorfe921a72010-12-20 23:36:19 +00005173 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5174 unsigned Index)
5175 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005176
Douglas Gregorfe921a72010-12-20 23:36:19 +00005177 TemplateArgumentLocContainerIterator &operator++() {
5178 ++Index;
5179 return *this;
5180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005181
Douglas Gregorfe921a72010-12-20 23:36:19 +00005182 TemplateArgumentLocContainerIterator operator++(int) {
5183 TemplateArgumentLocContainerIterator Old(*this);
5184 ++(*this);
5185 return Old;
5186 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005187
Douglas Gregorfe921a72010-12-20 23:36:19 +00005188 TemplateArgumentLoc operator*() const {
5189 return Container->getArgLoc(Index);
5190 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005191
Douglas Gregorfe921a72010-12-20 23:36:19 +00005192 pointer operator->() const {
5193 return pointer(Container->getArgLoc(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.Container == Y.Container && X.Index == Y.Index;
5199 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005200
Douglas Gregorfe921a72010-12-20 23:36:19 +00005201 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005202 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005203 return !(X == Y);
5204 }
5205 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005206
5207
John McCall31f82722010-11-12 08:19:04 +00005208template <typename Derived>
5209QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5210 TypeLocBuilder &TLB,
5211 TemplateSpecializationTypeLoc TL,
5212 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005213 TemplateArgumentListInfo NewTemplateArgs;
5214 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5215 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005216 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5217 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005218 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005219 ArgIterator(TL, TL.getNumArgs()),
5220 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005221 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005222
John McCall0ad16662009-10-29 08:12:44 +00005223 // FIXME: maybe don't rebuild if all the template arguments are the same.
5224
5225 QualType Result =
5226 getDerived().RebuildTemplateSpecializationType(Template,
5227 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005228 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005229
5230 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005231 // Specializations of template template parameters are represented as
5232 // TemplateSpecializationTypes, and substitution of type alias templates
5233 // within a dependent context can transform them into
5234 // DependentTemplateSpecializationTypes.
5235 if (isa<DependentTemplateSpecializationType>(Result)) {
5236 DependentTemplateSpecializationTypeLoc NewTL
5237 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005238 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005239 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005240 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005241 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005242 NewTL.setLAngleLoc(TL.getLAngleLoc());
5243 NewTL.setRAngleLoc(TL.getRAngleLoc());
5244 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5245 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5246 return Result;
5247 }
5248
John McCall0ad16662009-10-29 08:12:44 +00005249 TemplateSpecializationTypeLoc NewTL
5250 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005251 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005252 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5253 NewTL.setLAngleLoc(TL.getLAngleLoc());
5254 NewTL.setRAngleLoc(TL.getRAngleLoc());
5255 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5256 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005257 }
Mike Stump11289f42009-09-09 15:08:12 +00005258
John McCall0ad16662009-10-29 08:12:44 +00005259 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005260}
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregor5a064722011-02-28 17:23:35 +00005262template <typename Derived>
5263QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5264 TypeLocBuilder &TLB,
5265 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005266 TemplateName Template,
5267 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005268 TemplateArgumentListInfo NewTemplateArgs;
5269 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5270 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5271 typedef TemplateArgumentLocContainerIterator<
5272 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005273 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005274 ArgIterator(TL, TL.getNumArgs()),
5275 NewTemplateArgs))
5276 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005277
Douglas Gregor5a064722011-02-28 17:23:35 +00005278 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005279
Douglas Gregor5a064722011-02-28 17:23:35 +00005280 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5281 QualType Result
5282 = getSema().Context.getDependentTemplateSpecializationType(
5283 TL.getTypePtr()->getKeyword(),
5284 DTN->getQualifier(),
5285 DTN->getIdentifier(),
5286 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005287
Douglas Gregor5a064722011-02-28 17:23:35 +00005288 DependentTemplateSpecializationTypeLoc NewTL
5289 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005290 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005291 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005292 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005293 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005294 NewTL.setLAngleLoc(TL.getLAngleLoc());
5295 NewTL.setRAngleLoc(TL.getRAngleLoc());
5296 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5297 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5298 return Result;
5299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005300
5301 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005302 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005303 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005304 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005305
Douglas Gregor5a064722011-02-28 17:23:35 +00005306 if (!Result.isNull()) {
5307 /// FIXME: Wrap this in an elaborated-type-specifier?
5308 TemplateSpecializationTypeLoc NewTL
5309 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005310 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005311 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005312 NewTL.setLAngleLoc(TL.getLAngleLoc());
5313 NewTL.setRAngleLoc(TL.getRAngleLoc());
5314 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5315 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005317
Douglas Gregor5a064722011-02-28 17:23:35 +00005318 return Result;
5319}
5320
Mike Stump11289f42009-09-09 15:08:12 +00005321template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005322QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005323TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005324 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005325 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005326
Douglas Gregor844cb502011-03-01 18:12:44 +00005327 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005328 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005329 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005330 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005331 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5332 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005333 return QualType();
5334 }
Mike Stump11289f42009-09-09 15:08:12 +00005335
John McCall31f82722010-11-12 08:19:04 +00005336 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5337 if (NamedT.isNull())
5338 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005339
Richard Smith3f1b5d02011-05-05 21:57:07 +00005340 // C++0x [dcl.type.elab]p2:
5341 // If the identifier resolves to a typedef-name or the simple-template-id
5342 // resolves to an alias template specialization, the
5343 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005344 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5345 if (const TemplateSpecializationType *TST =
5346 NamedT->getAs<TemplateSpecializationType>()) {
5347 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005348 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5349 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005350 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5351 diag::err_tag_reference_non_tag) << 4;
5352 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5353 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005354 }
5355 }
5356
John McCall550e0c22009-10-21 00:40:46 +00005357 QualType Result = TL.getType();
5358 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005359 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005360 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005361 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005362 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005363 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005364 if (Result.isNull())
5365 return QualType();
5366 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005367
Abramo Bagnara6150c882010-05-11 21:36:43 +00005368 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005369 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005370 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005371 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005372}
Mike Stump11289f42009-09-09 15:08:12 +00005373
5374template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005375QualType TreeTransform<Derived>::TransformAttributedType(
5376 TypeLocBuilder &TLB,
5377 AttributedTypeLoc TL) {
5378 const AttributedType *oldType = TL.getTypePtr();
5379 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5380 if (modifiedType.isNull())
5381 return QualType();
5382
5383 QualType result = TL.getType();
5384
5385 // FIXME: dependent operand expressions?
5386 if (getDerived().AlwaysRebuild() ||
5387 modifiedType != oldType->getModifiedType()) {
5388 // TODO: this is really lame; we should really be rebuilding the
5389 // equivalent type from first principles.
5390 QualType equivalentType
5391 = getDerived().TransformType(oldType->getEquivalentType());
5392 if (equivalentType.isNull())
5393 return QualType();
5394 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5395 modifiedType,
5396 equivalentType);
5397 }
5398
5399 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5400 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5401 if (TL.hasAttrOperand())
5402 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5403 if (TL.hasAttrExprOperand())
5404 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5405 else if (TL.hasAttrEnumOperand())
5406 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5407
5408 return result;
5409}
5410
5411template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005412QualType
5413TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5414 ParenTypeLoc TL) {
5415 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5416 if (Inner.isNull())
5417 return QualType();
5418
5419 QualType Result = TL.getType();
5420 if (getDerived().AlwaysRebuild() ||
5421 Inner != TL.getInnerLoc().getType()) {
5422 Result = getDerived().RebuildParenType(Inner);
5423 if (Result.isNull())
5424 return QualType();
5425 }
5426
5427 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5428 NewTL.setLParenLoc(TL.getLParenLoc());
5429 NewTL.setRParenLoc(TL.getRParenLoc());
5430 return Result;
5431}
5432
5433template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005434QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005435 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005436 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005437
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005438 NestedNameSpecifierLoc QualifierLoc
5439 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5440 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005441 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005442
John McCallc392f372010-06-11 00:33:02 +00005443 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005444 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005445 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005446 QualifierLoc,
5447 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005448 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005449 if (Result.isNull())
5450 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005451
Abramo Bagnarad7548482010-05-19 21:37:53 +00005452 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5453 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005454 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5455
Abramo Bagnarad7548482010-05-19 21:37:53 +00005456 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005457 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005458 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005459 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005460 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005461 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005462 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005463 NewTL.setNameLoc(TL.getNameLoc());
5464 }
John McCall550e0c22009-10-21 00:40:46 +00005465 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005466}
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregord6ff3322009-08-04 16:50:30 +00005468template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005469QualType TreeTransform<Derived>::
5470 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005471 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005472 NestedNameSpecifierLoc QualifierLoc;
5473 if (TL.getQualifierLoc()) {
5474 QualifierLoc
5475 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5476 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005477 return QualType();
5478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
John McCall31f82722010-11-12 08:19:04 +00005480 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005481 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005482}
5483
5484template<typename Derived>
5485QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005486TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5487 DependentTemplateSpecializationTypeLoc TL,
5488 NestedNameSpecifierLoc QualifierLoc) {
5489 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005490
Douglas Gregora7a795b2011-03-01 20:11:18 +00005491 TemplateArgumentListInfo NewTemplateArgs;
5492 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5493 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005494
Douglas Gregora7a795b2011-03-01 20:11:18 +00005495 typedef TemplateArgumentLocContainerIterator<
5496 DependentTemplateSpecializationTypeLoc> ArgIterator;
5497 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5498 ArgIterator(TL, TL.getNumArgs()),
5499 NewTemplateArgs))
5500 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005501
Douglas Gregora7a795b2011-03-01 20:11:18 +00005502 QualType Result
5503 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5504 QualifierLoc,
5505 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005506 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005507 NewTemplateArgs);
5508 if (Result.isNull())
5509 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005510
Douglas Gregora7a795b2011-03-01 20:11:18 +00005511 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5512 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005513
Douglas Gregora7a795b2011-03-01 20:11:18 +00005514 // Copy information relevant to the template specialization.
5515 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005516 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005517 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005518 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005519 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5520 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005521 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005522 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005523
Douglas Gregora7a795b2011-03-01 20:11:18 +00005524 // Copy information relevant to the elaborated type.
5525 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005526 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005527 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005528 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5529 DependentTemplateSpecializationTypeLoc SpecTL
5530 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005531 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005532 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005533 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005534 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005535 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5536 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005537 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005538 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005539 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005540 TemplateSpecializationTypeLoc SpecTL
5541 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005542 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005543 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005544 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5545 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005546 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005547 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005548 }
5549 return Result;
5550}
5551
5552template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005553QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5554 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005555 QualType Pattern
5556 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005557 if (Pattern.isNull())
5558 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005559
5560 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005561 if (getDerived().AlwaysRebuild() ||
5562 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005563 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005564 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005565 TL.getEllipsisLoc(),
5566 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005567 if (Result.isNull())
5568 return QualType();
5569 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005570
Douglas Gregor822d0302011-01-12 17:07:58 +00005571 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5572 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5573 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005574}
5575
5576template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005577QualType
5578TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005579 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005580 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005581 TLB.pushFullCopy(TL);
5582 return TL.getType();
5583}
5584
5585template<typename Derived>
5586QualType
5587TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005588 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005589 // ObjCObjectType is never dependent.
5590 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005591 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
5594template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005595QualType
5596TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005597 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005598 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005599 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005600 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005601}
5602
Douglas Gregord6ff3322009-08-04 16:50:30 +00005603//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005604// Statement transformation
5605//===----------------------------------------------------------------------===//
5606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005607StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005608TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005609 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005610}
5611
5612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005614TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5615 return getDerived().TransformCompoundStmt(S, false);
5616}
5617
5618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005620TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005622 Sema::CompoundScopeRAII CompoundScope(getSema());
5623
John McCall1ababa62010-08-27 19:56:05 +00005624 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005625 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005626 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005627 for (auto *B : S->body()) {
5628 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005629 if (Result.isInvalid()) {
5630 // Immediately fail if this was a DeclStmt, since it's very
5631 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005632 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005633 return StmtError();
5634
5635 // Otherwise, just keep processing substatements and fail later.
5636 SubStmtInvalid = true;
5637 continue;
5638 }
Mike Stump11289f42009-09-09 15:08:12 +00005639
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005640 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005641 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005642 }
Mike Stump11289f42009-09-09 15:08:12 +00005643
John McCall1ababa62010-08-27 19:56:05 +00005644 if (SubStmtInvalid)
5645 return StmtError();
5646
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 if (!getDerived().AlwaysRebuild() &&
5648 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005649 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005650
5651 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005652 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005653 S->getRBracLoc(),
5654 IsStmtExpr);
5655}
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorebe10102009-08-20 07:17:43 +00005657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005658StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005659TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005660 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005661 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005662 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5663 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005664
Eli Friedman06577382009-11-19 03:14:00 +00005665 // Transform the left-hand case value.
5666 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005667 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005668 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005669 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005670
Eli Friedman06577382009-11-19 03:14:00 +00005671 // Transform the right-hand case value (for the GNU case-range extension).
5672 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005673 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005674 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005676 }
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 // Build the case statement.
5679 // Case statements are always rebuilt so that they will attached to their
5680 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005681 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005682 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005684 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005685 S->getColonLoc());
5686 if (Case.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 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005690 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005691 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005692 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005695 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005696}
5697
5698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005699StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005700TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005702 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005703 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregorebe10102009-08-20 07:17:43 +00005706 // Default statements are always rebuilt
5707 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005708 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005709}
Mike Stump11289f42009-09-09 15:08:12 +00005710
Douglas Gregorebe10102009-08-20 07:17:43 +00005711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005712StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005713TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005714 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005715 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005716 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005717
Chris Lattnercab02a62011-02-17 20:34:02 +00005718 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5719 S->getDecl());
5720 if (!LD)
5721 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005722
5723
Douglas Gregorebe10102009-08-20 07:17:43 +00005724 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005725 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005726 cast<LabelDecl>(LD), SourceLocation(),
5727 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005728}
Mike Stump11289f42009-09-09 15:08:12 +00005729
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005730template <typename Derived>
5731const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5732 if (!R)
5733 return R;
5734
5735 switch (R->getKind()) {
5736// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5737#define ATTR(X)
5738#define PRAGMA_SPELLING_ATTR(X) \
5739 case attr::X: \
5740 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5741#include "clang/Basic/AttrList.inc"
5742 default:
5743 return R;
5744 }
5745}
5746
5747template <typename Derived>
5748StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5749 bool AttrsChanged = false;
5750 SmallVector<const Attr *, 1> Attrs;
5751
5752 // Visit attributes and keep track if any are transformed.
5753 for (const auto *I : S->getAttrs()) {
5754 const Attr *R = getDerived().TransformAttr(I);
5755 AttrsChanged |= (I != R);
5756 Attrs.push_back(R);
5757 }
5758
Richard Smithc202b282012-04-14 00:33:13 +00005759 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5760 if (SubStmt.isInvalid())
5761 return StmtError();
5762
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005763 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005764 return S;
5765
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005766 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005767 SubStmt.get());
5768}
5769
5770template<typename Derived>
5771StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005772TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005773 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005774 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005775 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005776 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005777 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005778 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005779 getDerived().TransformDefinition(
5780 S->getConditionVariable()->getLocation(),
5781 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005782 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005783 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005784 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005785 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005786
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005787 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005788 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005789
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005790 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005791 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005792 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005793 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005794 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005795 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005796
John McCallb268a282010-08-23 23:25:46 +00005797 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005798 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005800
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005801 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005802 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005803 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005804
Douglas Gregorebe10102009-08-20 07:17:43 +00005805 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005806 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005807 if (Then.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 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005811 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005812 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005813 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005814
Douglas Gregorebe10102009-08-20 07:17:43 +00005815 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005816 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005817 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005818 Then.get() == S->getThen() &&
5819 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005820 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005822 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005823 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005824 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005825}
5826
5827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005828StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005829TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005830 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005831 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005832 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005833 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005834 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005835 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005836 getDerived().TransformDefinition(
5837 S->getConditionVariable()->getLocation(),
5838 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005839 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005841 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005842 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005843
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005844 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005845 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005846 }
Mike Stump11289f42009-09-09 15:08:12 +00005847
Douglas Gregorebe10102009-08-20 07:17:43 +00005848 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005849 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005850 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005851 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005852 if (Switch.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 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005856 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005857 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005858 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregorebe10102009-08-20 07:17:43 +00005860 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005861 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5862 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005863}
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregorebe10102009-08-20 07:17:43 +00005865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005866StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005867TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005868 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005869 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005870 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005871 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005872 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005873 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005874 getDerived().TransformDefinition(
5875 S->getConditionVariable()->getLocation(),
5876 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005877 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005879 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005880 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005881
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005882 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005883 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005884
5885 if (S->getCond()) {
5886 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005887 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5888 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005889 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005890 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005891 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005892 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005893 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005894 }
Mike Stump11289f42009-09-09 15:08:12 +00005895
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005896 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005897 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005899
Douglas Gregorebe10102009-08-20 07:17:43 +00005900 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005901 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005902 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005904
Douglas Gregorebe10102009-08-20 07:17:43 +00005905 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005906 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005907 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005908 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005909 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005910
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005911 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005912 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005913}
Mike Stump11289f42009-09-09 15:08:12 +00005914
Douglas Gregorebe10102009-08-20 07:17:43 +00005915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005916StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005917TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005918 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005919 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005923 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005924 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005925 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005927
Douglas Gregorebe10102009-08-20 07:17:43 +00005928 if (!getDerived().AlwaysRebuild() &&
5929 Cond.get() == S->getCond() &&
5930 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005931 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005932
John McCallb268a282010-08-23 23:25:46 +00005933 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5934 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005935 S->getRParenLoc());
5936}
Mike Stump11289f42009-09-09 15:08:12 +00005937
Douglas Gregorebe10102009-08-20 07:17:43 +00005938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005939StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005940TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005941 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005942 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005943 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005944 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005945
Douglas Gregorebe10102009-08-20 07:17:43 +00005946 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005947 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005948 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005949 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005950 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005951 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005952 getDerived().TransformDefinition(
5953 S->getConditionVariable()->getLocation(),
5954 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005955 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005957 } else {
5958 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005960 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005961 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005962
5963 if (S->getCond()) {
5964 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005965 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5966 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005967 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005968 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005969 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005970
John McCallb268a282010-08-23 23:25:46 +00005971 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005972 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005973 }
Mike Stump11289f42009-09-09 15:08:12 +00005974
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005975 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005976 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005978
Douglas Gregorebe10102009-08-20 07:17:43 +00005979 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005980 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005981 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005983
Richard Smith945f8d32013-01-14 22:39:08 +00005984 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005985 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005987
Douglas Gregorebe10102009-08-20 07:17:43 +00005988 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005989 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005990 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005991 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005992
Douglas Gregorebe10102009-08-20 07:17:43 +00005993 if (!getDerived().AlwaysRebuild() &&
5994 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005995 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005996 Inc.get() == S->getInc() &&
5997 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005998 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005999
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006001 Init.get(), FullCond, ConditionVar,
6002 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006003}
6004
6005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006006StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006007TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006008 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6009 S->getLabel());
6010 if (!LD)
6011 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006012
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006014 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006015 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006016}
6017
6018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006019StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006020TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006021 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006022 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006023 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006024 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregorebe10102009-08-20 07:17:43 +00006026 if (!getDerived().AlwaysRebuild() &&
6027 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006028 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006029
6030 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006031 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006032}
6033
6034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006035StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006036TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006037 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006038}
Mike Stump11289f42009-09-09 15:08:12 +00006039
Douglas Gregorebe10102009-08-20 07:17:43 +00006040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006041StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006042TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006043 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006044}
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregorebe10102009-08-20 07:17:43 +00006046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006047StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006048TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006049 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6050 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006051 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006052 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006053
Mike Stump11289f42009-09-09 15:08:12 +00006054 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006055 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006056 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006057}
Mike Stump11289f42009-09-09 15:08:12 +00006058
Douglas Gregorebe10102009-08-20 07:17:43 +00006059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006060StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006061TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006062 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006063 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006064 for (auto *D : S->decls()) {
6065 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006066 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006068
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006069 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006070 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregorebe10102009-08-20 07:17:43 +00006072 Decls.push_back(Transformed);
6073 }
Mike Stump11289f42009-09-09 15:08:12 +00006074
Douglas Gregorebe10102009-08-20 07:17:43 +00006075 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006076 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006077
Rafael Espindolaab417692013-07-09 12:05:01 +00006078 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006079}
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregorebe10102009-08-20 07:17:43 +00006081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006082StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006083TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006084
Benjamin Kramerf0623432012-08-23 22:51:59 +00006085 SmallVector<Expr*, 8> Constraints;
6086 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006087 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006088
John McCalldadc5752010-08-24 06:29:42 +00006089 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006090 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006091
6092 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006093
Anders Carlssonaaeef072010-01-24 05:50:09 +00006094 // Go through the outputs.
6095 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006096 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006097
Anders Carlssonaaeef072010-01-24 05:50:09 +00006098 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006099 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006100
Anders Carlssonaaeef072010-01-24 05:50:09 +00006101 // Transform the output expr.
6102 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006103 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006104 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006106
Anders Carlssonaaeef072010-01-24 05:50:09 +00006107 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006108
John McCallb268a282010-08-23 23:25:46 +00006109 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006111
Anders Carlssonaaeef072010-01-24 05:50:09 +00006112 // Go through the inputs.
6113 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006114 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006115
Anders Carlssonaaeef072010-01-24 05:50:09 +00006116 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006117 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006118
Anders Carlssonaaeef072010-01-24 05:50:09 +00006119 // Transform the input expr.
6120 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006121 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006122 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006123 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006124
Anders Carlssonaaeef072010-01-24 05:50:09 +00006125 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
John McCallb268a282010-08-23 23:25:46 +00006127 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006128 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006129
Anders Carlssonaaeef072010-01-24 05:50:09 +00006130 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006131 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006132
6133 // Go through the clobbers.
6134 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006135 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006136
6137 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006138 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006139 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6140 S->isVolatile(), S->getNumOutputs(),
6141 S->getNumInputs(), Names.data(),
6142 Constraints, Exprs, AsmString.get(),
6143 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006144}
6145
Chad Rosier32503022012-06-11 20:47:18 +00006146template<typename Derived>
6147StmtResult
6148TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006149 ArrayRef<Token> AsmToks =
6150 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006151
John McCallf413f5e2013-05-03 00:10:13 +00006152 bool HadError = false, HadChange = false;
6153
6154 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6155 SmallVector<Expr*, 8> TransformedExprs;
6156 TransformedExprs.reserve(SrcExprs.size());
6157 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6158 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6159 if (!Result.isUsable()) {
6160 HadError = true;
6161 } else {
6162 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006163 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006164 }
6165 }
6166
6167 if (HadError) return StmtError();
6168 if (!HadChange && !getDerived().AlwaysRebuild())
6169 return Owned(S);
6170
Chad Rosierb6f46c12012-08-15 16:53:30 +00006171 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006172 AsmToks, S->getAsmString(),
6173 S->getNumOutputs(), S->getNumInputs(),
6174 S->getAllConstraints(), S->getClobbers(),
6175 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006176}
Douglas Gregorebe10102009-08-20 07:17:43 +00006177
6178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006179StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006180TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006181 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006182 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006183 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006184 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006185
Douglas Gregor96c79492010-04-23 22:50:49 +00006186 // Transform the @catch statements (if present).
6187 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006188 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006189 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006190 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006191 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006192 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006193 if (Catch.get() != S->getCatchStmt(I))
6194 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006195 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006196 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006197
Douglas Gregor306de2f2010-04-22 23:59:56 +00006198 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006199 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006200 if (S->getFinallyStmt()) {
6201 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6202 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006204 }
6205
6206 // If nothing changed, just retain this statement.
6207 if (!getDerived().AlwaysRebuild() &&
6208 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006209 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006210 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006211 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006212
Douglas Gregor306de2f2010-04-22 23:59:56 +00006213 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006214 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006215 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006216}
Mike Stump11289f42009-09-09 15:08:12 +00006217
Douglas Gregorebe10102009-08-20 07:17:43 +00006218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006219StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006220TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006221 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006222 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006223 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006224 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006225 if (FromVar->getTypeSourceInfo()) {
6226 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6227 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006230
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006231 QualType T;
6232 if (TSInfo)
6233 T = TSInfo->getType();
6234 else {
6235 T = getDerived().TransformType(FromVar->getType());
6236 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006237 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006238 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006239
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006240 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6241 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006242 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006243 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006244
John McCalldadc5752010-08-24 06:29:42 +00006245 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006246 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006247 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006248
6249 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006250 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006251 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006252}
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregorebe10102009-08-20 07:17:43 +00006254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006255StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006256TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006257 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006258 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006259 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006260 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006261
Douglas Gregor306de2f2010-04-22 23:59:56 +00006262 // If nothing changed, just retain this statement.
6263 if (!getDerived().AlwaysRebuild() &&
6264 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006265 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006266
6267 // Build a new statement.
6268 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006269 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006270}
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregorebe10102009-08-20 07:17:43 +00006272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006273StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006274TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006275 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006276 if (S->getThrowExpr()) {
6277 Operand = getDerived().TransformExpr(S->getThrowExpr());
6278 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006279 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006280 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006281
Douglas Gregor2900c162010-04-22 21:44:01 +00006282 if (!getDerived().AlwaysRebuild() &&
6283 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006284 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006285
John McCallb268a282010-08-23 23:25:46 +00006286 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006287}
Mike Stump11289f42009-09-09 15:08:12 +00006288
Douglas Gregorebe10102009-08-20 07:17:43 +00006289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006290StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006291TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006292 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006293 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006294 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006295 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006296 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006297 Object =
6298 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6299 Object.get());
6300 if (Object.isInvalid())
6301 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006302
Douglas Gregor6148de72010-04-22 22:01:21 +00006303 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006304 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006305 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006306 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006307
Douglas Gregor6148de72010-04-22 22:01:21 +00006308 // If nothing change, just retain the current statement.
6309 if (!getDerived().AlwaysRebuild() &&
6310 Object.get() == S->getSynchExpr() &&
6311 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006312 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006313
6314 // Build a new statement.
6315 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006316 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006317}
6318
6319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006320StmtResult
John McCall31168b02011-06-15 23:02:42 +00006321TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6322 ObjCAutoreleasePoolStmt *S) {
6323 // Transform the body.
6324 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6325 if (Body.isInvalid())
6326 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006327
John McCall31168b02011-06-15 23:02:42 +00006328 // If nothing changed, just retain this statement.
6329 if (!getDerived().AlwaysRebuild() &&
6330 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006331 return S;
John McCall31168b02011-06-15 23:02:42 +00006332
6333 // Build a new statement.
6334 return getDerived().RebuildObjCAutoreleasePoolStmt(
6335 S->getAtLoc(), Body.get());
6336}
6337
6338template<typename Derived>
6339StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006340TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006341 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006342 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006343 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006344 if (Element.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 collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006348 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006349 if (Collection.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 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006353 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006354 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006355 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006356
Douglas Gregorf68a5082010-04-22 23:10:45 +00006357 // If nothing changed, just retain this statement.
6358 if (!getDerived().AlwaysRebuild() &&
6359 Element.get() == S->getElement() &&
6360 Collection.get() == S->getCollection() &&
6361 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006362 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006363
Douglas Gregorf68a5082010-04-22 23:10:45 +00006364 // Build a new statement.
6365 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006366 Element.get(),
6367 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006368 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006369 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006370}
6371
David Majnemer5f7efef2013-10-15 09:50:08 +00006372template <typename Derived>
6373StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006374 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006375 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006376 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6377 TypeSourceInfo *T =
6378 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006379 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006381
David Majnemer5f7efef2013-10-15 09:50:08 +00006382 Var = getDerived().RebuildExceptionDecl(
6383 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6384 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006385 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006386 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006387 }
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregorebe10102009-08-20 07:17:43 +00006389 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006390 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006391 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006392 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006393
David Majnemer5f7efef2013-10-15 09:50:08 +00006394 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006395 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006396 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006397
David Majnemer5f7efef2013-10-15 09:50:08 +00006398 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006399}
Mike Stump11289f42009-09-09 15:08:12 +00006400
David Majnemer5f7efef2013-10-15 09:50:08 +00006401template <typename Derived>
6402StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006403 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006404 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006405 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006406 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006407
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 // Transform the handlers.
6409 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006410 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006411 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006412 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006413 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006414 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregorebe10102009-08-20 07:17:43 +00006416 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006417 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006418 }
Mike Stump11289f42009-09-09 15:08:12 +00006419
David Majnemer5f7efef2013-10-15 09:50:08 +00006420 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006421 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006422 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006423
John McCallb268a282010-08-23 23:25:46 +00006424 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006425 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006426}
Mike Stump11289f42009-09-09 15:08:12 +00006427
Richard Smith02e85f32011-04-14 22:09:26 +00006428template<typename Derived>
6429StmtResult
6430TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6431 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6432 if (Range.isInvalid())
6433 return StmtError();
6434
6435 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6436 if (BeginEnd.isInvalid())
6437 return StmtError();
6438
6439 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6440 if (Cond.isInvalid())
6441 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006442 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006443 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006444 if (Cond.isInvalid())
6445 return StmtError();
6446 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006447 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006448
6449 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6450 if (Inc.isInvalid())
6451 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006452 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006453 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006454
6455 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6456 if (LoopVar.isInvalid())
6457 return StmtError();
6458
6459 StmtResult NewStmt = S;
6460 if (getDerived().AlwaysRebuild() ||
6461 Range.get() != S->getRangeStmt() ||
6462 BeginEnd.get() != S->getBeginEndStmt() ||
6463 Cond.get() != S->getCond() ||
6464 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006465 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006466 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6467 S->getColonLoc(), Range.get(),
6468 BeginEnd.get(), Cond.get(),
6469 Inc.get(), LoopVar.get(),
6470 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006471 if (NewStmt.isInvalid())
6472 return StmtError();
6473 }
Richard Smith02e85f32011-04-14 22:09:26 +00006474
6475 StmtResult Body = getDerived().TransformStmt(S->getBody());
6476 if (Body.isInvalid())
6477 return StmtError();
6478
6479 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6480 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006481 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006482 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6483 S->getColonLoc(), Range.get(),
6484 BeginEnd.get(), Cond.get(),
6485 Inc.get(), LoopVar.get(),
6486 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006487 if (NewStmt.isInvalid())
6488 return StmtError();
6489 }
Richard Smith02e85f32011-04-14 22:09:26 +00006490
6491 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006492 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006493
6494 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6495}
6496
John Wiegley1c0675e2011-04-28 01:08:34 +00006497template<typename Derived>
6498StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006499TreeTransform<Derived>::TransformMSDependentExistsStmt(
6500 MSDependentExistsStmt *S) {
6501 // Transform the nested-name-specifier, if any.
6502 NestedNameSpecifierLoc QualifierLoc;
6503 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006504 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006505 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6506 if (!QualifierLoc)
6507 return StmtError();
6508 }
6509
6510 // Transform the declaration name.
6511 DeclarationNameInfo NameInfo = S->getNameInfo();
6512 if (NameInfo.getName()) {
6513 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6514 if (!NameInfo.getName())
6515 return StmtError();
6516 }
6517
6518 // Check whether anything changed.
6519 if (!getDerived().AlwaysRebuild() &&
6520 QualifierLoc == S->getQualifierLoc() &&
6521 NameInfo.getName() == S->getNameInfo().getName())
6522 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006523
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006524 // Determine whether this name exists, if we can.
6525 CXXScopeSpec SS;
6526 SS.Adopt(QualifierLoc);
6527 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006528 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006529 case Sema::IER_Exists:
6530 if (S->isIfExists())
6531 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006532
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006533 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6534
6535 case Sema::IER_DoesNotExist:
6536 if (S->isIfNotExists())
6537 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006538
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006539 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006540
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006541 case Sema::IER_Dependent:
6542 Dependent = true;
6543 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006544
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006545 case Sema::IER_Error:
6546 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006548
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006549 // We need to continue with the instantiation, so do so now.
6550 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6551 if (SubStmt.isInvalid())
6552 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006553
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006554 // If we have resolved the name, just transform to the substatement.
6555 if (!Dependent)
6556 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006557
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006558 // The name is still dependent, so build a dependent expression again.
6559 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6560 S->isIfExists(),
6561 QualifierLoc,
6562 NameInfo,
6563 SubStmt.get());
6564}
6565
6566template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006567ExprResult
6568TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6569 NestedNameSpecifierLoc QualifierLoc;
6570 if (E->getQualifierLoc()) {
6571 QualifierLoc
6572 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6573 if (!QualifierLoc)
6574 return ExprError();
6575 }
6576
6577 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6578 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6579 if (!PD)
6580 return ExprError();
6581
6582 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6583 if (Base.isInvalid())
6584 return ExprError();
6585
6586 return new (SemaRef.getASTContext())
6587 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6588 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6589 QualifierLoc, E->getMemberLoc());
6590}
6591
David Majnemerfad8f482013-10-15 09:33:02 +00006592template <typename Derived>
6593StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006594 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006595 if (TryBlock.isInvalid())
6596 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006597
6598 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006599 if (Handler.isInvalid())
6600 return StmtError();
6601
David Majnemerfad8f482013-10-15 09:33:02 +00006602 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6603 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006604 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006605
Warren Huntf6be4cb2014-07-25 20:52:51 +00006606 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6607 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006608}
6609
David Majnemerfad8f482013-10-15 09:33:02 +00006610template <typename Derived>
6611StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006612 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006613 if (Block.isInvalid())
6614 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006615
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006616 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006617}
6618
David Majnemerfad8f482013-10-15 09:33:02 +00006619template <typename Derived>
6620StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006621 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006622 if (FilterExpr.isInvalid())
6623 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006624
David Majnemer7e755502013-10-15 09:30:14 +00006625 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006626 if (Block.isInvalid())
6627 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006628
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006629 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6630 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006631}
6632
David Majnemerfad8f482013-10-15 09:33:02 +00006633template <typename Derived>
6634StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6635 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006636 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6637 else
6638 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6639}
6640
Nico Weber9b982072014-07-07 00:12:30 +00006641template<typename Derived>
6642StmtResult
6643TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6644 return S;
6645}
6646
Alexander Musman64d33f12014-06-04 07:53:32 +00006647//===----------------------------------------------------------------------===//
6648// OpenMP directive transformation
6649//===----------------------------------------------------------------------===//
6650template <typename Derived>
6651StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6652 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006653
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006654 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006655 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006656 ArrayRef<OMPClause *> Clauses = D->clauses();
6657 TClauses.reserve(Clauses.size());
6658 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6659 I != E; ++I) {
6660 if (*I) {
6661 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006662 if (Clause)
6663 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006664 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006665 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006666 }
6667 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006668 StmtResult AssociatedStmt;
6669 if (D->hasAssociatedStmt()) {
6670 if (!D->getAssociatedStmt()) {
6671 return StmtError();
6672 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006673 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6674 /*CurScope=*/nullptr);
6675 StmtResult Body;
6676 {
6677 Sema::CompoundScopeRAII CompoundScope(getSema());
6678 Body = getDerived().TransformStmt(
6679 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6680 }
6681 AssociatedStmt =
6682 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006683 if (AssociatedStmt.isInvalid()) {
6684 return StmtError();
6685 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006686 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006687 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006688 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006689 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006690
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006691 // Transform directive name for 'omp critical' directive.
6692 DeclarationNameInfo DirName;
6693 if (D->getDirectiveKind() == OMPD_critical) {
6694 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6695 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6696 }
6697
Alexander Musman64d33f12014-06-04 07:53:32 +00006698 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006699 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6700 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006701}
6702
Alexander Musman64d33f12014-06-04 07:53:32 +00006703template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006704StmtResult
6705TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6706 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006707 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6708 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006709 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6710 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6711 return Res;
6712}
6713
Alexander Musman64d33f12014-06-04 07:53:32 +00006714template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006715StmtResult
6716TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6717 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006718 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6719 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006720 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6721 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006722 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006723}
6724
Alexey Bataevf29276e2014-06-18 04:14:57 +00006725template <typename Derived>
6726StmtResult
6727TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6728 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006729 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6730 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006731 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6732 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6733 return Res;
6734}
6735
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006736template <typename Derived>
6737StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006738TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6739 DeclarationNameInfo DirName;
6740 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6741 D->getLocStart());
6742 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6743 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6744 return Res;
6745}
6746
6747template <typename Derived>
6748StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006749TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6750 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006751 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6752 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006753 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6754 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6755 return Res;
6756}
6757
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006758template <typename Derived>
6759StmtResult
6760TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6761 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006762 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6763 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006764 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6765 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6766 return Res;
6767}
6768
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006769template <typename Derived>
6770StmtResult
6771TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6772 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006773 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6774 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006775 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6776 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6777 return Res;
6778}
6779
Alexey Bataev4acb8592014-07-07 13:01:15 +00006780template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006781StmtResult
6782TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6783 DeclarationNameInfo DirName;
6784 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6785 D->getLocStart());
6786 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6787 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6788 return Res;
6789}
6790
6791template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006792StmtResult
6793TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6794 getDerived().getSema().StartOpenMPDSABlock(
6795 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6796 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6797 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6798 return Res;
6799}
6800
6801template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006802StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6803 OMPParallelForDirective *D) {
6804 DeclarationNameInfo DirName;
6805 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6806 nullptr, D->getLocStart());
6807 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6808 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6809 return Res;
6810}
6811
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006812template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006813StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6814 OMPParallelForSimdDirective *D) {
6815 DeclarationNameInfo DirName;
6816 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6817 nullptr, D->getLocStart());
6818 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6819 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6820 return Res;
6821}
6822
6823template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006824StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6825 OMPParallelSectionsDirective *D) {
6826 DeclarationNameInfo DirName;
6827 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6828 nullptr, D->getLocStart());
6829 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6830 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6831 return Res;
6832}
6833
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006834template <typename Derived>
6835StmtResult
6836TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6837 DeclarationNameInfo DirName;
6838 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6839 D->getLocStart());
6840 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6841 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6842 return Res;
6843}
6844
Alexey Bataev68446b72014-07-18 07:47:19 +00006845template <typename Derived>
6846StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6847 OMPTaskyieldDirective *D) {
6848 DeclarationNameInfo DirName;
6849 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6850 D->getLocStart());
6851 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6852 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6853 return Res;
6854}
6855
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006856template <typename Derived>
6857StmtResult
6858TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6859 DeclarationNameInfo DirName;
6860 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6861 D->getLocStart());
6862 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6863 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6864 return Res;
6865}
6866
Alexey Bataev2df347a2014-07-18 10:17:07 +00006867template <typename Derived>
6868StmtResult
6869TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6870 DeclarationNameInfo DirName;
6871 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6872 D->getLocStart());
6873 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6874 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6875 return Res;
6876}
6877
Alexey Bataev6125da92014-07-21 11:26:11 +00006878template <typename Derived>
6879StmtResult
6880TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6881 DeclarationNameInfo DirName;
6882 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6883 D->getLocStart());
6884 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6885 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6886 return Res;
6887}
6888
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006889template <typename Derived>
6890StmtResult
6891TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6892 DeclarationNameInfo DirName;
6893 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6894 D->getLocStart());
6895 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6896 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6897 return Res;
6898}
6899
Alexey Bataev0162e452014-07-22 10:10:35 +00006900template <typename Derived>
6901StmtResult
6902TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6903 DeclarationNameInfo DirName;
6904 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6905 D->getLocStart());
6906 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6907 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6908 return Res;
6909}
6910
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006911template <typename Derived>
6912StmtResult
6913TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6914 DeclarationNameInfo DirName;
6915 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6916 D->getLocStart());
6917 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6918 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6919 return Res;
6920}
6921
Alexey Bataev13314bf2014-10-09 04:18:56 +00006922template <typename Derived>
6923StmtResult
6924TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6925 DeclarationNameInfo DirName;
6926 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6927 D->getLocStart());
6928 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6929 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6930 return Res;
6931}
6932
Alexander Musman64d33f12014-06-04 07:53:32 +00006933//===----------------------------------------------------------------------===//
6934// OpenMP clause transformation
6935//===----------------------------------------------------------------------===//
6936template <typename Derived>
6937OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006938 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6939 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006940 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006941 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006942 C->getLParenLoc(), C->getLocEnd());
6943}
6944
Alexander Musman64d33f12014-06-04 07:53:32 +00006945template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006946OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6947 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6948 if (Cond.isInvalid())
6949 return nullptr;
6950 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6951 C->getLParenLoc(), C->getLocEnd());
6952}
6953
6954template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006955OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006956TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6957 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6958 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006959 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006960 return getDerived().RebuildOMPNumThreadsClause(
6961 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006962}
6963
Alexey Bataev62c87d22014-03-21 04:51:18 +00006964template <typename Derived>
6965OMPClause *
6966TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6967 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6968 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006969 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006970 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006971 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006972}
6973
Alexander Musman8bd31e62014-05-27 15:12:19 +00006974template <typename Derived>
6975OMPClause *
6976TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6977 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6978 if (E.isInvalid())
6979 return 0;
6980 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006981 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006982}
6983
Alexander Musman64d33f12014-06-04 07:53:32 +00006984template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006985OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006986TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006987 return getDerived().RebuildOMPDefaultClause(
6988 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6989 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006990}
6991
Alexander Musman64d33f12014-06-04 07:53:32 +00006992template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006993OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006994TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006995 return getDerived().RebuildOMPProcBindClause(
6996 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6997 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006998}
6999
Alexander Musman64d33f12014-06-04 07:53:32 +00007000template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007001OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007002TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7003 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7004 if (E.isInvalid())
7005 return nullptr;
7006 return getDerived().RebuildOMPScheduleClause(
7007 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7008 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7009}
7010
7011template <typename Derived>
7012OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007013TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7014 // No need to rebuild this clause, no template-dependent parameters.
7015 return C;
7016}
7017
7018template <typename Derived>
7019OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007020TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7021 // No need to rebuild this clause, no template-dependent parameters.
7022 return C;
7023}
7024
7025template <typename Derived>
7026OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007027TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7028 // No need to rebuild this clause, no template-dependent parameters.
7029 return C;
7030}
7031
7032template <typename Derived>
7033OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007034TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7035 // No need to rebuild this clause, no template-dependent parameters.
7036 return C;
7037}
7038
7039template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007040OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7041 // No need to rebuild this clause, no template-dependent parameters.
7042 return C;
7043}
7044
7045template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007046OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7047 // No need to rebuild this clause, no template-dependent parameters.
7048 return C;
7049}
7050
7051template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007052OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007053TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7054 // No need to rebuild this clause, no template-dependent parameters.
7055 return C;
7056}
7057
7058template <typename Derived>
7059OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007060TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7061 // No need to rebuild this clause, no template-dependent parameters.
7062 return C;
7063}
7064
7065template <typename Derived>
7066OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007067TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7068 // No need to rebuild this clause, no template-dependent parameters.
7069 return C;
7070}
7071
7072template <typename Derived>
7073OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007074TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007075 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007076 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007077 for (auto *VE : C->varlists()) {
7078 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007079 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007080 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007081 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007082 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007083 return getDerived().RebuildOMPPrivateClause(
7084 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007085}
7086
Alexander Musman64d33f12014-06-04 07:53:32 +00007087template <typename Derived>
7088OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7089 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007090 llvm::SmallVector<Expr *, 16> Vars;
7091 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007092 for (auto *VE : C->varlists()) {
7093 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007094 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007095 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007096 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007097 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007098 return getDerived().RebuildOMPFirstprivateClause(
7099 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007100}
7101
Alexander Musman64d33f12014-06-04 07:53:32 +00007102template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007103OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007104TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7105 llvm::SmallVector<Expr *, 16> Vars;
7106 Vars.reserve(C->varlist_size());
7107 for (auto *VE : C->varlists()) {
7108 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7109 if (EVar.isInvalid())
7110 return nullptr;
7111 Vars.push_back(EVar.get());
7112 }
7113 return getDerived().RebuildOMPLastprivateClause(
7114 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7115}
7116
7117template <typename Derived>
7118OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007119TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7120 llvm::SmallVector<Expr *, 16> Vars;
7121 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007122 for (auto *VE : C->varlists()) {
7123 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007124 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007125 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007126 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007127 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007128 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7129 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007130}
7131
Alexander Musman64d33f12014-06-04 07:53:32 +00007132template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007133OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007134TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7135 llvm::SmallVector<Expr *, 16> Vars;
7136 Vars.reserve(C->varlist_size());
7137 for (auto *VE : C->varlists()) {
7138 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7139 if (EVar.isInvalid())
7140 return nullptr;
7141 Vars.push_back(EVar.get());
7142 }
7143 CXXScopeSpec ReductionIdScopeSpec;
7144 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7145
7146 DeclarationNameInfo NameInfo = C->getNameInfo();
7147 if (NameInfo.getName()) {
7148 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7149 if (!NameInfo.getName())
7150 return nullptr;
7151 }
7152 return getDerived().RebuildOMPReductionClause(
7153 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7154 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7155}
7156
7157template <typename Derived>
7158OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007159TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7160 llvm::SmallVector<Expr *, 16> Vars;
7161 Vars.reserve(C->varlist_size());
7162 for (auto *VE : C->varlists()) {
7163 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7164 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007165 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007166 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007167 }
7168 ExprResult Step = getDerived().TransformExpr(C->getStep());
7169 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007170 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007171 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7172 C->getLParenLoc(),
7173 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007174}
7175
Alexander Musman64d33f12014-06-04 07:53:32 +00007176template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007177OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007178TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7179 llvm::SmallVector<Expr *, 16> Vars;
7180 Vars.reserve(C->varlist_size());
7181 for (auto *VE : C->varlists()) {
7182 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7183 if (EVar.isInvalid())
7184 return nullptr;
7185 Vars.push_back(EVar.get());
7186 }
7187 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7188 if (Alignment.isInvalid())
7189 return nullptr;
7190 return getDerived().RebuildOMPAlignedClause(
7191 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7192 C->getColonLoc(), C->getLocEnd());
7193}
7194
Alexander Musman64d33f12014-06-04 07:53:32 +00007195template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007196OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007197TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7198 llvm::SmallVector<Expr *, 16> Vars;
7199 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007200 for (auto *VE : C->varlists()) {
7201 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007202 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007203 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007204 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007205 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007206 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7207 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007208}
7209
Alexey Bataevbae9a792014-06-27 10:37:06 +00007210template <typename Derived>
7211OMPClause *
7212TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7213 llvm::SmallVector<Expr *, 16> Vars;
7214 Vars.reserve(C->varlist_size());
7215 for (auto *VE : C->varlists()) {
7216 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7217 if (EVar.isInvalid())
7218 return nullptr;
7219 Vars.push_back(EVar.get());
7220 }
7221 return getDerived().RebuildOMPCopyprivateClause(
7222 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7223}
7224
Alexey Bataev6125da92014-07-21 11:26:11 +00007225template <typename Derived>
7226OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7227 llvm::SmallVector<Expr *, 16> Vars;
7228 Vars.reserve(C->varlist_size());
7229 for (auto *VE : C->varlists()) {
7230 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7231 if (EVar.isInvalid())
7232 return nullptr;
7233 Vars.push_back(EVar.get());
7234 }
7235 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7236 C->getLParenLoc(), C->getLocEnd());
7237}
7238
Douglas Gregorebe10102009-08-20 07:17:43 +00007239//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007240// Expression transformation
7241//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007244TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007245 if (!E->isTypeDependent())
7246 return E;
7247
7248 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7249 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007250}
Mike Stump11289f42009-09-09 15:08:12 +00007251
7252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007254TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007255 NestedNameSpecifierLoc QualifierLoc;
7256 if (E->getQualifierLoc()) {
7257 QualifierLoc
7258 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7259 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007260 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007261 }
John McCallce546572009-12-08 09:08:17 +00007262
7263 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007264 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7265 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007266 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007268
John McCall815039a2010-08-17 21:27:17 +00007269 DeclarationNameInfo NameInfo = E->getNameInfo();
7270 if (NameInfo.getName()) {
7271 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7272 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007273 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007274 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007275
7276 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007277 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007278 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007279 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007280 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007281
7282 // Mark it referenced in the new context regardless.
7283 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007284 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007285
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007286 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007287 }
John McCallce546572009-12-08 09:08:17 +00007288
Craig Topperc3ec1492014-05-26 06:22:03 +00007289 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007290 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007291 TemplateArgs = &TransArgs;
7292 TransArgs.setLAngleLoc(E->getLAngleLoc());
7293 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007294 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7295 E->getNumTemplateArgs(),
7296 TransArgs))
7297 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007298 }
7299
Chad Rosier1dcde962012-08-08 18:46:20 +00007300 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007301 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007302}
Mike Stump11289f42009-09-09 15:08:12 +00007303
Douglas Gregora16548e2009-08-11 05:31:07 +00007304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007306TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007307 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007312TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007313 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007314}
Mike Stump11289f42009-09-09 15:08:12 +00007315
Douglas Gregora16548e2009-08-11 05:31:07 +00007316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007318TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007319 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007320}
Mike Stump11289f42009-09-09 15:08:12 +00007321
Douglas Gregora16548e2009-08-11 05:31:07 +00007322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007324TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007325 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007326}
Mike Stump11289f42009-09-09 15:08:12 +00007327
Douglas Gregora16548e2009-08-11 05:31:07 +00007328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007330TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007331 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007332}
7333
7334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007335ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007336TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007337 if (FunctionDecl *FD = E->getDirectCallee())
7338 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007339 return SemaRef.MaybeBindToTemporary(E);
7340}
7341
7342template<typename Derived>
7343ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007344TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7345 ExprResult ControllingExpr =
7346 getDerived().TransformExpr(E->getControllingExpr());
7347 if (ControllingExpr.isInvalid())
7348 return ExprError();
7349
Chris Lattner01cf8db2011-07-20 06:58:45 +00007350 SmallVector<Expr *, 4> AssocExprs;
7351 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007352 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7353 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7354 if (TS) {
7355 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7356 if (!AssocType)
7357 return ExprError();
7358 AssocTypes.push_back(AssocType);
7359 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007360 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007361 }
7362
7363 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7364 if (AssocExpr.isInvalid())
7365 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007366 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007367 }
7368
7369 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7370 E->getDefaultLoc(),
7371 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007372 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007373 AssocTypes,
7374 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007375}
7376
7377template<typename Derived>
7378ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007379TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007380 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007381 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007383
Douglas Gregora16548e2009-08-11 05:31:07 +00007384 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007385 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007386
John McCallb268a282010-08-23 23:25:46 +00007387 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007388 E->getRParen());
7389}
7390
Richard Smithdb2630f2012-10-21 03:28:35 +00007391/// \brief The operand of a unary address-of operator has special rules: it's
7392/// allowed to refer to a non-static member of a class even if there's no 'this'
7393/// object available.
7394template<typename Derived>
7395ExprResult
7396TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7397 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007398 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007399 else
7400 return getDerived().TransformExpr(E);
7401}
7402
Mike Stump11289f42009-09-09 15:08:12 +00007403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007404ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007405TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007406 ExprResult SubExpr;
7407 if (E->getOpcode() == UO_AddrOf)
7408 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7409 else
7410 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007411 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007412 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007413
Douglas Gregora16548e2009-08-11 05:31:07 +00007414 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007415 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007416
Douglas Gregora16548e2009-08-11 05:31:07 +00007417 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7418 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007419 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007420}
Mike Stump11289f42009-09-09 15:08:12 +00007421
Douglas Gregora16548e2009-08-11 05:31:07 +00007422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007423ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007424TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7425 // Transform the type.
7426 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7427 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007428 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007429
Douglas Gregor882211c2010-04-28 22:16:22 +00007430 // Transform all of the components into components similar to what the
7431 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007432 // FIXME: It would be slightly more efficient in the non-dependent case to
7433 // just map FieldDecls, rather than requiring the rebuilder to look for
7434 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007435 // template code that we don't care.
7436 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007437 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007438 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007439 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007440 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7441 const Node &ON = E->getComponent(I);
7442 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007443 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007444 Comp.LocStart = ON.getSourceRange().getBegin();
7445 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007446 switch (ON.getKind()) {
7447 case Node::Array: {
7448 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007449 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007450 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007451 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007452
Douglas Gregor882211c2010-04-28 22:16:22 +00007453 ExprChanged = ExprChanged || Index.get() != FromIndex;
7454 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007455 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007456 break;
7457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007458
Douglas Gregor882211c2010-04-28 22:16:22 +00007459 case Node::Field:
7460 case Node::Identifier:
7461 Comp.isBrackets = false;
7462 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007463 if (!Comp.U.IdentInfo)
7464 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007465
Douglas Gregor882211c2010-04-28 22:16:22 +00007466 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007467
Douglas Gregord1702062010-04-29 00:18:15 +00007468 case Node::Base:
7469 // Will be recomputed during the rebuild.
7470 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007472
Douglas Gregor882211c2010-04-28 22:16:22 +00007473 Components.push_back(Comp);
7474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007475
Douglas Gregor882211c2010-04-28 22:16:22 +00007476 // If nothing changed, retain the existing expression.
7477 if (!getDerived().AlwaysRebuild() &&
7478 Type == E->getTypeSourceInfo() &&
7479 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007480 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007481
Douglas Gregor882211c2010-04-28 22:16:22 +00007482 // Build a new offsetof expression.
7483 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7484 Components.data(), Components.size(),
7485 E->getRParenLoc());
7486}
7487
7488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007489ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007490TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7491 assert(getDerived().AlreadyTransformed(E->getType()) &&
7492 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007493 return E;
John McCall8d69a212010-11-15 23:31:06 +00007494}
7495
7496template<typename Derived>
7497ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007498TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7499 return E;
7500}
7501
7502template<typename Derived>
7503ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007504TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007505 // Rebuild the syntactic form. The original syntactic form has
7506 // opaque-value expressions in it, so strip those away and rebuild
7507 // the result. This is a really awful way of doing this, but the
7508 // better solution (rebuilding the semantic expressions and
7509 // rebinding OVEs as necessary) doesn't work; we'd need
7510 // TreeTransform to not strip away implicit conversions.
7511 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7512 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007513 if (result.isInvalid()) return ExprError();
7514
7515 // If that gives us a pseudo-object result back, the pseudo-object
7516 // expression must have been an lvalue-to-rvalue conversion which we
7517 // should reapply.
7518 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007519 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007520
7521 return result;
7522}
7523
7524template<typename Derived>
7525ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007526TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7527 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007528 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007529 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007530
John McCallbcd03502009-12-07 02:54:59 +00007531 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007532 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007534
John McCall4c98fd82009-11-04 07:28:41 +00007535 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007536 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007537
Peter Collingbournee190dee2011-03-11 19:24:49 +00007538 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7539 E->getKind(),
7540 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007541 }
Mike Stump11289f42009-09-09 15:08:12 +00007542
Eli Friedmane4f22df2012-02-29 04:03:55 +00007543 // C++0x [expr.sizeof]p1:
7544 // The operand is either an expression, which is an unevaluated operand
7545 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007546 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7547 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007548
Reid Kleckner32506ed2014-06-12 23:03:48 +00007549 // Try to recover if we have something like sizeof(T::X) where X is a type.
7550 // Notably, there must be *exactly* one set of parens if X is a type.
7551 TypeSourceInfo *RecoveryTSI = nullptr;
7552 ExprResult SubExpr;
7553 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7554 if (auto *DRE =
7555 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7556 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7557 PE, DRE, false, &RecoveryTSI);
7558 else
7559 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7560
7561 if (RecoveryTSI) {
7562 return getDerived().RebuildUnaryExprOrTypeTrait(
7563 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7564 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007566
Eli Friedmane4f22df2012-02-29 04:03:55 +00007567 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007568 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007569
Peter Collingbournee190dee2011-03-11 19:24:49 +00007570 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7571 E->getOperatorLoc(),
7572 E->getKind(),
7573 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007574}
Mike Stump11289f42009-09-09 15:08:12 +00007575
Douglas Gregora16548e2009-08-11 05:31:07 +00007576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007578TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007579 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007580 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007582
John McCalldadc5752010-08-24 06:29:42 +00007583 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007584 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007586
7587
Douglas Gregora16548e2009-08-11 05:31:07 +00007588 if (!getDerived().AlwaysRebuild() &&
7589 LHS.get() == E->getLHS() &&
7590 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007591 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007592
John McCallb268a282010-08-23 23:25:46 +00007593 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007595 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007596 E->getRBracketLoc());
7597}
Mike Stump11289f42009-09-09 15:08:12 +00007598
7599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007600ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007601TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007602 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007603 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007604 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007605 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007606
7607 // Transform arguments.
7608 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007609 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007610 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007611 &ArgChanged))
7612 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007613
Douglas Gregora16548e2009-08-11 05:31:07 +00007614 if (!getDerived().AlwaysRebuild() &&
7615 Callee.get() == E->getCallee() &&
7616 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007617 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007618
Douglas Gregora16548e2009-08-11 05:31:07 +00007619 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007620 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007621 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007622 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007623 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007624 E->getRParenLoc());
7625}
Mike Stump11289f42009-09-09 15:08:12 +00007626
7627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007629TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007630 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007631 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007632 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007633
Douglas Gregorea972d32011-02-28 21:54:11 +00007634 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007635 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007636 QualifierLoc
7637 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007638
Douglas Gregorea972d32011-02-28 21:54:11 +00007639 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007640 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007641 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007642 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007643
Eli Friedman2cfcef62009-12-04 06:40:45 +00007644 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007645 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7646 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007647 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007649
John McCall16df1e52010-03-30 21:47:33 +00007650 NamedDecl *FoundDecl = E->getFoundDecl();
7651 if (FoundDecl == E->getMemberDecl()) {
7652 FoundDecl = Member;
7653 } else {
7654 FoundDecl = cast_or_null<NamedDecl>(
7655 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7656 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007657 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007658 }
7659
Douglas Gregora16548e2009-08-11 05:31:07 +00007660 if (!getDerived().AlwaysRebuild() &&
7661 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007662 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007663 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007664 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007665 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007666
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007667 // Mark it referenced in the new context regardless.
7668 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007669 SemaRef.MarkMemberReferenced(E);
7670
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007671 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007672 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007673
John McCall6b51f282009-11-23 01:53:49 +00007674 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007675 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007676 TransArgs.setLAngleLoc(E->getLAngleLoc());
7677 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007678 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7679 E->getNumTemplateArgs(),
7680 TransArgs))
7681 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007682 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007683
Douglas Gregora16548e2009-08-11 05:31:07 +00007684 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007685 SourceLocation FakeOperatorLoc =
7686 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007687
John McCall38836f02010-01-15 08:34:02 +00007688 // FIXME: to do this check properly, we will need to preserve the
7689 // first-qualifier-in-scope here, just in case we had a dependent
7690 // base (and therefore couldn't do the check) and a
7691 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007692 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007693
John McCallb268a282010-08-23 23:25:46 +00007694 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007696 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007697 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007698 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007699 Member,
John McCall16df1e52010-03-30 21:47:33 +00007700 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007701 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007702 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007703 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007704}
Mike Stump11289f42009-09-09 15:08:12 +00007705
Douglas Gregora16548e2009-08-11 05:31:07 +00007706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007707ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007708TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007709 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007710 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007712
John McCalldadc5752010-08-24 06:29:42 +00007713 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007714 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007716
Douglas Gregora16548e2009-08-11 05:31:07 +00007717 if (!getDerived().AlwaysRebuild() &&
7718 LHS.get() == E->getLHS() &&
7719 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007720 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007721
Lang Hames5de91cc2012-10-02 04:45:10 +00007722 Sema::FPContractStateRAII FPContractState(getSema());
7723 getSema().FPFeatures.fp_contract = E->isFPContractable();
7724
Douglas Gregora16548e2009-08-11 05:31:07 +00007725 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007726 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007727}
7728
Mike Stump11289f42009-09-09 15:08:12 +00007729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007730ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007731TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007732 CompoundAssignOperator *E) {
7733 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007734}
Mike Stump11289f42009-09-09 15:08:12 +00007735
Douglas Gregora16548e2009-08-11 05:31:07 +00007736template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007737ExprResult TreeTransform<Derived>::
7738TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7739 // Just rebuild the common and RHS expressions and see whether we
7740 // get any changes.
7741
7742 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7743 if (commonExpr.isInvalid())
7744 return ExprError();
7745
7746 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7747 if (rhs.isInvalid())
7748 return ExprError();
7749
7750 if (!getDerived().AlwaysRebuild() &&
7751 commonExpr.get() == e->getCommon() &&
7752 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007753 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007754
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007755 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007756 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007757 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007758 e->getColonLoc(),
7759 rhs.get());
7760}
7761
7762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007764TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007765 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007766 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007767 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007768
John McCalldadc5752010-08-24 06:29:42 +00007769 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007770 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007772
John McCalldadc5752010-08-24 06:29:42 +00007773 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007774 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007776
Douglas Gregora16548e2009-08-11 05:31:07 +00007777 if (!getDerived().AlwaysRebuild() &&
7778 Cond.get() == E->getCond() &&
7779 LHS.get() == E->getLHS() &&
7780 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007781 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007782
John McCallb268a282010-08-23 23:25:46 +00007783 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007784 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007785 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007786 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007787 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007788}
Mike Stump11289f42009-09-09 15:08:12 +00007789
7790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007791ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007792TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007793 // Implicit casts are eliminated during transformation, since they
7794 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007795 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007796}
Mike Stump11289f42009-09-09 15:08:12 +00007797
Douglas Gregora16548e2009-08-11 05:31:07 +00007798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007800TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007801 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7802 if (!Type)
7803 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007804
John McCalldadc5752010-08-24 06:29:42 +00007805 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007806 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007807 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007809
Douglas Gregora16548e2009-08-11 05:31:07 +00007810 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007811 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007812 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007813 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007814
John McCall97513962010-01-15 18:39:57 +00007815 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007816 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007817 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007818 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007819}
Mike Stump11289f42009-09-09 15:08:12 +00007820
Douglas Gregora16548e2009-08-11 05:31:07 +00007821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007823TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007824 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7825 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7826 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007828
John McCalldadc5752010-08-24 06:29:42 +00007829 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007830 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007832
Douglas Gregora16548e2009-08-11 05:31:07 +00007833 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007834 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007835 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007836 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007837
John McCall5d7aa7f2010-01-19 22:33:45 +00007838 // Note: the expression type doesn't necessarily match the
7839 // type-as-written, but that's okay, because it should always be
7840 // derivable from the initializer.
7841
John McCalle15bbff2010-01-18 19:35:47 +00007842 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007843 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007844 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007845}
Mike Stump11289f42009-09-09 15:08:12 +00007846
Douglas Gregora16548e2009-08-11 05:31:07 +00007847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007848ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007849TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007850 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007851 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007853
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 if (!getDerived().AlwaysRebuild() &&
7855 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007856 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007857
Douglas Gregora16548e2009-08-11 05:31:07 +00007858 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007859 SourceLocation FakeOperatorLoc =
7860 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007861 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007862 E->getAccessorLoc(),
7863 E->getAccessor());
7864}
Mike Stump11289f42009-09-09 15:08:12 +00007865
Douglas Gregora16548e2009-08-11 05:31:07 +00007866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007867ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007868TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00007869 if (InitListExpr *Syntactic = E->getSyntacticForm())
7870 E = Syntactic;
7871
Douglas Gregora16548e2009-08-11 05:31:07 +00007872 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007873
Benjamin Kramerf0623432012-08-23 22:51:59 +00007874 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007875 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007876 Inits, &InitChanged))
7877 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007878
Richard Smith520449d2015-02-05 06:15:50 +00007879 if (!getDerived().AlwaysRebuild() && !InitChanged) {
7880 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
7881 // in some cases. We can't reuse it in general, because the syntactic and
7882 // semantic forms are linked, and we can't know that semantic form will
7883 // match even if the syntactic form does.
7884 }
Mike Stump11289f42009-09-09 15:08:12 +00007885
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007886 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007887 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007888}
Mike Stump11289f42009-09-09 15:08:12 +00007889
Douglas Gregora16548e2009-08-11 05:31:07 +00007890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007891ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007892TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007893 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007894
Douglas Gregorebe10102009-08-20 07:17:43 +00007895 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007896 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007897 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007899
Douglas Gregorebe10102009-08-20 07:17:43 +00007900 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007901 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007902 bool ExprChanged = false;
7903 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7904 DEnd = E->designators_end();
7905 D != DEnd; ++D) {
7906 if (D->isFieldDesignator()) {
7907 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7908 D->getDotLoc(),
7909 D->getFieldLoc()));
7910 continue;
7911 }
Mike Stump11289f42009-09-09 15:08:12 +00007912
Douglas Gregora16548e2009-08-11 05:31:07 +00007913 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007914 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007915 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007917
7918 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007919 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007920
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007922 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007923 continue;
7924 }
Mike Stump11289f42009-09-09 15:08:12 +00007925
Douglas Gregora16548e2009-08-11 05:31:07 +00007926 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007927 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007928 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7929 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007930 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007931
John McCalldadc5752010-08-24 06:29:42 +00007932 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007933 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007935
7936 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007937 End.get(),
7938 D->getLBracketLoc(),
7939 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007940
Douglas Gregora16548e2009-08-11 05:31:07 +00007941 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7942 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007943
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007944 ArrayExprs.push_back(Start.get());
7945 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007946 }
Mike Stump11289f42009-09-09 15:08:12 +00007947
Douglas Gregora16548e2009-08-11 05:31:07 +00007948 if (!getDerived().AlwaysRebuild() &&
7949 Init.get() == E->getInit() &&
7950 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007951 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007952
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007953 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007954 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007955 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007956}
Mike Stump11289f42009-09-09 15:08:12 +00007957
Douglas Gregora16548e2009-08-11 05:31:07 +00007958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007959ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007960TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007961 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007962 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007963
Douglas Gregor3da3c062009-10-28 00:29:27 +00007964 // FIXME: Will we ever have proper type location here? Will we actually
7965 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007966 QualType T = getDerived().TransformType(E->getType());
7967 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007968 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007969
Douglas Gregora16548e2009-08-11 05:31:07 +00007970 if (!getDerived().AlwaysRebuild() &&
7971 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007972 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007973
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 return getDerived().RebuildImplicitValueInitExpr(T);
7975}
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregora16548e2009-08-11 05:31:07 +00007977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007978ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007979TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007980 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7981 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007983
John McCalldadc5752010-08-24 06:29:42 +00007984 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007985 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007987
Douglas Gregora16548e2009-08-11 05:31:07 +00007988 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007989 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007990 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007991 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007992
John McCallb268a282010-08-23 23:25:46 +00007993 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007994 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007995}
7996
7997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007999TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008000 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008001 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008002 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8003 &ArgumentChanged))
8004 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008005
Douglas Gregora16548e2009-08-11 05:31:07 +00008006 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008007 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008008 E->getRParenLoc());
8009}
Mike Stump11289f42009-09-09 15:08:12 +00008010
Douglas Gregora16548e2009-08-11 05:31:07 +00008011/// \brief Transform an address-of-label expression.
8012///
8013/// By default, the transformation of an address-of-label expression always
8014/// rebuilds the expression, so that the label identifier can be resolved to
8015/// the corresponding label statement by semantic analysis.
8016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008017ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008018TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008019 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8020 E->getLabel());
8021 if (!LD)
8022 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008023
Douglas Gregora16548e2009-08-11 05:31:07 +00008024 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008025 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008026}
Mike Stump11289f42009-09-09 15:08:12 +00008027
8028template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008030TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008031 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008032 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008033 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008034 if (SubStmt.isInvalid()) {
8035 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008036 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008037 }
Mike Stump11289f42009-09-09 15:08:12 +00008038
Douglas Gregora16548e2009-08-11 05:31:07 +00008039 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008040 SubStmt.get() == E->getSubStmt()) {
8041 // Calling this an 'error' is unintuitive, but it does the right thing.
8042 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008043 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008044 }
Mike Stump11289f42009-09-09 15:08:12 +00008045
8046 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008047 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008048 E->getRParenLoc());
8049}
Mike Stump11289f42009-09-09 15:08:12 +00008050
Douglas Gregora16548e2009-08-11 05:31:07 +00008051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008053TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008054 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008055 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008057
John McCalldadc5752010-08-24 06:29:42 +00008058 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008059 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008061
John McCalldadc5752010-08-24 06:29:42 +00008062 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008063 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008065
Douglas Gregora16548e2009-08-11 05:31:07 +00008066 if (!getDerived().AlwaysRebuild() &&
8067 Cond.get() == E->getCond() &&
8068 LHS.get() == E->getLHS() &&
8069 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008070 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008071
Douglas Gregora16548e2009-08-11 05:31:07 +00008072 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008073 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008074 E->getRParenLoc());
8075}
Mike Stump11289f42009-09-09 15:08:12 +00008076
Douglas Gregora16548e2009-08-11 05:31:07 +00008077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008079TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008080 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008081}
8082
8083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008085TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008086 switch (E->getOperator()) {
8087 case OO_New:
8088 case OO_Delete:
8089 case OO_Array_New:
8090 case OO_Array_Delete:
8091 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008092
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008093 case OO_Call: {
8094 // This is a call to an object's operator().
8095 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8096
8097 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008098 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008099 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008100 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008101
8102 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008103 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8104 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008105
8106 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008107 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008108 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008109 Args))
8110 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008111
John McCallb268a282010-08-23 23:25:46 +00008112 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008113 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008114 E->getLocEnd());
8115 }
8116
8117#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8118 case OO_##Name:
8119#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8120#include "clang/Basic/OperatorKinds.def"
8121 case OO_Subscript:
8122 // Handled below.
8123 break;
8124
8125 case OO_Conditional:
8126 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008127
8128 case OO_None:
8129 case NUM_OVERLOADED_OPERATORS:
8130 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008131 }
8132
John McCalldadc5752010-08-24 06:29:42 +00008133 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008134 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008135 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008136
Richard Smithdb2630f2012-10-21 03:28:35 +00008137 ExprResult First;
8138 if (E->getOperator() == OO_Amp)
8139 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8140 else
8141 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008142 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008143 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008144
John McCalldadc5752010-08-24 06:29:42 +00008145 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008146 if (E->getNumArgs() == 2) {
8147 Second = getDerived().TransformExpr(E->getArg(1));
8148 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008149 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008150 }
Mike Stump11289f42009-09-09 15:08:12 +00008151
Douglas Gregora16548e2009-08-11 05:31:07 +00008152 if (!getDerived().AlwaysRebuild() &&
8153 Callee.get() == E->getCallee() &&
8154 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008155 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008156 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008157
Lang Hames5de91cc2012-10-02 04:45:10 +00008158 Sema::FPContractStateRAII FPContractState(getSema());
8159 getSema().FPFeatures.fp_contract = E->isFPContractable();
8160
Douglas Gregora16548e2009-08-11 05:31:07 +00008161 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8162 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008163 Callee.get(),
8164 First.get(),
8165 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008166}
Mike Stump11289f42009-09-09 15:08:12 +00008167
Douglas Gregora16548e2009-08-11 05:31:07 +00008168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008169ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008170TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8171 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008172}
Mike Stump11289f42009-09-09 15:08:12 +00008173
Douglas Gregora16548e2009-08-11 05:31:07 +00008174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008175ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008176TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8177 // Transform the callee.
8178 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8179 if (Callee.isInvalid())
8180 return ExprError();
8181
8182 // Transform exec config.
8183 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8184 if (EC.isInvalid())
8185 return ExprError();
8186
8187 // Transform arguments.
8188 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008189 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008190 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008191 &ArgChanged))
8192 return ExprError();
8193
8194 if (!getDerived().AlwaysRebuild() &&
8195 Callee.get() == E->getCallee() &&
8196 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008197 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008198
8199 // FIXME: Wrong source location information for the '('.
8200 SourceLocation FakeLParenLoc
8201 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8202 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008203 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008204 E->getRParenLoc(), EC.get());
8205}
8206
8207template<typename Derived>
8208ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008209TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008210 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8211 if (!Type)
8212 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008213
John McCalldadc5752010-08-24 06:29:42 +00008214 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008215 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008216 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008218
Douglas Gregora16548e2009-08-11 05:31:07 +00008219 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008220 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008222 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008223 return getDerived().RebuildCXXNamedCastExpr(
8224 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8225 Type, E->getAngleBrackets().getEnd(),
8226 // FIXME. this should be '(' location
8227 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008228}
Mike Stump11289f42009-09-09 15:08:12 +00008229
Douglas Gregora16548e2009-08-11 05:31:07 +00008230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008232TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8233 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008234}
Mike Stump11289f42009-09-09 15:08:12 +00008235
8236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008238TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8239 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008240}
8241
Douglas Gregora16548e2009-08-11 05:31:07 +00008242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008243ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008244TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008245 CXXReinterpretCastExpr *E) {
8246 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008247}
Mike Stump11289f42009-09-09 15:08:12 +00008248
Douglas Gregora16548e2009-08-11 05:31:07 +00008249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008251TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8252 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008253}
Mike Stump11289f42009-09-09 15:08:12 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008256ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008257TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008258 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008259 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8260 if (!Type)
8261 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008262
John McCalldadc5752010-08-24 06:29:42 +00008263 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008264 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008265 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008267
Douglas Gregora16548e2009-08-11 05:31:07 +00008268 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008269 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008270 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008271 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008272
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008273 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008274 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008275 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008276 E->getRParenLoc());
8277}
Mike Stump11289f42009-09-09 15:08:12 +00008278
Douglas Gregora16548e2009-08-11 05:31:07 +00008279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008280ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008281TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008282 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008283 TypeSourceInfo *TInfo
8284 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8285 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008287
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008289 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008290 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008291
Douglas Gregor9da64192010-04-26 22:37:10 +00008292 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8293 E->getLocStart(),
8294 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008295 E->getLocEnd());
8296 }
Mike Stump11289f42009-09-09 15:08:12 +00008297
Eli Friedman456f0182012-01-20 01:26:23 +00008298 // We don't know whether the subexpression is potentially evaluated until
8299 // after we perform semantic analysis. We speculatively assume it is
8300 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008301 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008302 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8303 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008304
John McCalldadc5752010-08-24 06:29:42 +00008305 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008306 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008308
Douglas Gregora16548e2009-08-11 05:31:07 +00008309 if (!getDerived().AlwaysRebuild() &&
8310 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008311 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008312
Douglas Gregor9da64192010-04-26 22:37:10 +00008313 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8314 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008315 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008316 E->getLocEnd());
8317}
8318
8319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008320ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008321TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8322 if (E->isTypeOperand()) {
8323 TypeSourceInfo *TInfo
8324 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8325 if (!TInfo)
8326 return ExprError();
8327
8328 if (!getDerived().AlwaysRebuild() &&
8329 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008330 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008331
Douglas Gregor69735112011-03-06 17:40:41 +00008332 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008333 E->getLocStart(),
8334 TInfo,
8335 E->getLocEnd());
8336 }
8337
Francois Pichet9f4f2072010-09-08 12:20:18 +00008338 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8339
8340 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8341 if (SubExpr.isInvalid())
8342 return ExprError();
8343
8344 if (!getDerived().AlwaysRebuild() &&
8345 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008346 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008347
8348 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8349 E->getLocStart(),
8350 SubExpr.get(),
8351 E->getLocEnd());
8352}
8353
8354template<typename Derived>
8355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008356TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008357 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008358}
Mike Stump11289f42009-09-09 15:08:12 +00008359
Douglas Gregora16548e2009-08-11 05:31:07 +00008360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008361ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008362TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008363 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008364 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008365}
Mike Stump11289f42009-09-09 15:08:12 +00008366
Douglas Gregora16548e2009-08-11 05:31:07 +00008367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008369TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008370 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008371
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008372 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8373 // Make sure that we capture 'this'.
8374 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008375 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008377
Douglas Gregorb15af892010-01-07 23:12:05 +00008378 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008379}
Mike Stump11289f42009-09-09 15:08:12 +00008380
Douglas Gregora16548e2009-08-11 05:31:07 +00008381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008383TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008384 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008385 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008386 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008387
Douglas Gregora16548e2009-08-11 05:31:07 +00008388 if (!getDerived().AlwaysRebuild() &&
8389 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008390 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008391
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008392 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8393 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008394}
Mike Stump11289f42009-09-09 15:08:12 +00008395
Douglas Gregora16548e2009-08-11 05:31:07 +00008396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008398TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008399 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008400 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8401 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008402 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008404
Chandler Carruth794da4c2010-02-08 06:42:49 +00008405 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008406 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008407 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008408
Douglas Gregor033f6752009-12-23 23:03:06 +00008409 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008410}
Mike Stump11289f42009-09-09 15:08:12 +00008411
Douglas Gregora16548e2009-08-11 05:31:07 +00008412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008413ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008414TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8415 FieldDecl *Field
8416 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8417 E->getField()));
8418 if (!Field)
8419 return ExprError();
8420
8421 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008422 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008423
8424 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8425}
8426
8427template<typename Derived>
8428ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008429TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8430 CXXScalarValueInitExpr *E) {
8431 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8432 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008433 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008434
Douglas Gregora16548e2009-08-11 05:31:07 +00008435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008436 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008437 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008438
Chad Rosier1dcde962012-08-08 18:46:20 +00008439 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008440 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008441 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008442}
Mike Stump11289f42009-09-09 15:08:12 +00008443
Douglas Gregora16548e2009-08-11 05:31:07 +00008444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008446TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008447 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008448 TypeSourceInfo *AllocTypeInfo
8449 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8450 if (!AllocTypeInfo)
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 size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008454 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008455 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008456 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008457
Douglas Gregora16548e2009-08-11 05:31:07 +00008458 // Transform the placement arguments (if any).
8459 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008460 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008461 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008462 E->getNumPlacementArgs(), true,
8463 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008465
Sebastian Redl6047f072012-02-16 12:22:20 +00008466 // Transform the initializer (if any).
8467 Expr *OldInit = E->getInitializer();
8468 ExprResult NewInit;
8469 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008470 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008471 if (NewInit.isInvalid())
8472 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008473
Sebastian Redl6047f072012-02-16 12:22:20 +00008474 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008475 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008476 if (E->getOperatorNew()) {
8477 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008478 getDerived().TransformDecl(E->getLocStart(),
8479 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008480 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008481 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008482 }
8483
Craig Topperc3ec1492014-05-26 06:22:03 +00008484 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008485 if (E->getOperatorDelete()) {
8486 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008487 getDerived().TransformDecl(E->getLocStart(),
8488 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008489 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008490 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008492
Douglas Gregora16548e2009-08-11 05:31:07 +00008493 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008494 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008495 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008496 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008497 OperatorNew == E->getOperatorNew() &&
8498 OperatorDelete == E->getOperatorDelete() &&
8499 !ArgumentChanged) {
8500 // Mark any declarations we need as referenced.
8501 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008502 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008503 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008504 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008505 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008506
Sebastian Redl6047f072012-02-16 12:22:20 +00008507 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008508 QualType ElementType
8509 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8510 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8511 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8512 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008513 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008514 }
8515 }
8516 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008517
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008518 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008519 }
Mike Stump11289f42009-09-09 15:08:12 +00008520
Douglas Gregor0744ef62010-09-07 21:49:58 +00008521 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008522 if (!ArraySize.get()) {
8523 // If no array size was specified, but the new expression was
8524 // instantiated with an array type (e.g., "new T" where T is
8525 // instantiated with "int[4]"), extract the outer bound from the
8526 // array type as our array size. We do this with constant and
8527 // dependently-sized array types.
8528 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8529 if (!ArrayT) {
8530 // Do nothing
8531 } else if (const ConstantArrayType *ConsArrayT
8532 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008533 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8534 SemaRef.Context.getSizeType(),
8535 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008536 AllocType = ConsArrayT->getElementType();
8537 } else if (const DependentSizedArrayType *DepArrayT
8538 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8539 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008540 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008541 AllocType = DepArrayT->getElementType();
8542 }
8543 }
8544 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008545
Douglas Gregora16548e2009-08-11 05:31:07 +00008546 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8547 E->isGlobalNew(),
8548 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008549 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008550 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008551 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008552 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008553 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008554 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008555 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008556 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008557}
Mike Stump11289f42009-09-09 15:08:12 +00008558
Douglas Gregora16548e2009-08-11 05:31:07 +00008559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008561TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008562 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008563 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008565
Douglas Gregord2d9da02010-02-26 00:38:10 +00008566 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008567 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008568 if (E->getOperatorDelete()) {
8569 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008570 getDerived().TransformDecl(E->getLocStart(),
8571 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008572 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008573 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
Douglas Gregora16548e2009-08-11 05:31:07 +00008576 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008577 Operand.get() == E->getArgument() &&
8578 OperatorDelete == E->getOperatorDelete()) {
8579 // Mark any declarations we need as referenced.
8580 // FIXME: instantiation-specific.
8581 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008582 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008583
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008584 if (!E->getArgument()->isTypeDependent()) {
8585 QualType Destroyed = SemaRef.Context.getBaseElementType(
8586 E->getDestroyedType());
8587 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8588 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008589 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008590 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008591 }
8592 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008593
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008594 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008595 }
Mike Stump11289f42009-09-09 15:08:12 +00008596
Douglas Gregora16548e2009-08-11 05:31:07 +00008597 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8598 E->isGlobalDelete(),
8599 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008600 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008601}
Mike Stump11289f42009-09-09 15:08:12 +00008602
Douglas Gregora16548e2009-08-11 05:31:07 +00008603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008604ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008605TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008606 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008607 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008608 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008609 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008610
John McCallba7bf592010-08-24 05:47:05 +00008611 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008612 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008613 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008614 E->getOperatorLoc(),
8615 E->isArrow()? tok::arrow : tok::period,
8616 ObjectTypePtr,
8617 MayBePseudoDestructor);
8618 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008619 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008620
John McCallba7bf592010-08-24 05:47:05 +00008621 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008622 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8623 if (QualifierLoc) {
8624 QualifierLoc
8625 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8626 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008627 return ExprError();
8628 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008629 CXXScopeSpec SS;
8630 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008631
Douglas Gregor678f90d2010-02-25 01:56:36 +00008632 PseudoDestructorTypeStorage Destroyed;
8633 if (E->getDestroyedTypeInfo()) {
8634 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008635 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008636 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008637 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008638 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008639 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008640 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008641 // We aren't likely to be able to resolve the identifier down to a type
8642 // now anyway, so just retain the identifier.
8643 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8644 E->getDestroyedTypeLoc());
8645 } else {
8646 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008647 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008648 *E->getDestroyedTypeIdentifier(),
8649 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008650 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008651 SS, ObjectTypePtr,
8652 false);
8653 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008654 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008655
Douglas Gregor678f90d2010-02-25 01:56:36 +00008656 Destroyed
8657 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8658 E->getDestroyedTypeLoc());
8659 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008660
Craig Topperc3ec1492014-05-26 06:22:03 +00008661 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008662 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008663 CXXScopeSpec EmptySS;
8664 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008665 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008666 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008667 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008669
John McCallb268a282010-08-23 23:25:46 +00008670 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008671 E->getOperatorLoc(),
8672 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008673 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008674 ScopeTypeInfo,
8675 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008676 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008677 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008678}
Mike Stump11289f42009-09-09 15:08:12 +00008679
Douglas Gregorad8a3362009-09-04 17:36:40 +00008680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008681ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008682TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008683 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008684 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8685 Sema::LookupOrdinaryName);
8686
8687 // Transform all the decls.
8688 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8689 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008690 NamedDecl *InstD = static_cast<NamedDecl*>(
8691 getDerived().TransformDecl(Old->getNameLoc(),
8692 *I));
John McCall84d87672009-12-10 09:41:52 +00008693 if (!InstD) {
8694 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8695 // This can happen because of dependent hiding.
8696 if (isa<UsingShadowDecl>(*I))
8697 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008698 else {
8699 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008700 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008701 }
John McCall84d87672009-12-10 09:41:52 +00008702 }
John McCalle66edc12009-11-24 19:00:30 +00008703
8704 // Expand using declarations.
8705 if (isa<UsingDecl>(InstD)) {
8706 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008707 for (auto *I : UD->shadows())
8708 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008709 continue;
8710 }
8711
8712 R.addDecl(InstD);
8713 }
8714
8715 // Resolve a kind, but don't do any further analysis. If it's
8716 // ambiguous, the callee needs to deal with it.
8717 R.resolveKind();
8718
8719 // Rebuild the nested-name qualifier, if present.
8720 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008721 if (Old->getQualifierLoc()) {
8722 NestedNameSpecifierLoc QualifierLoc
8723 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8724 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008725 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008726
Douglas Gregor0da1d432011-02-28 20:01:57 +00008727 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008728 }
8729
Douglas Gregor9262f472010-04-27 18:19:34 +00008730 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008731 CXXRecordDecl *NamingClass
8732 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8733 Old->getNameLoc(),
8734 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008735 if (!NamingClass) {
8736 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008737 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008738 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008739
Douglas Gregorda7be082010-04-27 16:10:10 +00008740 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008741 }
8742
Abramo Bagnara7945c982012-01-27 09:46:47 +00008743 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8744
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008745 // If we have neither explicit template arguments, nor the template keyword,
8746 // it's a normal declaration name.
8747 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008748 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8749
8750 // If we have template arguments, rebuild them, then rebuild the
8751 // templateid expression.
8752 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008753 if (Old->hasExplicitTemplateArgs() &&
8754 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008755 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008756 TransArgs)) {
8757 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008758 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008759 }
John McCalle66edc12009-11-24 19:00:30 +00008760
Abramo Bagnara7945c982012-01-27 09:46:47 +00008761 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008762 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008763}
Mike Stump11289f42009-09-09 15:08:12 +00008764
Douglas Gregora16548e2009-08-11 05:31:07 +00008765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008766ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008767TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8768 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008769 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008770 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8771 TypeSourceInfo *From = E->getArg(I);
8772 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008773 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008774 TypeLocBuilder TLB;
8775 TLB.reserve(FromTL.getFullDataSize());
8776 QualType To = getDerived().TransformType(TLB, FromTL);
8777 if (To.isNull())
8778 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008779
Douglas Gregor29c42f22012-02-24 07:38:34 +00008780 if (To == From->getType())
8781 Args.push_back(From);
8782 else {
8783 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8784 ArgChanged = true;
8785 }
8786 continue;
8787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008788
Douglas Gregor29c42f22012-02-24 07:38:34 +00008789 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008790
Douglas Gregor29c42f22012-02-24 07:38:34 +00008791 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008792 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008793 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8794 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8795 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008796
Douglas Gregor29c42f22012-02-24 07:38:34 +00008797 // Determine whether the set of unexpanded parameter packs can and should
8798 // be expanded.
8799 bool Expand = true;
8800 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008801 Optional<unsigned> OrigNumExpansions =
8802 ExpansionTL.getTypePtr()->getNumExpansions();
8803 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008804 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8805 PatternTL.getSourceRange(),
8806 Unexpanded,
8807 Expand, RetainExpansion,
8808 NumExpansions))
8809 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008810
Douglas Gregor29c42f22012-02-24 07:38:34 +00008811 if (!Expand) {
8812 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008813 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008814 // expansion.
8815 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008816
Douglas Gregor29c42f22012-02-24 07:38:34 +00008817 TypeLocBuilder TLB;
8818 TLB.reserve(From->getTypeLoc().getFullDataSize());
8819
8820 QualType To = getDerived().TransformType(TLB, PatternTL);
8821 if (To.isNull())
8822 return ExprError();
8823
Chad Rosier1dcde962012-08-08 18:46:20 +00008824 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008825 PatternTL.getSourceRange(),
8826 ExpansionTL.getEllipsisLoc(),
8827 NumExpansions);
8828 if (To.isNull())
8829 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008830
Douglas Gregor29c42f22012-02-24 07:38:34 +00008831 PackExpansionTypeLoc ToExpansionTL
8832 = TLB.push<PackExpansionTypeLoc>(To);
8833 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8834 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8835 continue;
8836 }
8837
8838 // Expand the pack expansion by substituting for each argument in the
8839 // pack(s).
8840 for (unsigned I = 0; I != *NumExpansions; ++I) {
8841 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8842 TypeLocBuilder TLB;
8843 TLB.reserve(PatternTL.getFullDataSize());
8844 QualType To = getDerived().TransformType(TLB, PatternTL);
8845 if (To.isNull())
8846 return ExprError();
8847
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008848 if (To->containsUnexpandedParameterPack()) {
8849 To = getDerived().RebuildPackExpansionType(To,
8850 PatternTL.getSourceRange(),
8851 ExpansionTL.getEllipsisLoc(),
8852 NumExpansions);
8853 if (To.isNull())
8854 return ExprError();
8855
8856 PackExpansionTypeLoc ToExpansionTL
8857 = TLB.push<PackExpansionTypeLoc>(To);
8858 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8859 }
8860
Douglas Gregor29c42f22012-02-24 07:38:34 +00008861 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008863
Douglas Gregor29c42f22012-02-24 07:38:34 +00008864 if (!RetainExpansion)
8865 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008866
Douglas Gregor29c42f22012-02-24 07:38:34 +00008867 // If we're supposed to retain a pack expansion, do so by temporarily
8868 // forgetting the partially-substituted parameter pack.
8869 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8870
8871 TypeLocBuilder TLB;
8872 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008873
Douglas Gregor29c42f22012-02-24 07:38:34 +00008874 QualType To = getDerived().TransformType(TLB, PatternTL);
8875 if (To.isNull())
8876 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008877
8878 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008879 PatternTL.getSourceRange(),
8880 ExpansionTL.getEllipsisLoc(),
8881 NumExpansions);
8882 if (To.isNull())
8883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008884
Douglas Gregor29c42f22012-02-24 07:38:34 +00008885 PackExpansionTypeLoc ToExpansionTL
8886 = TLB.push<PackExpansionTypeLoc>(To);
8887 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8888 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008890
Douglas Gregor29c42f22012-02-24 07:38:34 +00008891 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008892 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008893
8894 return getDerived().RebuildTypeTrait(E->getTrait(),
8895 E->getLocStart(),
8896 Args,
8897 E->getLocEnd());
8898}
8899
8900template<typename Derived>
8901ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008902TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8903 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8904 if (!T)
8905 return ExprError();
8906
8907 if (!getDerived().AlwaysRebuild() &&
8908 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008909 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008910
8911 ExprResult SubExpr;
8912 {
8913 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8914 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8915 if (SubExpr.isInvalid())
8916 return ExprError();
8917
8918 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008919 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008920 }
8921
8922 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8923 E->getLocStart(),
8924 T,
8925 SubExpr.get(),
8926 E->getLocEnd());
8927}
8928
8929template<typename Derived>
8930ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008931TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8932 ExprResult SubExpr;
8933 {
8934 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8935 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8936 if (SubExpr.isInvalid())
8937 return ExprError();
8938
8939 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008940 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008941 }
8942
8943 return getDerived().RebuildExpressionTrait(
8944 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8945}
8946
Reid Kleckner32506ed2014-06-12 23:03:48 +00008947template <typename Derived>
8948ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8949 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8950 TypeSourceInfo **RecoveryTSI) {
8951 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8952 DRE, AddrTaken, RecoveryTSI);
8953
8954 // Propagate both errors and recovered types, which return ExprEmpty.
8955 if (!NewDRE.isUsable())
8956 return NewDRE;
8957
8958 // We got an expr, wrap it up in parens.
8959 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8960 return PE;
8961 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8962 PE->getRParen());
8963}
8964
8965template <typename Derived>
8966ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8967 DependentScopeDeclRefExpr *E) {
8968 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8969 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008970}
8971
8972template<typename Derived>
8973ExprResult
8974TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8975 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008976 bool IsAddressOfOperand,
8977 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008978 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008979 NestedNameSpecifierLoc QualifierLoc
8980 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8981 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008982 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008983 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008984
John McCall31f82722010-11-12 08:19:04 +00008985 // TODO: If this is a conversion-function-id, verify that the
8986 // destination type name (if present) resolves the same way after
8987 // instantiation as it did in the local scope.
8988
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008989 DeclarationNameInfo NameInfo
8990 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8991 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008993
John McCalle66edc12009-11-24 19:00:30 +00008994 if (!E->hasExplicitTemplateArgs()) {
8995 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008996 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008997 // Note: it is sufficient to compare the Name component of NameInfo:
8998 // if name has not changed, DNLoc has not changed either.
8999 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009000 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009001
Reid Kleckner32506ed2014-06-12 23:03:48 +00009002 return getDerived().RebuildDependentScopeDeclRefExpr(
9003 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9004 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009005 }
John McCall6b51f282009-11-23 01:53:49 +00009006
9007 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009008 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9009 E->getNumTemplateArgs(),
9010 TransArgs))
9011 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009012
Reid Kleckner32506ed2014-06-12 23:03:48 +00009013 return getDerived().RebuildDependentScopeDeclRefExpr(
9014 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9015 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009016}
9017
9018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009020TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009021 // CXXConstructExprs other than for list-initialization and
9022 // CXXTemporaryObjectExpr are always implicit, so when we have
9023 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009024 if ((E->getNumArgs() == 1 ||
9025 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009026 (!getDerived().DropCallArgument(E->getArg(0))) &&
9027 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009028 return getDerived().TransformExpr(E->getArg(0));
9029
Douglas Gregora16548e2009-08-11 05:31:07 +00009030 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9031
9032 QualType T = getDerived().TransformType(E->getType());
9033 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009034 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009035
9036 CXXConstructorDecl *Constructor
9037 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009038 getDerived().TransformDecl(E->getLocStart(),
9039 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009040 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009042
Douglas Gregora16548e2009-08-11 05:31:07 +00009043 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009044 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009045 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009046 &ArgumentChanged))
9047 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009048
Douglas Gregora16548e2009-08-11 05:31:07 +00009049 if (!getDerived().AlwaysRebuild() &&
9050 T == E->getType() &&
9051 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009052 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009053 // Mark the constructor as referenced.
9054 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009055 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009056 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009057 }
Mike Stump11289f42009-09-09 15:08:12 +00009058
Douglas Gregordb121ba2009-12-14 16:27:04 +00009059 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9060 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009061 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009062 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009063 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009064 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009065 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009066 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009067 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009068}
Mike Stump11289f42009-09-09 15:08:12 +00009069
Douglas Gregora16548e2009-08-11 05:31:07 +00009070/// \brief Transform a C++ temporary-binding expression.
9071///
Douglas Gregor363b1512009-12-24 18:51:59 +00009072/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9073/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009075ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009076TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009077 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009078}
Mike Stump11289f42009-09-09 15:08:12 +00009079
John McCall5d413782010-12-06 08:20:24 +00009080/// \brief Transform a C++ expression that contains cleanups that should
9081/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009082///
John McCall5d413782010-12-06 08:20:24 +00009083/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009084/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009086ExprResult
John McCall5d413782010-12-06 08:20:24 +00009087TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009088 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009089}
Mike Stump11289f42009-09-09 15:08:12 +00009090
Douglas Gregora16548e2009-08-11 05:31:07 +00009091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009092ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009093TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009094 CXXTemporaryObjectExpr *E) {
9095 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9096 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009097 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009098
Douglas Gregora16548e2009-08-11 05:31:07 +00009099 CXXConstructorDecl *Constructor
9100 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009101 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009102 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009103 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009105
Douglas Gregora16548e2009-08-11 05:31:07 +00009106 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009107 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009108 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009109 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009110 &ArgumentChanged))
9111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009112
Douglas Gregora16548e2009-08-11 05:31:07 +00009113 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009114 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009115 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009116 !ArgumentChanged) {
9117 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009118 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009119 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009121
Richard Smithd59b8322012-12-19 01:39:02 +00009122 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009123 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9124 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009125 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009126 E->getLocEnd());
9127}
Mike Stump11289f42009-09-09 15:08:12 +00009128
Douglas Gregora16548e2009-08-11 05:31:07 +00009129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009130ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009131TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009132 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009133 // lambda body, because they are not semantically within that scope.
9134 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9135 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
9136 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009137 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009138 CEnd = E->capture_end();
9139 C != CEnd; ++C) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009140 if (!C->isInitCapture())
9141 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009142 EnterExpressionEvaluationContext EEEC(getSema(),
9143 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009144 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9145 C->getCapturedVar()->getInit(),
9146 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009147
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009148 if (NewExprInitResult.isInvalid())
9149 return ExprError();
9150 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009151
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009152 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009153 QualType NewInitCaptureType =
9154 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9155 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009156 NewExprInit);
9157 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009158 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9159 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009160 }
9161
Faisal Vali524ca282013-11-12 01:40:44 +00009162 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Reid Kleckneraac43c62014-12-15 21:07:16 +00009163 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9164
Faisal Vali2cba1332013-10-23 06:44:28 +00009165 // Transform the template parameters, and add them to the current
9166 // instantiation scope. The null case is handled correctly.
9167 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
9168 E->getTemplateParameterList());
9169
Richard Smith01014ce2014-11-20 23:53:14 +00009170 // Transform the type of the original lambda's call operator.
9171 // The transformation MUST be done in the CurrentInstantiationScope since
9172 // it introduces a mapping of the original to the newly created
9173 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009174 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009175 {
9176 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9177 FunctionProtoTypeLoc OldCallOpFPTL =
9178 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009179
9180 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009181 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009182 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009183 QualType NewCallOpType = TransformFunctionProtoType(
9184 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009185 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9186 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9187 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009188 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009189 if (NewCallOpType.isNull())
9190 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009191 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9192 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009193 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009194
Eli Friedmand564afb2012-09-19 01:18:11 +00009195 // Create the local class that will describe the lambda.
9196 CXXRecordDecl *Class
9197 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009198 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009199 /*KnownDependent=*/false,
9200 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009201 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9202
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009203 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009204 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9205 Class, E->getIntroducerRange(), NewCallOpTSI,
9206 E->getCallOperator()->getLocEnd(),
9207 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009208 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009209
Faisal Vali2cba1332013-10-23 06:44:28 +00009210 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
9211
Reid Kleckneraac43c62014-12-15 21:07:16 +00009212 // TransformLambdaScope will manage the function scope, so we can disable the
9213 // cleanup.
9214 FuncScopeCleanup.disable();
9215
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009216 return getDerived().TransformLambdaScope(E, NewCallOperator,
9217 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00009218}
9219
9220template<typename Derived>
9221ExprResult
9222TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009223 CXXMethodDecl *CallOperator,
9224 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00009225 bool Invalid = false;
9226
Douglas Gregorb4328232012-02-14 00:00:48 +00009227 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009228 Sema::ContextRAII SavedContext(getSema(), CallOperator,
9229 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009230
Faisal Vali2b391ab2013-09-26 19:54:12 +00009231 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009232 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00009233 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009234 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00009235 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009236 E->hasExplicitParameters(),
9237 E->hasExplicitResultType(),
9238 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00009239
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009240 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009241 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009242 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009243 CEnd = E->capture_end();
9244 C != CEnd; ++C) {
9245 // When we hit the first implicit capture, tell Sema that we've finished
9246 // the list of explicit captures.
9247 if (!FinishedExplicitCaptures && C->isImplicit()) {
9248 getSema().finishLambdaExplicitCaptures(LSI);
9249 FinishedExplicitCaptures = true;
9250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009251
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009252 // Capturing 'this' is trivial.
9253 if (C->capturesThis()) {
9254 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9255 continue;
9256 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009257 // Captured expression will be recaptured during captured variables
9258 // rebuilding.
9259 if (C->capturesVLAType())
9260 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009261
Richard Smithba71c082013-05-16 06:20:58 +00009262 // Rebuild init-captures, including the implied field declaration.
9263 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009264
9265 InitCaptureInfoTy InitExprTypePair =
9266 InitCaptureExprsAndTypes[C - E->capture_begin()];
9267 ExprResult Init = InitExprTypePair.first;
9268 QualType InitQualType = InitExprTypePair.second;
9269 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009270 Invalid = true;
9271 continue;
9272 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009273 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009274 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9275 OldVD->getLocation(), InitExprTypePair.second,
9276 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009277 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009278 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009279 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009280 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009281 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009282 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009283 continue;
9284 }
9285
9286 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9287
Douglas Gregor3e308b12012-02-14 19:27:52 +00009288 // Determine the capture kind for Sema.
9289 Sema::TryCaptureKind Kind
9290 = C->isImplicit()? Sema::TryCapture_Implicit
9291 : C->getCaptureKind() == LCK_ByCopy
9292 ? Sema::TryCapture_ExplicitByVal
9293 : Sema::TryCapture_ExplicitByRef;
9294 SourceLocation EllipsisLoc;
9295 if (C->isPackExpansion()) {
9296 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9297 bool ShouldExpand = false;
9298 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009299 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009300 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9301 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009302 Unexpanded,
9303 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009304 NumExpansions)) {
9305 Invalid = true;
9306 continue;
9307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009308
Douglas Gregor3e308b12012-02-14 19:27:52 +00009309 if (ShouldExpand) {
9310 // The transform has determined that we should perform an expansion;
9311 // transform and capture each of the arguments.
9312 // expansion of the pattern. Do so.
9313 VarDecl *Pack = C->getCapturedVar();
9314 for (unsigned I = 0; I != *NumExpansions; ++I) {
9315 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9316 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009317 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009318 Pack));
9319 if (!CapturedVar) {
9320 Invalid = true;
9321 continue;
9322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009323
Douglas Gregor3e308b12012-02-14 19:27:52 +00009324 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009325 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9326 }
Richard Smith9467be42014-06-06 17:33:35 +00009327
9328 // FIXME: Retain a pack expansion if RetainExpansion is true.
9329
Douglas Gregor3e308b12012-02-14 19:27:52 +00009330 continue;
9331 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009332
Douglas Gregor3e308b12012-02-14 19:27:52 +00009333 EllipsisLoc = C->getEllipsisLoc();
9334 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009335
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009336 // Transform the captured variable.
9337 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009338 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009339 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009340 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009341 Invalid = true;
9342 continue;
9343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009344
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009345 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009346 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009347 }
9348 if (!FinishedExplicitCaptures)
9349 getSema().finishLambdaExplicitCaptures(LSI);
9350
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009351
9352 // Enter a new evaluation context to insulate the lambda from any
9353 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009354 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009355
9356 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009357 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009358 /*IsInstantiation=*/true);
9359 return ExprError();
9360 }
9361
9362 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009363 StmtResult Body = getDerived().TransformStmt(E->getBody());
9364 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009365 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009366 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009367 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009368 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009369
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009370 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009371 /*CurScope=*/nullptr,
9372 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009373}
9374
9375template<typename Derived>
9376ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009377TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009378 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009379 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9380 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009382
Douglas Gregora16548e2009-08-11 05:31:07 +00009383 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009384 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009385 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009386 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009387 &ArgumentChanged))
9388 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009389
Douglas Gregora16548e2009-08-11 05:31:07 +00009390 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009391 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009392 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009393 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009394
Douglas Gregora16548e2009-08-11 05:31:07 +00009395 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009396 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009397 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009398 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009399 E->getRParenLoc());
9400}
Mike Stump11289f42009-09-09 15:08:12 +00009401
Douglas Gregora16548e2009-08-11 05:31:07 +00009402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009403ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009404TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009405 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009406 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009407 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009408 Expr *OldBase;
9409 QualType BaseType;
9410 QualType ObjectType;
9411 if (!E->isImplicitAccess()) {
9412 OldBase = E->getBase();
9413 Base = getDerived().TransformExpr(OldBase);
9414 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009416
John McCall2d74de92009-12-01 22:10:20 +00009417 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009418 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009419 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009420 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009421 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009422 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009423 ObjectTy,
9424 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009425 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009426 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009427
John McCallba7bf592010-08-24 05:47:05 +00009428 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009429 BaseType = ((Expr*) Base.get())->getType();
9430 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009431 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009432 BaseType = getDerived().TransformType(E->getBaseType());
9433 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9434 }
Mike Stump11289f42009-09-09 15:08:12 +00009435
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009436 // Transform the first part of the nested-name-specifier that qualifies
9437 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009438 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009439 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009440 E->getFirstQualifierFoundInScope(),
9441 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009442
Douglas Gregore16af532011-02-28 18:50:33 +00009443 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009444 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009445 QualifierLoc
9446 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9447 ObjectType,
9448 FirstQualifierInScope);
9449 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009450 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009451 }
Mike Stump11289f42009-09-09 15:08:12 +00009452
Abramo Bagnara7945c982012-01-27 09:46:47 +00009453 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9454
John McCall31f82722010-11-12 08:19:04 +00009455 // TODO: If this is a conversion-function-id, verify that the
9456 // destination type name (if present) resolves the same way after
9457 // instantiation as it did in the local scope.
9458
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009459 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009460 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009461 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009462 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009463
John McCall2d74de92009-12-01 22:10:20 +00009464 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009465 // This is a reference to a member without an explicitly-specified
9466 // template argument list. Optimize for this common case.
9467 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009468 Base.get() == OldBase &&
9469 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009470 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009471 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009472 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009473 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009474
John McCallb268a282010-08-23 23:25:46 +00009475 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009476 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009477 E->isArrow(),
9478 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009479 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009480 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009481 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009482 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009483 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009484 }
9485
John McCall6b51f282009-11-23 01:53:49 +00009486 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009487 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9488 E->getNumTemplateArgs(),
9489 TransArgs))
9490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009491
John McCallb268a282010-08-23 23:25:46 +00009492 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009493 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009494 E->isArrow(),
9495 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009496 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009497 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009498 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009499 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009500 &TransArgs);
9501}
9502
9503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009504ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009505TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009506 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009507 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009508 QualType BaseType;
9509 if (!Old->isImplicitAccess()) {
9510 Base = getDerived().TransformExpr(Old->getBase());
9511 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009512 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009513 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009514 Old->isArrow());
9515 if (Base.isInvalid())
9516 return ExprError();
9517 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009518 } else {
9519 BaseType = getDerived().TransformType(Old->getBaseType());
9520 }
John McCall10eae182009-11-30 22:42:35 +00009521
Douglas Gregor0da1d432011-02-28 20:01:57 +00009522 NestedNameSpecifierLoc QualifierLoc;
9523 if (Old->getQualifierLoc()) {
9524 QualifierLoc
9525 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9526 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009527 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009528 }
9529
Abramo Bagnara7945c982012-01-27 09:46:47 +00009530 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9531
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009532 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009533 Sema::LookupOrdinaryName);
9534
9535 // Transform all the decls.
9536 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9537 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009538 NamedDecl *InstD = static_cast<NamedDecl*>(
9539 getDerived().TransformDecl(Old->getMemberLoc(),
9540 *I));
John McCall84d87672009-12-10 09:41:52 +00009541 if (!InstD) {
9542 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9543 // This can happen because of dependent hiding.
9544 if (isa<UsingShadowDecl>(*I))
9545 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009546 else {
9547 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009548 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009549 }
John McCall84d87672009-12-10 09:41:52 +00009550 }
John McCall10eae182009-11-30 22:42:35 +00009551
9552 // Expand using declarations.
9553 if (isa<UsingDecl>(InstD)) {
9554 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009555 for (auto *I : UD->shadows())
9556 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009557 continue;
9558 }
9559
9560 R.addDecl(InstD);
9561 }
9562
9563 R.resolveKind();
9564
Douglas Gregor9262f472010-04-27 18:19:34 +00009565 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009566 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009567 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009568 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009569 Old->getMemberLoc(),
9570 Old->getNamingClass()));
9571 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009572 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009573
Douglas Gregorda7be082010-04-27 16:10:10 +00009574 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009576
John McCall10eae182009-11-30 22:42:35 +00009577 TemplateArgumentListInfo TransArgs;
9578 if (Old->hasExplicitTemplateArgs()) {
9579 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9580 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009581 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9582 Old->getNumTemplateArgs(),
9583 TransArgs))
9584 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009585 }
John McCall38836f02010-01-15 08:34:02 +00009586
9587 // FIXME: to do this check properly, we will need to preserve the
9588 // first-qualifier-in-scope here, just in case we had a dependent
9589 // base (and therefore couldn't do the check) and a
9590 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009591 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009592
John McCallb268a282010-08-23 23:25:46 +00009593 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009594 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009595 Old->getOperatorLoc(),
9596 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009597 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009598 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009599 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009600 R,
9601 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009602 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009603}
9604
9605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009606ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009607TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009608 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009609 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9610 if (SubExpr.isInvalid())
9611 return ExprError();
9612
9613 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009614 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009615
9616 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9617}
9618
9619template<typename Derived>
9620ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009621TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009622 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9623 if (Pattern.isInvalid())
9624 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009625
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009626 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009627 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009628
Douglas Gregorb8840002011-01-14 21:20:45 +00009629 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9630 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009631}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009632
9633template<typename Derived>
9634ExprResult
9635TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9636 // If E is not value-dependent, then nothing will change when we transform it.
9637 // Note: This is an instantiation-centric view.
9638 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009639 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009640
9641 // Note: None of the implementations of TryExpandParameterPacks can ever
9642 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009643 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009644 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9645 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009646 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009647 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009648 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009649 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009650 ShouldExpand, RetainExpansion,
9651 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009652 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009653
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009654 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009655 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009656
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009657 NamedDecl *Pack = E->getPack();
9658 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009659 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009660 Pack));
9661 if (!Pack)
9662 return ExprError();
9663 }
9664
Chad Rosier1dcde962012-08-08 18:46:20 +00009665
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009666 // We now know the length of the parameter pack, so build a new expression
9667 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009668 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9669 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009670 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009671}
9672
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009673template<typename Derived>
9674ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009675TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9676 SubstNonTypeTemplateParmPackExpr *E) {
9677 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009678 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009679}
9680
9681template<typename Derived>
9682ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009683TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9684 SubstNonTypeTemplateParmExpr *E) {
9685 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009686 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009687}
9688
9689template<typename Derived>
9690ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009691TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9692 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009693 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009694}
9695
9696template<typename Derived>
9697ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009698TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9699 MaterializeTemporaryExpr *E) {
9700 return getDerived().TransformExpr(E->GetTemporaryExpr());
9701}
Chad Rosier1dcde962012-08-08 18:46:20 +00009702
Douglas Gregorfe314812011-06-21 17:03:29 +00009703template<typename Derived>
9704ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009705TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9706 Expr *Pattern = E->getPattern();
9707
9708 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9709 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9710 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9711
9712 // Determine whether the set of unexpanded parameter packs can and should
9713 // be expanded.
9714 bool Expand = true;
9715 bool RetainExpansion = false;
9716 Optional<unsigned> NumExpansions;
9717 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9718 Pattern->getSourceRange(),
9719 Unexpanded,
9720 Expand, RetainExpansion,
9721 NumExpansions))
9722 return true;
9723
9724 if (!Expand) {
9725 // Do not expand any packs here, just transform and rebuild a fold
9726 // expression.
9727 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9728
9729 ExprResult LHS =
9730 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9731 if (LHS.isInvalid())
9732 return true;
9733
9734 ExprResult RHS =
9735 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9736 if (RHS.isInvalid())
9737 return true;
9738
9739 if (!getDerived().AlwaysRebuild() &&
9740 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9741 return E;
9742
9743 return getDerived().RebuildCXXFoldExpr(
9744 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9745 RHS.get(), E->getLocEnd());
9746 }
9747
9748 // The transform has determined that we should perform an elementwise
9749 // expansion of the pattern. Do so.
9750 ExprResult Result = getDerived().TransformExpr(E->getInit());
9751 if (Result.isInvalid())
9752 return true;
9753 bool LeftFold = E->isLeftFold();
9754
9755 // If we're retaining an expansion for a right fold, it is the innermost
9756 // component and takes the init (if any).
9757 if (!LeftFold && RetainExpansion) {
9758 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9759
9760 ExprResult Out = getDerived().TransformExpr(Pattern);
9761 if (Out.isInvalid())
9762 return true;
9763
9764 Result = getDerived().RebuildCXXFoldExpr(
9765 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9766 Result.get(), E->getLocEnd());
9767 if (Result.isInvalid())
9768 return true;
9769 }
9770
9771 for (unsigned I = 0; I != *NumExpansions; ++I) {
9772 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9773 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9774 ExprResult Out = getDerived().TransformExpr(Pattern);
9775 if (Out.isInvalid())
9776 return true;
9777
9778 if (Out.get()->containsUnexpandedParameterPack()) {
9779 // We still have a pack; retain a pack expansion for this slice.
9780 Result = getDerived().RebuildCXXFoldExpr(
9781 E->getLocStart(),
9782 LeftFold ? Result.get() : Out.get(),
9783 E->getOperator(), E->getEllipsisLoc(),
9784 LeftFold ? Out.get() : Result.get(),
9785 E->getLocEnd());
9786 } else if (Result.isUsable()) {
9787 // We've got down to a single element; build a binary operator.
9788 Result = getDerived().RebuildBinaryOperator(
9789 E->getEllipsisLoc(), E->getOperator(),
9790 LeftFold ? Result.get() : Out.get(),
9791 LeftFold ? Out.get() : Result.get());
9792 } else
9793 Result = Out;
9794
9795 if (Result.isInvalid())
9796 return true;
9797 }
9798
9799 // If we're retaining an expansion for a left fold, it is the outermost
9800 // component and takes the complete expansion so far as its init (if any).
9801 if (LeftFold && RetainExpansion) {
9802 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9803
9804 ExprResult Out = getDerived().TransformExpr(Pattern);
9805 if (Out.isInvalid())
9806 return true;
9807
9808 Result = getDerived().RebuildCXXFoldExpr(
9809 E->getLocStart(), Result.get(),
9810 E->getOperator(), E->getEllipsisLoc(),
9811 Out.get(), E->getLocEnd());
9812 if (Result.isInvalid())
9813 return true;
9814 }
9815
9816 // If we had no init and an empty pack, and we're not retaining an expansion,
9817 // then produce a fallback value or error.
9818 if (Result.isUnset())
9819 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9820 E->getOperator());
9821
9822 return Result;
9823}
9824
9825template<typename Derived>
9826ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009827TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9828 CXXStdInitializerListExpr *E) {
9829 return getDerived().TransformExpr(E->getSubExpr());
9830}
9831
9832template<typename Derived>
9833ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009834TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009835 return SemaRef.MaybeBindToTemporary(E);
9836}
9837
9838template<typename Derived>
9839ExprResult
9840TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009841 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009842}
9843
9844template<typename Derived>
9845ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009846TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9847 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9848 if (SubExpr.isInvalid())
9849 return ExprError();
9850
9851 if (!getDerived().AlwaysRebuild() &&
9852 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009853 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009854
9855 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009856}
9857
9858template<typename Derived>
9859ExprResult
9860TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9861 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009862 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009863 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009864 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009865 /*IsCall=*/false, Elements, &ArgChanged))
9866 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009867
Ted Kremeneke65b0862012-03-06 20:05:56 +00009868 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9869 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009870
Ted Kremeneke65b0862012-03-06 20:05:56 +00009871 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9872 Elements.data(),
9873 Elements.size());
9874}
9875
9876template<typename Derived>
9877ExprResult
9878TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009879 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009880 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009881 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009882 bool ArgChanged = false;
9883 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9884 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009885
Ted Kremeneke65b0862012-03-06 20:05:56 +00009886 if (OrigElement.isPackExpansion()) {
9887 // This key/value element is a pack expansion.
9888 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9889 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9890 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9891 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9892
9893 // Determine whether the set of unexpanded parameter packs can
9894 // and should be expanded.
9895 bool Expand = true;
9896 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009897 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9898 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009899 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9900 OrigElement.Value->getLocEnd());
9901 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9902 PatternRange,
9903 Unexpanded,
9904 Expand, RetainExpansion,
9905 NumExpansions))
9906 return ExprError();
9907
9908 if (!Expand) {
9909 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009910 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009911 // expansion.
9912 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9913 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9914 if (Key.isInvalid())
9915 return ExprError();
9916
9917 if (Key.get() != OrigElement.Key)
9918 ArgChanged = true;
9919
9920 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9921 if (Value.isInvalid())
9922 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009923
Ted Kremeneke65b0862012-03-06 20:05:56 +00009924 if (Value.get() != OrigElement.Value)
9925 ArgChanged = true;
9926
Chad Rosier1dcde962012-08-08 18:46:20 +00009927 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009928 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9929 };
9930 Elements.push_back(Expansion);
9931 continue;
9932 }
9933
9934 // Record right away that the argument was changed. This needs
9935 // to happen even if the array expands to nothing.
9936 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009937
Ted Kremeneke65b0862012-03-06 20:05:56 +00009938 // The transform has determined that we should perform an elementwise
9939 // expansion of the pattern. Do so.
9940 for (unsigned I = 0; I != *NumExpansions; ++I) {
9941 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9942 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9943 if (Key.isInvalid())
9944 return ExprError();
9945
9946 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9947 if (Value.isInvalid())
9948 return ExprError();
9949
Chad Rosier1dcde962012-08-08 18:46:20 +00009950 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009951 Key.get(), Value.get(), SourceLocation(), NumExpansions
9952 };
9953
9954 // If any unexpanded parameter packs remain, we still have a
9955 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009956 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009957 if (Key.get()->containsUnexpandedParameterPack() ||
9958 Value.get()->containsUnexpandedParameterPack())
9959 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009960
Ted Kremeneke65b0862012-03-06 20:05:56 +00009961 Elements.push_back(Element);
9962 }
9963
Richard Smith9467be42014-06-06 17:33:35 +00009964 // FIXME: Retain a pack expansion if RetainExpansion is true.
9965
Ted Kremeneke65b0862012-03-06 20:05:56 +00009966 // We've finished with this pack expansion.
9967 continue;
9968 }
9969
9970 // Transform and check key.
9971 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9972 if (Key.isInvalid())
9973 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009974
Ted Kremeneke65b0862012-03-06 20:05:56 +00009975 if (Key.get() != OrigElement.Key)
9976 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009977
Ted Kremeneke65b0862012-03-06 20:05:56 +00009978 // Transform and check value.
9979 ExprResult Value
9980 = getDerived().TransformExpr(OrigElement.Value);
9981 if (Value.isInvalid())
9982 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009983
Ted Kremeneke65b0862012-03-06 20:05:56 +00009984 if (Value.get() != OrigElement.Value)
9985 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009986
9987 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009988 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009989 };
9990 Elements.push_back(Element);
9991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009992
Ted Kremeneke65b0862012-03-06 20:05:56 +00009993 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9994 return SemaRef.MaybeBindToTemporary(E);
9995
9996 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9997 Elements.data(),
9998 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009999}
10000
Mike Stump11289f42009-09-09 15:08:12 +000010001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010003TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010004 TypeSourceInfo *EncodedTypeInfo
10005 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10006 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010008
Douglas Gregora16548e2009-08-11 05:31:07 +000010009 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010010 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010011 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010012
10013 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010014 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010015 E->getRParenLoc());
10016}
Mike Stump11289f42009-09-09 15:08:12 +000010017
Douglas Gregora16548e2009-08-11 05:31:07 +000010018template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010019ExprResult TreeTransform<Derived>::
10020TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010021 // This is a kind of implicit conversion, and it needs to get dropped
10022 // and recomputed for the same general reasons that ImplicitCastExprs
10023 // do, as well a more specific one: this expression is only valid when
10024 // it appears *immediately* as an argument expression.
10025 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010026}
10027
10028template<typename Derived>
10029ExprResult TreeTransform<Derived>::
10030TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010031 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010032 = getDerived().TransformType(E->getTypeInfoAsWritten());
10033 if (!TSInfo)
10034 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010035
John McCall31168b02011-06-15 23:02:42 +000010036 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010037 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010039
John McCall31168b02011-06-15 23:02:42 +000010040 if (!getDerived().AlwaysRebuild() &&
10041 TSInfo == E->getTypeInfoAsWritten() &&
10042 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010043 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010044
John McCall31168b02011-06-15 23:02:42 +000010045 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010046 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010047 Result.get());
10048}
10049
10050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010052TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010053 // Transform arguments.
10054 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010055 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010056 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010057 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010058 &ArgChanged))
10059 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010060
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010061 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10062 // Class message: transform the receiver type.
10063 TypeSourceInfo *ReceiverTypeInfo
10064 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10065 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010066 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010067
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010068 // If nothing changed, just retain the existing message send.
10069 if (!getDerived().AlwaysRebuild() &&
10070 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010071 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010072
10073 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010074 SmallVector<SourceLocation, 16> SelLocs;
10075 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010076 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10077 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010078 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010079 E->getMethodDecl(),
10080 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010081 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010082 E->getRightLoc());
10083 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010084 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10085 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10086 // Build a new class message send to 'super'.
10087 SmallVector<SourceLocation, 16> SelLocs;
10088 E->getSelectorLocs(SelLocs);
10089 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10090 E->getSelector(),
10091 SelLocs,
10092 E->getMethodDecl(),
10093 E->getLeftLoc(),
10094 Args,
10095 E->getRightLoc());
10096 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010097
10098 // Instance message: transform the receiver
10099 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10100 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010101 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010102 = getDerived().TransformExpr(E->getInstanceReceiver());
10103 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010104 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010105
10106 // If nothing changed, just retain the existing message send.
10107 if (!getDerived().AlwaysRebuild() &&
10108 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010109 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010110
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010111 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010112 SmallVector<SourceLocation, 16> SelLocs;
10113 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010114 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010115 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010116 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010117 E->getMethodDecl(),
10118 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010119 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010120 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010121}
10122
Mike Stump11289f42009-09-09 15:08:12 +000010123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010124ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010125TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010126 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010127}
10128
Mike Stump11289f42009-09-09 15:08:12 +000010129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010131TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010132 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010133}
10134
Mike Stump11289f42009-09-09 15:08:12 +000010135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010137TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010138 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010139 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010140 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010141 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010142
10143 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010144
Douglas Gregord51d90d2010-04-26 20:11:03 +000010145 // If nothing changed, just retain the existing expression.
10146 if (!getDerived().AlwaysRebuild() &&
10147 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010148 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010149
John McCallb268a282010-08-23 23:25:46 +000010150 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010151 E->getLocation(),
10152 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010153}
10154
Mike Stump11289f42009-09-09 15:08:12 +000010155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010157TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010158 // 'super' and types never change. Property never changes. Just
10159 // retain the existing expression.
10160 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010161 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010162
Douglas Gregor9faee212010-04-26 20:47:02 +000010163 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010164 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010165 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010166 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010167
Douglas Gregor9faee212010-04-26 20:47:02 +000010168 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010169
Douglas Gregor9faee212010-04-26 20:47:02 +000010170 // If nothing changed, just retain the existing expression.
10171 if (!getDerived().AlwaysRebuild() &&
10172 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010173 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010174
John McCallb7bd14f2010-12-02 01:19:52 +000010175 if (E->isExplicitProperty())
10176 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10177 E->getExplicitProperty(),
10178 E->getLocation());
10179
10180 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010181 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010182 E->getImplicitPropertyGetter(),
10183 E->getImplicitPropertySetter(),
10184 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010185}
10186
Mike Stump11289f42009-09-09 15:08:12 +000010187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010188ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010189TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10190 // Transform the base expression.
10191 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10192 if (Base.isInvalid())
10193 return ExprError();
10194
10195 // Transform the key expression.
10196 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10197 if (Key.isInvalid())
10198 return ExprError();
10199
10200 // If nothing changed, just retain the existing expression.
10201 if (!getDerived().AlwaysRebuild() &&
10202 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010203 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010204
Chad Rosier1dcde962012-08-08 18:46:20 +000010205 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010206 Base.get(), Key.get(),
10207 E->getAtIndexMethodDecl(),
10208 E->setAtIndexMethodDecl());
10209}
10210
10211template<typename Derived>
10212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010213TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010214 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010215 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010216 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010217 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010218
Douglas Gregord51d90d2010-04-26 20:11:03 +000010219 // If nothing changed, just retain the existing expression.
10220 if (!getDerived().AlwaysRebuild() &&
10221 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010222 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010223
John McCallb268a282010-08-23 23:25:46 +000010224 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010225 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010226 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010227}
10228
Mike Stump11289f42009-09-09 15:08:12 +000010229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010231TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010232 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010233 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010234 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010235 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010236 SubExprs, &ArgumentChanged))
10237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010238
Douglas Gregora16548e2009-08-11 05:31:07 +000010239 if (!getDerived().AlwaysRebuild() &&
10240 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010241 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010242
Douglas Gregora16548e2009-08-11 05:31:07 +000010243 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010244 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010245 E->getRParenLoc());
10246}
10247
Mike Stump11289f42009-09-09 15:08:12 +000010248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010249ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010250TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10251 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10252 if (SrcExpr.isInvalid())
10253 return ExprError();
10254
10255 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10256 if (!Type)
10257 return ExprError();
10258
10259 if (!getDerived().AlwaysRebuild() &&
10260 Type == E->getTypeSourceInfo() &&
10261 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010262 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010263
10264 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10265 SrcExpr.get(), Type,
10266 E->getRParenLoc());
10267}
10268
10269template<typename Derived>
10270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010271TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010272 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010273
Craig Topperc3ec1492014-05-26 06:22:03 +000010274 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010275 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10276
10277 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010278 blockScope->TheDecl->setBlockMissingReturnType(
10279 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010280
Chris Lattner01cf8db2011-07-20 06:58:45 +000010281 SmallVector<ParmVarDecl*, 4> params;
10282 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010283
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010284 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010285 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10286 oldBlock->param_begin(),
10287 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010288 nullptr, paramTypes, &params)) {
10289 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010290 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010291 }
John McCall490112f2011-02-04 18:33:18 +000010292
Jordan Rosea0a86be2013-03-08 22:25:36 +000010293 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010294 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010295 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010296
Jordan Rose5c382722013-03-08 21:51:21 +000010297 QualType functionType =
10298 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010299 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010300 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010301
10302 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010303 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010304 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010305
10306 if (!oldBlock->blockMissingReturnType()) {
10307 blockScope->HasImplicitReturnType = false;
10308 blockScope->ReturnType = exprResultType;
10309 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010310
John McCall3882ace2011-01-05 12:14:39 +000010311 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010312 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010313 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010314 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010315 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010316 }
John McCall3882ace2011-01-05 12:14:39 +000010317
John McCall490112f2011-02-04 18:33:18 +000010318#ifndef NDEBUG
10319 // In builds with assertions, make sure that we captured everything we
10320 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010321 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010322 for (const auto &I : oldBlock->captures()) {
10323 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010324
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010325 // Ignore parameter packs.
10326 if (isa<ParmVarDecl>(oldCapture) &&
10327 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10328 continue;
John McCall490112f2011-02-04 18:33:18 +000010329
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010330 VarDecl *newCapture =
10331 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10332 oldCapture));
10333 assert(blockScope->CaptureMap.count(newCapture));
10334 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010335 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010336 }
10337#endif
10338
10339 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010340 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010341}
10342
Mike Stump11289f42009-09-09 15:08:12 +000010343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010344ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010345TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010346 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010347}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010348
10349template<typename Derived>
10350ExprResult
10351TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010352 QualType RetTy = getDerived().TransformType(E->getType());
10353 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010354 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010355 SubExprs.reserve(E->getNumSubExprs());
10356 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10357 SubExprs, &ArgumentChanged))
10358 return ExprError();
10359
10360 if (!getDerived().AlwaysRebuild() &&
10361 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010362 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010363
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010364 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010365 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010366}
Chad Rosier1dcde962012-08-08 18:46:20 +000010367
Douglas Gregora16548e2009-08-11 05:31:07 +000010368//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010369// Type reconstruction
10370//===----------------------------------------------------------------------===//
10371
Mike Stump11289f42009-09-09 15:08:12 +000010372template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010373QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10374 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010375 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010376 getDerived().getBaseEntity());
10377}
10378
Mike Stump11289f42009-09-09 15:08:12 +000010379template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010380QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10381 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010382 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010383 getDerived().getBaseEntity());
10384}
10385
Mike Stump11289f42009-09-09 15:08:12 +000010386template<typename Derived>
10387QualType
John McCall70dd5f62009-10-30 00:06:24 +000010388TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10389 bool WrittenAsLValue,
10390 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010391 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010392 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010393}
10394
10395template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010396QualType
John McCall70dd5f62009-10-30 00:06:24 +000010397TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10398 QualType ClassType,
10399 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010400 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10401 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010402}
10403
10404template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010405QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010406TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10407 ArrayType::ArraySizeModifier SizeMod,
10408 const llvm::APInt *Size,
10409 Expr *SizeExpr,
10410 unsigned IndexTypeQuals,
10411 SourceRange BracketsRange) {
10412 if (SizeExpr || !Size)
10413 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10414 IndexTypeQuals, BracketsRange,
10415 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010416
10417 QualType Types[] = {
10418 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10419 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10420 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010421 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010422 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010423 QualType SizeType;
10424 for (unsigned I = 0; I != NumTypes; ++I)
10425 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10426 SizeType = Types[I];
10427 break;
10428 }
Mike Stump11289f42009-09-09 15:08:12 +000010429
Eli Friedman9562f392012-01-25 23:20:27 +000010430 // Note that we can return a VariableArrayType here in the case where
10431 // the element type was a dependent VariableArrayType.
10432 IntegerLiteral *ArraySize
10433 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10434 /*FIXME*/BracketsRange.getBegin());
10435 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010436 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010437 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010438}
Mike Stump11289f42009-09-09 15:08:12 +000010439
Douglas Gregord6ff3322009-08-04 16:50:30 +000010440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010441QualType
10442TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010443 ArrayType::ArraySizeModifier SizeMod,
10444 const llvm::APInt &Size,
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, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010448 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010449}
10450
10451template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010452QualType
Mike Stump11289f42009-09-09 15:08:12 +000010453TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010454 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010455 unsigned IndexTypeQuals,
10456 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010457 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010458 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010459}
Mike Stump11289f42009-09-09 15:08:12 +000010460
Douglas Gregord6ff3322009-08-04 16:50:30 +000010461template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010462QualType
10463TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010464 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010465 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010466 unsigned IndexTypeQuals,
10467 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010468 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010469 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010470 IndexTypeQuals, BracketsRange);
10471}
10472
10473template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010474QualType
10475TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010476 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010477 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010478 unsigned IndexTypeQuals,
10479 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010480 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010481 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010482 IndexTypeQuals, BracketsRange);
10483}
10484
10485template<typename Derived>
10486QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010487 unsigned NumElements,
10488 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010489 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010490 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010491}
Mike Stump11289f42009-09-09 15:08:12 +000010492
Douglas Gregord6ff3322009-08-04 16:50:30 +000010493template<typename Derived>
10494QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10495 unsigned NumElements,
10496 SourceLocation AttributeLoc) {
10497 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10498 NumElements, true);
10499 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010500 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10501 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010502 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010503}
Mike Stump11289f42009-09-09 15:08:12 +000010504
Douglas Gregord6ff3322009-08-04 16:50:30 +000010505template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010506QualType
10507TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010508 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010509 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010510 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010511}
Mike Stump11289f42009-09-09 15:08:12 +000010512
Douglas Gregord6ff3322009-08-04 16:50:30 +000010513template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010514QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10515 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010516 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010517 const FunctionProtoType::ExtProtoInfo &EPI) {
10518 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010519 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010520 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010521 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010522}
Mike Stump11289f42009-09-09 15:08:12 +000010523
Douglas Gregord6ff3322009-08-04 16:50:30 +000010524template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010525QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10526 return SemaRef.Context.getFunctionNoProtoType(T);
10527}
10528
10529template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010530QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10531 assert(D && "no decl found");
10532 if (D->isInvalidDecl()) return QualType();
10533
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010534 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010535 TypeDecl *Ty;
10536 if (isa<UsingDecl>(D)) {
10537 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010538 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010539 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10540
10541 // A valid resolved using typename decl points to exactly one type decl.
10542 assert(++Using->shadow_begin() == Using->shadow_end());
10543 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010544
John McCallb96ec562009-12-04 22:46:56 +000010545 } else {
10546 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10547 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10548 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10549 }
10550
10551 return SemaRef.Context.getTypeDeclType(Ty);
10552}
10553
10554template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010555QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10556 SourceLocation Loc) {
10557 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010558}
10559
10560template<typename Derived>
10561QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10562 return SemaRef.Context.getTypeOfType(Underlying);
10563}
10564
10565template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010566QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10567 SourceLocation Loc) {
10568 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010569}
10570
10571template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010572QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10573 UnaryTransformType::UTTKind UKind,
10574 SourceLocation Loc) {
10575 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10576}
10577
10578template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010579QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010580 TemplateName Template,
10581 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010582 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010583 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010584}
Mike Stump11289f42009-09-09 15:08:12 +000010585
Douglas Gregor1135c352009-08-06 05:28:30 +000010586template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010587QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10588 SourceLocation KWLoc) {
10589 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10590}
10591
10592template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010593TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010594TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010595 bool TemplateKW,
10596 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010597 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010598 Template);
10599}
10600
10601template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010602TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010603TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10604 const IdentifierInfo &Name,
10605 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010606 QualType ObjectType,
10607 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010608 UnqualifiedId TemplateName;
10609 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010610 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010611 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010612 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010613 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010614 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010615 /*EnteringContext=*/false,
10616 Template);
John McCall31f82722010-11-12 08:19:04 +000010617 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010618}
Mike Stump11289f42009-09-09 15:08:12 +000010619
Douglas Gregora16548e2009-08-11 05:31:07 +000010620template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010621TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010622TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010623 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010624 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010625 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010626 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010627 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010628 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010629 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010630 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010631 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010632 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010633 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010634 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010635 /*EnteringContext=*/false,
10636 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010637 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010638}
Chad Rosier1dcde962012-08-08 18:46:20 +000010639
Douglas Gregor71395fa2009-11-04 00:56:37 +000010640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010641ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010642TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10643 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010644 Expr *OrigCallee,
10645 Expr *First,
10646 Expr *Second) {
10647 Expr *Callee = OrigCallee->IgnoreParenCasts();
10648 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010649
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010650 if (First->getObjectKind() == OK_ObjCProperty) {
10651 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10652 if (BinaryOperator::isAssignmentOp(Opc))
10653 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10654 First, Second);
10655 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10656 if (Result.isInvalid())
10657 return ExprError();
10658 First = Result.get();
10659 }
10660
10661 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10662 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10663 if (Result.isInvalid())
10664 return ExprError();
10665 Second = Result.get();
10666 }
10667
Douglas Gregora16548e2009-08-11 05:31:07 +000010668 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010669 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010670 if (!First->getType()->isOverloadableType() &&
10671 !Second->getType()->isOverloadableType())
10672 return getSema().CreateBuiltinArraySubscriptExpr(First,
10673 Callee->getLocStart(),
10674 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010675 } else if (Op == OO_Arrow) {
10676 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010677 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10678 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010679 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010680 // The argument is not of overloadable type, so try to create a
10681 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010682 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010683 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010684
John McCallb268a282010-08-23 23:25:46 +000010685 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010686 }
10687 } else {
John McCallb268a282010-08-23 23:25:46 +000010688 if (!First->getType()->isOverloadableType() &&
10689 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010690 // Neither of the arguments is an overloadable type, so try to
10691 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010692 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010693 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010694 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010695 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010697
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010698 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010699 }
10700 }
Mike Stump11289f42009-09-09 15:08:12 +000010701
10702 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010703 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010704 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010705
John McCallb268a282010-08-23 23:25:46 +000010706 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010707 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010708 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010709 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010710 // If we've resolved this to a particular non-member function, just call
10711 // that function. If we resolved it to a member function,
10712 // CreateOverloaded* will find that function for us.
10713 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10714 if (!isa<CXXMethodDecl>(ND))
10715 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010716 }
Mike Stump11289f42009-09-09 15:08:12 +000010717
Douglas Gregora16548e2009-08-11 05:31:07 +000010718 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010719 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010720 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010721
Douglas Gregora16548e2009-08-11 05:31:07 +000010722 // Create the overloaded operator invocation for unary operators.
10723 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010724 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010725 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010726 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010727 }
Mike Stump11289f42009-09-09 15:08:12 +000010728
Douglas Gregore9d62932011-07-15 16:25:15 +000010729 if (Op == OO_Subscript) {
10730 SourceLocation LBrace;
10731 SourceLocation RBrace;
10732
10733 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010734 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010735 LBrace = SourceLocation::getFromRawEncoding(
10736 NameLoc.CXXOperatorName.BeginOpNameLoc);
10737 RBrace = SourceLocation::getFromRawEncoding(
10738 NameLoc.CXXOperatorName.EndOpNameLoc);
10739 } else {
10740 LBrace = Callee->getLocStart();
10741 RBrace = OpLoc;
10742 }
10743
10744 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10745 First, Second);
10746 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010747
Douglas Gregora16548e2009-08-11 05:31:07 +000010748 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010749 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010750 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010751 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10752 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010754
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010755 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010756}
Mike Stump11289f42009-09-09 15:08:12 +000010757
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010758template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010759ExprResult
John McCallb268a282010-08-23 23:25:46 +000010760TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010761 SourceLocation OperatorLoc,
10762 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010763 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010764 TypeSourceInfo *ScopeType,
10765 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010766 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010767 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010768 QualType BaseType = Base->getType();
10769 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010770 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010771 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010772 !BaseType->getAs<PointerType>()->getPointeeType()
10773 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010774 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000010775 return SemaRef.BuildPseudoDestructorExpr(
10776 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
10777 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010778 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010779
Douglas Gregor678f90d2010-02-25 01:56:36 +000010780 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010781 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10782 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10783 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10784 NameInfo.setNamedTypeInfo(DestroyedType);
10785
Richard Smith8e4a3862012-05-15 06:15:11 +000010786 // The scope type is now known to be a valid nested name specifier
10787 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010788 if (ScopeType) {
10789 if (!ScopeType->getType()->getAs<TagType>()) {
10790 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10791 diag::err_expected_class_or_namespace)
10792 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10793 return ExprError();
10794 }
10795 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10796 CCLoc);
10797 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010798
Abramo Bagnara7945c982012-01-27 09:46:47 +000010799 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010800 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010801 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010802 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010803 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010804 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010805 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010806}
10807
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010808template<typename Derived>
10809StmtResult
10810TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010811 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010812 CapturedDecl *CD = S->getCapturedDecl();
10813 unsigned NumParams = CD->getNumParams();
10814 unsigned ContextParamPos = CD->getContextParamPosition();
10815 SmallVector<Sema::CapturedParamNameType, 4> Params;
10816 for (unsigned I = 0; I < NumParams; ++I) {
10817 if (I != ContextParamPos) {
10818 Params.push_back(
10819 std::make_pair(
10820 CD->getParam(I)->getName(),
10821 getDerived().TransformType(CD->getParam(I)->getType())));
10822 } else {
10823 Params.push_back(std::make_pair(StringRef(), QualType()));
10824 }
10825 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010826 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010827 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010828 StmtResult Body;
10829 {
10830 Sema::CompoundScopeRAII CompoundScope(getSema());
10831 Body = getDerived().TransformStmt(S->getCapturedStmt());
10832 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010833
10834 if (Body.isInvalid()) {
10835 getSema().ActOnCapturedRegionError();
10836 return StmtError();
10837 }
10838
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010839 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010840}
10841
Douglas Gregord6ff3322009-08-04 16:50:30 +000010842} // end namespace clang
10843
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010844#endif