blob: 80896be981d1916b7cc213ad950b61eb58f839e7 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000330 /// \brief Transform the given attribute.
331 ///
332 /// By default, this routine transforms a statement by delegating to the
333 /// appropriate TransformXXXAttr function to transform a specific kind
334 /// of attribute. Subclasses may override this function to transform
335 /// attributed statements using some other mechanism.
336 ///
337 /// \returns the transformed attribute
338 const Attr *TransformAttr(const Attr *S);
339
340/// \brief Transform the specified attribute.
341///
342/// Subclasses should override the transformation of attributes with a pragma
343/// spelling to transform expressions stored within the attribute.
344///
345/// \returns the transformed attribute.
346#define ATTR(X)
347#define PRAGMA_SPELLING_ATTR(X) \
348 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
349#include "clang/Basic/AttrList.inc"
350
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000351 /// \brief Transform the given expression.
352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000353 /// By default, this routine transforms an expression by delegating to the
354 /// appropriate TransformXXXExpr function to build a new expression.
355 /// Subclasses may override this function to transform expressions using some
356 /// other mechanism.
357 ///
358 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000359 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Richard Smithd59b8322012-12-19 01:39:02 +0000361 /// \brief Transform the given initializer.
362 ///
363 /// By default, this routine transforms an initializer by stripping off the
364 /// semantic nodes added by initialization, then passing the result to
365 /// TransformExpr or TransformExprs.
366 ///
367 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000368 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000369
Douglas Gregora3efea12011-01-03 19:04:46 +0000370 /// \brief Transform the given list of expressions.
371 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000372 /// This routine transforms a list of expressions by invoking
373 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 /// support for variadic templates by expanding any pack expansions (if the
375 /// derived class permits such expansion) along the way. When pack expansions
376 /// are present, the number of outputs may not equal the number of inputs.
377 ///
378 /// \param Inputs The set of expressions to be transformed.
379 ///
380 /// \param NumInputs The number of expressions in \c Inputs.
381 ///
382 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 /// be.
385 ///
386 /// \param Outputs The transformed input expressions will be added to this
387 /// vector.
388 ///
389 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
390 /// due to transformation.
391 ///
392 /// \returns true if an error occurred, false otherwise.
393 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000394 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000395 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given declaration, which is referenced from a type
398 /// or expression.
399 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000400 /// By default, acts as the identity function on declarations, unless the
401 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000402 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000403 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000404 llvm::DenseMap<Decl *, Decl *>::iterator Known
405 = TransformedLocalDecls.find(D);
406 if (Known != TransformedLocalDecls.end())
407 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
409 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000410 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000411
Chad Rosier1dcde962012-08-08 18:46:20 +0000412 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// place them on the new declaration.
414 ///
415 /// By default, this operation does nothing. Subclasses may override this
416 /// behavior to transform attributes.
417 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000418
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// \brief Note that a local declaration has been transformed by this
420 /// transformer.
421 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
424 /// the transformer itself has to transform the declarations. This routine
425 /// can be overridden by a subclass that keeps track of such mappings.
426 void transformedLocalDecl(Decl *Old, Decl *New) {
427 TransformedLocalDecls[Old] = New;
428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregorebe10102009-08-20 07:17:43 +0000430 /// \brief Transform the definition of the given declaration.
431 ///
Mike Stump11289f42009-09-09 15:08:12 +0000432 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000433 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000434 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
435 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000438 /// \brief Transform the given declaration, which was the first part of a
439 /// nested-name-specifier in a member access expression.
440 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000441 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000442 /// identifier in a nested-name-specifier of a member access expression, e.g.,
443 /// the \c T in \c x->T::member
444 ///
445 /// By default, invokes TransformDecl() to transform the declaration.
446 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000447 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
448 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregor14454802011-02-25 02:25:35 +0000451 /// \brief Transform the given nested-name-specifier with source-location
452 /// information.
453 ///
454 /// By default, transforms all of the types and declarations within the
455 /// nested-name-specifier. Subclasses may override this function to provide
456 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000457 NestedNameSpecifierLoc
458 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000461
Douglas Gregorf816bd72009-09-03 22:13:48 +0000462 /// \brief Transform the given declaration name.
463 ///
464 /// By default, transforms the types of conversion function, constructor,
465 /// and destructor names and then (if needed) rebuilds the declaration name.
466 /// Identifiers and selectors are returned unmodified. Sublcasses may
467 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000468 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000469 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000470
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000472 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 /// \param SS The nested-name-specifier that qualifies the template
474 /// name. This nested-name-specifier must already have been transformed.
475 ///
476 /// \param Name The template name to transform.
477 ///
478 /// \param NameLoc The source location of the template name.
479 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000480 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000481 /// access expression, this is the type of the object whose member template
482 /// is being referenced.
483 ///
484 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
485 /// also refers to a name within the current (lexical) scope, this is the
486 /// declaration it refers to.
487 ///
488 /// By default, transforms the template name by transforming the declarations
489 /// and nested-name-specifiers that occur within the template name.
490 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000491 TemplateName
492 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
493 SourceLocation NameLoc,
494 QualType ObjectType = QualType(),
495 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000496
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// \brief Transform the given template argument.
498 ///
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// By default, this operation transforms the type, expression, or
500 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000501 /// new template argument from the transformed result. Subclasses may
502 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000503 ///
504 /// Returns true if there was an error.
505 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
506 TemplateArgumentLoc &Output);
507
Douglas Gregor62e06f22010-12-20 17:31:10 +0000508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
512 /// the transformed arguments to the output list.
513 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000514 /// Note that this overload of \c TransformTemplateArguments() is merely
515 /// a convenience function. Subclasses that wish to override this behavior
516 /// should override the iterator-based member template version.
517 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \param Inputs The set of template arguments to be transformed.
519 ///
520 /// \param NumInputs The number of template arguments in \p Inputs.
521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
526 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
527 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 TemplateArgumentListInfo &Outputs) {
529 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
530 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000531
532 /// \brief Transform the given set of template arguments.
533 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000534 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000537 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000538 /// \param First An iterator to the first template argument.
539 ///
540 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
542 /// \param Outputs The set of transformed template arguments output by this
543 /// routine.
544 ///
545 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 template<typename InputIterator>
547 bool TransformTemplateArguments(InputIterator First,
548 InputIterator Last,
549 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000550
John McCall0ad16662009-10-29 08:12:44 +0000551 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
552 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
553 TemplateArgumentLoc &ArgLoc);
554
John McCallbcd03502009-12-07 02:54:59 +0000555 /// \brief Fakes up a TypeSourceInfo for a type.
556 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
557 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000558 getDerived().getBaseLocation());
559 }
Mike Stump11289f42009-09-09 15:08:12 +0000560
John McCall550e0c22009-10-21 00:40:46 +0000561#define ABSTRACT_TYPELOC(CLASS, PARENT)
562#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000563 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000564#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
Richard Smith2e321552014-11-12 02:00:47 +0000566 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000567 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
568 FunctionProtoTypeLoc TL,
569 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000570 unsigned ThisTypeQuals,
571 Fn TransformExceptionSpec);
572
573 bool TransformExceptionSpec(SourceLocation Loc,
574 FunctionProtoType::ExceptionSpecInfo &ESI,
575 SmallVectorImpl<QualType> &Exceptions,
576 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000577
David Majnemerfad8f482013-10-15 09:33:02 +0000578 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000579
Chad Rosier1dcde962012-08-08 18:46:20 +0000580 QualType
John McCall31f82722010-11-12 08:19:04 +0000581 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
582 TemplateSpecializationTypeLoc TL,
583 TemplateName Template);
584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
587 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000588 TemplateName Template,
589 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000590
Nico Weberc153d242014-07-28 00:02:09 +0000591 QualType TransformDependentTemplateSpecializationType(
592 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
593 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000594
John McCall58f10c32010-03-11 09:03:00 +0000595 /// \brief Transforms the parameters of a function type into the
596 /// given vectors.
597 ///
598 /// The result vectors should be kept in sync; null entries in the
599 /// variables vector are acceptable.
600 ///
601 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000602 bool TransformFunctionTypeParams(SourceLocation Loc,
603 ParmVarDecl **Params, unsigned NumParams,
604 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000605 SmallVectorImpl<QualType> &PTypes,
606 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000607
608 /// \brief Transforms a single function-type parameter. Return null
609 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000610 ///
611 /// \param indexAdjustment - A number to add to the parameter's
612 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000613 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000614 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000615 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000616 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000617
John McCall31f82722010-11-12 08:19:04 +0000618 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000619
John McCalldadc5752010-08-24 06:29:42 +0000620 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
621 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000622
Faisal Vali2cba1332013-10-23 06:44:28 +0000623 TemplateParameterList *TransformTemplateParameterList(
624 TemplateParameterList *TPL) {
625 return TPL;
626 }
627
Richard Smithdb2630f2012-10-21 03:28:35 +0000628 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000629
Richard Smithdb2630f2012-10-21 03:28:35 +0000630 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000631 bool IsAddressOfOperand,
632 TypeSourceInfo **RecoveryTSI);
633
634 ExprResult TransformParenDependentScopeDeclRefExpr(
635 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
636 TypeSourceInfo **RecoveryTSI);
637
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000638 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000639
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000640// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
641// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000642#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000643 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000644 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000645#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000646 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000647 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000648#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000649#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000650
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000651#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000652 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000653 OMPClause *Transform ## Class(Class *S);
654#include "clang/Basic/OpenMPKinds.def"
655
Douglas Gregord6ff3322009-08-04 16:50:30 +0000656 /// \brief Build a new pointer type given its pointee type.
657 ///
658 /// By default, performs semantic analysis when building the pointer type.
659 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000660 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661
662 /// \brief Build a new block pointer type given its pointee type.
663 ///
Mike Stump11289f42009-09-09 15:08:12 +0000664 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000666 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667
John McCall70dd5f62009-10-30 00:06:24 +0000668 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000669 ///
John McCall70dd5f62009-10-30 00:06:24 +0000670 /// By default, performs semantic analysis when building the
671 /// reference type. Subclasses may override this routine to provide
672 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 ///
John McCall70dd5f62009-10-30 00:06:24 +0000674 /// \param LValue whether the type was written with an lvalue sigil
675 /// or an rvalue sigil.
676 QualType RebuildReferenceType(QualType ReferentType,
677 bool LValue,
678 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new member pointer type given the pointee type and the
681 /// class type it refers into.
682 ///
683 /// By default, performs semantic analysis when building the member pointer
684 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000685 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
686 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000687
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688 /// \brief Build a new array type given the element type, size
689 /// modifier, size of the array (if known), size expression, and index type
690 /// qualifiers.
691 ///
692 /// By default, performs semantic analysis when building the array type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 QualType RebuildArrayType(QualType ElementType,
696 ArrayType::ArraySizeModifier SizeMod,
697 const llvm::APInt *Size,
698 Expr *SizeExpr,
699 unsigned IndexTypeQuals,
700 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// \brief Build a new constant array type given the element type, size
703 /// modifier, (known) size of the array, and index type qualifiers.
704 ///
705 /// By default, performs semantic analysis when building the array type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000707 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 ArrayType::ArraySizeModifier SizeMod,
709 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000710 unsigned IndexTypeQuals,
711 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// \brief Build a new incomplete array type given the element type, size
714 /// modifier, and index type qualifiers.
715 ///
716 /// By default, performs semantic analysis when building the array type.
717 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000718 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722
Mike Stump11289f42009-09-09 15:08:12 +0000723 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// size modifier, size expression, and index type qualifiers.
725 ///
726 /// By default, performs semantic analysis when building the array type.
727 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000728 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000730 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 unsigned IndexTypeQuals,
732 SourceRange BracketsRange);
733
Mike Stump11289f42009-09-09 15:08:12 +0000734 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000735 /// size modifier, size expression, and index type qualifiers.
736 ///
737 /// By default, performs semantic analysis when building the array type.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000741 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 unsigned IndexTypeQuals,
743 SourceRange BracketsRange);
744
745 /// \brief Build a new vector type given the element type and
746 /// number of elements.
747 ///
748 /// By default, performs semantic analysis when building the vector type.
749 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000750 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000751 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753 /// \brief Build a new extended vector type given the element type and
754 /// number of elements.
755 ///
756 /// By default, performs semantic analysis when building the vector type.
757 /// Subclasses may override this routine to provide different behavior.
758 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
759 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000760
761 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 /// given the element type and number of elements.
763 ///
764 /// By default, performs semantic analysis when building the vector type.
765 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000766 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// \brief Build a new function type.
771 ///
772 /// By default, performs semantic analysis when building the function type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000775 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000776 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000777
John McCall550e0c22009-10-21 00:40:46 +0000778 /// \brief Build a new unprototyped function type.
779 QualType RebuildFunctionNoProtoType(QualType ResultType);
780
John McCallb96ec562009-12-04 22:46:56 +0000781 /// \brief Rebuild an unresolved typename type, given the decl that
782 /// the UnresolvedUsingTypenameDecl was transformed to.
783 QualType RebuildUnresolvedUsingType(Decl *D);
784
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000786 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 return SemaRef.Context.getTypeDeclType(Typedef);
788 }
789
790 /// \brief Build a new class/struct/union type.
791 QualType RebuildRecordType(RecordDecl *Record) {
792 return SemaRef.Context.getTypeDeclType(Record);
793 }
794
795 /// \brief Build a new Enum type.
796 QualType RebuildEnumType(EnumDecl *Enum) {
797 return SemaRef.Context.getTypeDeclType(Enum);
798 }
John McCallfcc33b02009-09-05 00:15:47 +0000799
Mike Stump11289f42009-09-09 15:08:12 +0000800 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000801 ///
802 /// By default, performs semantic analysis when building the typeof type.
803 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000804 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805
Mike Stump11289f42009-09-09 15:08:12 +0000806 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 ///
808 /// By default, builds a new TypeOfType with the given underlying type.
809 QualType RebuildTypeOfType(QualType Underlying);
810
Alexis Hunte852b102011-05-24 22:41:36 +0000811 /// \brief Build a new unary transform type.
812 QualType RebuildUnaryTransformType(QualType BaseType,
813 UnaryTransformType::UTTKind UKind,
814 SourceLocation Loc);
815
Richard Smith74aeef52013-04-26 16:15:35 +0000816 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000817 ///
818 /// By default, performs semantic analysis when building the decltype type.
819 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000820 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000821
Richard Smith74aeef52013-04-26 16:15:35 +0000822 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000823 ///
824 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000825 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000826 // Note, IsDependent is always false here: we implicitly convert an 'auto'
827 // which has been deduced to a dependent type into an undeduced 'auto', so
828 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000829 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
830 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000831 }
832
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 /// \brief Build a new template specialization type.
834 ///
835 /// By default, performs semantic analysis when building the template
836 /// specialization type. Subclasses may override this routine to provide
837 /// different behavior.
838 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000839 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000840 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000841
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000842 /// \brief Build a new parenthesized type.
843 ///
844 /// By default, builds a new ParenType type from the inner type.
845 /// Subclasses may override this routine to provide different behavior.
846 QualType RebuildParenType(QualType InnerType) {
847 return SemaRef.Context.getParenType(InnerType);
848 }
849
Douglas Gregord6ff3322009-08-04 16:50:30 +0000850 /// \brief Build a new qualified name type.
851 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000852 /// By default, builds a new ElaboratedType type from the keyword,
853 /// the nested-name-specifier and the named type.
854 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000855 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
856 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000857 NestedNameSpecifierLoc QualifierLoc,
858 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getElaboratedType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000861 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000862 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000863
864 /// \brief Build a new typename type that refers to a template-id.
865 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000866 /// By default, builds a new DependentNameType type from the
867 /// nested-name-specifier and the given type. Subclasses may override
868 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000869 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 ElaboratedTypeKeyword Keyword,
871 NestedNameSpecifierLoc QualifierLoc,
872 const IdentifierInfo *Name,
873 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000874 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 // Rebuild the template name.
876 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000877 CXXScopeSpec SS;
878 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000879 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000880 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
881 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000882
Douglas Gregora7a795b2011-03-01 20:11:18 +0000883 if (InstName.isNull())
884 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000885
Douglas Gregora7a795b2011-03-01 20:11:18 +0000886 // If it's still dependent, make a dependent specialization.
887 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000888 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
889 QualifierLoc.getNestedNameSpecifier(),
890 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000892
Douglas Gregora7a795b2011-03-01 20:11:18 +0000893 // Otherwise, make an elaborated type wrapping a non-dependent
894 // specialization.
895 QualType T =
896 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
897 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000898
Craig Topperc3ec1492014-05-26 06:22:03 +0000899 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000900 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000901
902 return SemaRef.Context.getElaboratedType(Keyword,
903 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000904 T);
905 }
906
Douglas Gregord6ff3322009-08-04 16:50:30 +0000907 /// \brief Build a new typename type that refers to an identifier.
908 ///
909 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000910 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000911 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000912 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000913 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000914 NestedNameSpecifierLoc QualifierLoc,
915 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000916 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000918 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000919
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000920 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000921 // If the name is still dependent, just build a new dependent name type.
922 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000923 return SemaRef.Context.getDependentNameType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000925 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 }
927
Abramo Bagnara6150c882010-05-11 21:36:43 +0000928 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000929 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000930 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000931
932 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
933
Abramo Bagnarad7548482010-05-19 21:37:53 +0000934 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000935 // into a non-dependent elaborated-type-specifier. Find the tag we're
936 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000937 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
939 if (!DC)
940 return QualType();
941
John McCallbf8c5192010-05-27 06:40:31 +0000942 if (SemaRef.RequireCompleteDeclContext(SS, DC))
943 return QualType();
944
Craig Topperc3ec1492014-05-26 06:22:03 +0000945 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::NotFound:
949 case LookupResult::NotFoundInCurrentInstantiation:
950 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000951
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 case LookupResult::Found:
953 Tag = Result.getAsSingle<TagDecl>();
954 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000955
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 case LookupResult::FoundOverloaded:
957 case LookupResult::FoundUnresolvedValue:
958 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000959
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 case LookupResult::Ambiguous:
961 // Let the LookupResult structure handle ambiguities.
962 return QualType();
963 }
964
965 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000966 // Check where the name exists but isn't a tag type and use that to emit
967 // better diagnostics.
968 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
969 SemaRef.LookupQualifiedName(Result, DC);
970 switch (Result.getResultKind()) {
971 case LookupResult::Found:
972 case LookupResult::FoundOverloaded:
973 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000974 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000975 unsigned Kind = 0;
976 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000977 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
978 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000979 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
980 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
981 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000982 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000983 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000985 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000986 break;
987 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000988 return QualType();
989 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000990
Richard Trieucaa33d32011-06-10 03:11:26 +0000991 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
992 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000993 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000994 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
995 return QualType();
996 }
997
998 // Build the elaborated-type-specifier type.
999 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001000 return SemaRef.Context.getElaboratedType(Keyword,
1001 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001002 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregor822d0302011-01-12 17:07:58 +00001005 /// \brief Build a new pack expansion type.
1006 ///
1007 /// By default, builds a new PackExpansionType type from the given pattern.
1008 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001009 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001010 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001011 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001012 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001013 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1014 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001015 }
1016
Eli Friedman0dfb8892011-10-06 23:00:33 +00001017 /// \brief Build a new atomic type given its value type.
1018 ///
1019 /// By default, performs semantic analysis when building the atomic type.
1020 /// Subclasses may override this routine to provide different behavior.
1021 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1022
Douglas Gregor71dc5092009-08-06 06:41:21 +00001023 /// \brief Build a new template name given a nested name specifier, a flag
1024 /// indicating whether the "template" keyword was provided, and the template
1025 /// that the template name refers to.
1026 ///
1027 /// By default, builds the new template name directly. Subclasses may override
1028 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001029 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001030 bool TemplateKW,
1031 TemplateDecl *Template);
1032
Douglas Gregor71dc5092009-08-06 06:41:21 +00001033 /// \brief Build a new template name given a nested name specifier and the
1034 /// name that is referred to as a template.
1035 ///
1036 /// By default, performs semantic analysis to determine whether the name can
1037 /// be resolved to a specific template, then builds the appropriate kind of
1038 /// template name. Subclasses may override this routine to provide different
1039 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001040 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1041 const IdentifierInfo &Name,
1042 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001043 QualType ObjectType,
1044 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001045
Douglas Gregor71395fa2009-11-04 00:56:37 +00001046 /// \brief Build a new template name given a nested name specifier and the
1047 /// overloaded operator name that is referred to as a template.
1048 ///
1049 /// By default, performs semantic analysis to determine whether the name can
1050 /// be resolved to a specific template, then builds the appropriate kind of
1051 /// template name. Subclasses may override this routine to provide different
1052 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001053 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001054 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001056 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001057
1058 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001059 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001060 ///
1061 /// By default, performs semantic analysis to determine whether the name can
1062 /// be resolved to a specific template, then builds the appropriate kind of
1063 /// template name. Subclasses may override this routine to provide different
1064 /// behavior.
1065 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1066 const TemplateArgument &ArgPack) {
1067 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1068 }
1069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new compound statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001074 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 MultiStmtArg Statements,
1076 SourceLocation RBraceLoc,
1077 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001078 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 IsStmtExpr);
1080 }
1081
1082 /// \brief Build a new case statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001089 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001091 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 ColonLoc);
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Attach the body to a new case statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001099 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001100 getSema().ActOnCaseStmtBody(S, Body);
1101 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 /// \brief Build a new default statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001108 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001110 Stmt *SubStmt) {
1111 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001112 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Build a new label statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001119 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1120 SourceLocation ColonLoc, Stmt *SubStmt) {
1121 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Richard Smithc202b282012-04-14 00:33:13 +00001124 /// \brief Build a new label statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001128 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1129 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001130 Stmt *SubStmt) {
1131 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1132 }
1133
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 /// \brief Build a new "if" statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001138 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001139 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001140 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001141 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 }
Mike Stump11289f42009-09-09 15:08:12 +00001143
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 /// \brief Start building a new switch statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001148 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001149 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001150 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001151 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Douglas Gregorebe10102009-08-20 07:17:43 +00001154 /// \brief Attach the body to the switch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001159 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001160 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001161 }
1162
1163 /// \brief Build a new while statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001167 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1168 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001169 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new do-while statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001177 SourceLocation WhileLoc, SourceLocation LParenLoc,
1178 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001179 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1180 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
1182
1183 /// \brief Build a new for statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001188 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 VarDecl *CondVar, Sema::FullExprArg Inc,
1190 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001191 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001192 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 }
Mike Stump11289f42009-09-09 15:08:12 +00001194
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 /// \brief Build a new goto statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001199 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1200 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001201 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new indirect goto statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001209 SourceLocation StarLoc,
1210 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001211 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 /// \brief Build a new return statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001219 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 /// \brief Build a new declaration statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001226 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001227 SourceLocation StartLoc, SourceLocation EndLoc) {
1228 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001229 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Anders Carlssonaaeef072010-01-24 05:50:09 +00001232 /// \brief Build a new inline asm statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001236 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1237 bool IsVolatile, unsigned NumOutputs,
1238 unsigned NumInputs, IdentifierInfo **Names,
1239 MultiExprArg Constraints, MultiExprArg Exprs,
1240 Expr *AsmString, MultiExprArg Clobbers,
1241 SourceLocation RParenLoc) {
1242 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1243 NumInputs, Names, Constraints, Exprs,
1244 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001245 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001246
Chad Rosier32503022012-06-11 20:47:18 +00001247 /// \brief Build a new MS style inline asm statement.
1248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001251 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001252 ArrayRef<Token> AsmToks,
1253 StringRef AsmString,
1254 unsigned NumOutputs, unsigned NumInputs,
1255 ArrayRef<StringRef> Constraints,
1256 ArrayRef<StringRef> Clobbers,
1257 ArrayRef<Expr*> Exprs,
1258 SourceLocation EndLoc) {
1259 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1260 NumOutputs, NumInputs,
1261 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001262 }
1263
James Dennett2a4d13c2012-06-15 07:13:21 +00001264 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001268 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001269 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001270 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001271 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001272 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001273 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001274 }
1275
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 /// \brief Rebuild an Objective-C exception declaration.
1277 ///
1278 /// By default, performs semantic analysis to build the new declaration.
1279 /// Subclasses may override this routine to provide different behavior.
1280 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1281 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001282 return getSema().BuildObjCExceptionDecl(TInfo, T,
1283 ExceptionDecl->getInnerLocStart(),
1284 ExceptionDecl->getLocation(),
1285 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001287
James Dennett2a4d13c2012-06-15 07:13:21 +00001288 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001293 SourceLocation RParenLoc,
1294 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001295 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001296 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001297 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001298 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001299
James Dennett2a4d13c2012-06-15 07:13:21 +00001300 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001301 ///
1302 /// By default, performs semantic analysis to build the new statement.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001305 Stmt *Body) {
1306 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001308
James Dennett2a4d13c2012-06-15 07:13:21 +00001309 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001314 Expr *Operand) {
1315 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001317
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001318 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001319 ///
1320 /// By default, performs semantic analysis to build the new statement.
1321 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001322 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001323 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001324 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001325 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001326 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001327 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001328 return getSema().ActOnOpenMPExecutableDirective(
1329 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001330 }
1331
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001332 /// \brief Build a new OpenMP 'if' clause.
1333 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001334 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001335 /// Subclasses may override this routine to provide different behavior.
1336 OMPClause *RebuildOMPIfClause(Expr *Condition,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1341 LParenLoc, EndLoc);
1342 }
1343
Alexey Bataev3778b602014-07-17 07:32:53 +00001344 /// \brief Build a new OpenMP 'final' clause.
1345 ///
1346 /// By default, performs semantic analysis to build the new OpenMP clause.
1347 /// Subclasses may override this routine to provide different behavior.
1348 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1349 SourceLocation LParenLoc,
1350 SourceLocation EndLoc) {
1351 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1352 EndLoc);
1353 }
1354
Alexey Bataev568a8332014-03-06 06:15:19 +00001355 /// \brief Build a new OpenMP 'num_threads' clause.
1356 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001357 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001358 /// Subclasses may override this routine to provide different behavior.
1359 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1360 SourceLocation StartLoc,
1361 SourceLocation LParenLoc,
1362 SourceLocation EndLoc) {
1363 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1364 LParenLoc, EndLoc);
1365 }
1366
Alexey Bataev62c87d22014-03-21 04:51:18 +00001367 /// \brief Build a new OpenMP 'safelen' clause.
1368 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001369 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001370 /// Subclasses may override this routine to provide different behavior.
1371 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1372 SourceLocation LParenLoc,
1373 SourceLocation EndLoc) {
1374 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1375 }
1376
Alexander Musman8bd31e62014-05-27 15:12:19 +00001377 /// \brief Build a new OpenMP 'collapse' clause.
1378 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001379 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001380 /// Subclasses may override this routine to provide different behavior.
1381 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1382 SourceLocation LParenLoc,
1383 SourceLocation EndLoc) {
1384 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1385 EndLoc);
1386 }
1387
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001388 /// \brief Build a new OpenMP 'default' clause.
1389 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001390 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001391 /// Subclasses may override this routine to provide different behavior.
1392 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1393 SourceLocation KindKwLoc,
1394 SourceLocation StartLoc,
1395 SourceLocation LParenLoc,
1396 SourceLocation EndLoc) {
1397 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1398 StartLoc, LParenLoc, EndLoc);
1399 }
1400
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001401 /// \brief Build a new OpenMP 'proc_bind' clause.
1402 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001403 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001404 /// Subclasses may override this routine to provide different behavior.
1405 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1406 SourceLocation KindKwLoc,
1407 SourceLocation StartLoc,
1408 SourceLocation LParenLoc,
1409 SourceLocation EndLoc) {
1410 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1411 StartLoc, LParenLoc, EndLoc);
1412 }
1413
Alexey Bataev56dafe82014-06-20 07:16:17 +00001414 /// \brief Build a new OpenMP 'schedule' clause.
1415 ///
1416 /// By default, performs semantic analysis to build the new OpenMP clause.
1417 /// Subclasses may override this routine to provide different behavior.
1418 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1419 Expr *ChunkSize,
1420 SourceLocation StartLoc,
1421 SourceLocation LParenLoc,
1422 SourceLocation KindLoc,
1423 SourceLocation CommaLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPScheduleClause(
1426 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1427 }
1428
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001429 /// \brief Build a new OpenMP 'private' clause.
1430 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001431 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1438 EndLoc);
1439 }
1440
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001441 /// \brief Build a new OpenMP 'firstprivate' clause.
1442 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001443 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1450 EndLoc);
1451 }
1452
Alexander Musman1bb328c2014-06-04 13:06:39 +00001453 /// \brief Build a new OpenMP 'lastprivate' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new OpenMP clause.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1458 SourceLocation StartLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation EndLoc) {
1461 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1462 EndLoc);
1463 }
1464
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001465 /// \brief Build a new OpenMP 'shared' clause.
1466 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001467 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001468 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001469 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1470 SourceLocation StartLoc,
1471 SourceLocation LParenLoc,
1472 SourceLocation EndLoc) {
1473 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1474 EndLoc);
1475 }
1476
Alexey Bataevc5e02582014-06-16 07:08:35 +00001477 /// \brief Build a new OpenMP 'reduction' clause.
1478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1481 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1482 SourceLocation StartLoc,
1483 SourceLocation LParenLoc,
1484 SourceLocation ColonLoc,
1485 SourceLocation EndLoc,
1486 CXXScopeSpec &ReductionIdScopeSpec,
1487 const DeclarationNameInfo &ReductionId) {
1488 return getSema().ActOnOpenMPReductionClause(
1489 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1490 ReductionId);
1491 }
1492
Alexander Musman8dba6642014-04-22 13:09:42 +00001493 /// \brief Build a new OpenMP 'linear' clause.
1494 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001495 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001496 /// Subclasses may override this routine to provide different behavior.
1497 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1498 SourceLocation StartLoc,
1499 SourceLocation LParenLoc,
1500 SourceLocation ColonLoc,
1501 SourceLocation EndLoc) {
1502 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1503 ColonLoc, EndLoc);
1504 }
1505
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001506 /// \brief Build a new OpenMP 'aligned' clause.
1507 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001508 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001509 /// Subclasses may override this routine to provide different behavior.
1510 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1511 SourceLocation StartLoc,
1512 SourceLocation LParenLoc,
1513 SourceLocation ColonLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1516 LParenLoc, ColonLoc, EndLoc);
1517 }
1518
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001519 /// \brief Build a new OpenMP 'copyin' clause.
1520 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001521 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001522 /// Subclasses may override this routine to provide different behavior.
1523 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1524 SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1528 EndLoc);
1529 }
1530
Alexey Bataevbae9a792014-06-27 10:37:06 +00001531 /// \brief Build a new OpenMP 'copyprivate' clause.
1532 ///
1533 /// By default, performs semantic analysis to build the new OpenMP clause.
1534 /// Subclasses may override this routine to provide different behavior.
1535 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1536 SourceLocation StartLoc,
1537 SourceLocation LParenLoc,
1538 SourceLocation EndLoc) {
1539 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1540 EndLoc);
1541 }
1542
Alexey Bataev6125da92014-07-21 11:26:11 +00001543 /// \brief Build a new OpenMP 'flush' pseudo clause.
1544 ///
1545 /// By default, performs semantic analysis to build the new OpenMP clause.
1546 /// Subclasses may override this routine to provide different behavior.
1547 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1548 SourceLocation StartLoc,
1549 SourceLocation LParenLoc,
1550 SourceLocation EndLoc) {
1551 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1552 EndLoc);
1553 }
1554
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001555 /// \brief Build a new OpenMP 'depend' pseudo clause.
1556 ///
1557 /// By default, performs semantic analysis to build the new OpenMP clause.
1558 /// Subclasses may override this routine to provide different behavior.
1559 OMPClause *
1560 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1561 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1562 SourceLocation StartLoc, SourceLocation LParenLoc,
1563 SourceLocation EndLoc) {
1564 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1565 StartLoc, LParenLoc, EndLoc);
1566 }
1567
James Dennett2a4d13c2012-06-15 07:13:21 +00001568 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001569 ///
1570 /// By default, performs semantic analysis to build the new statement.
1571 /// Subclasses may override this routine to provide different behavior.
1572 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1573 Expr *object) {
1574 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1575 }
1576
James Dennett2a4d13c2012-06-15 07:13:21 +00001577 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001578 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001579 /// By default, performs semantic analysis to build the new statement.
1580 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001582 Expr *Object, Stmt *Body) {
1583 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001584 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001585
James Dennett2a4d13c2012-06-15 07:13:21 +00001586 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001587 ///
1588 /// By default, performs semantic analysis to build the new statement.
1589 /// Subclasses may override this routine to provide different behavior.
1590 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1591 Stmt *Body) {
1592 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1593 }
John McCall53848232011-07-27 01:07:15 +00001594
Douglas Gregorf68a5082010-04-22 23:10:45 +00001595 /// \brief Build a new Objective-C fast enumeration statement.
1596 ///
1597 /// By default, performs semantic analysis to build the new statement.
1598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001599 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001600 Stmt *Element,
1601 Expr *Collection,
1602 SourceLocation RParenLoc,
1603 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001604 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001605 Element,
John McCallb268a282010-08-23 23:25:46 +00001606 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001607 RParenLoc);
1608 if (ForEachStmt.isInvalid())
1609 return StmtError();
1610
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001611 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001613
Douglas Gregorebe10102009-08-20 07:17:43 +00001614 /// \brief Build a new C++ exception declaration.
1615 ///
1616 /// By default, performs semantic analysis to build the new decaration.
1617 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001618 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001619 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001620 SourceLocation StartLoc,
1621 SourceLocation IdLoc,
1622 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001623 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001624 StartLoc, IdLoc, Id);
1625 if (Var)
1626 getSema().CurContext->addDecl(Var);
1627 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001628 }
1629
1630 /// \brief Build a new C++ catch statement.
1631 ///
1632 /// By default, performs semantic analysis to build the new statement.
1633 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001634 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001635 VarDecl *ExceptionDecl,
1636 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001637 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1638 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001639 }
Mike Stump11289f42009-09-09 15:08:12 +00001640
Douglas Gregorebe10102009-08-20 07:17:43 +00001641 /// \brief Build a new C++ try statement.
1642 ///
1643 /// By default, performs semantic analysis to build the new statement.
1644 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001645 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1646 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001647 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001648 }
Mike Stump11289f42009-09-09 15:08:12 +00001649
Richard Smith02e85f32011-04-14 22:09:26 +00001650 /// \brief Build a new C++0x range-based for statement.
1651 ///
1652 /// By default, performs semantic analysis to build the new statement.
1653 /// Subclasses may override this routine to provide different behavior.
1654 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1655 SourceLocation ColonLoc,
1656 Stmt *Range, Stmt *BeginEnd,
1657 Expr *Cond, Expr *Inc,
1658 Stmt *LoopVar,
1659 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001660 // If we've just learned that the range is actually an Objective-C
1661 // collection, treat this as an Objective-C fast enumeration loop.
1662 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1663 if (RangeStmt->isSingleDecl()) {
1664 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001665 if (RangeVar->isInvalidDecl())
1666 return StmtError();
1667
Douglas Gregorf7106af2013-04-08 18:40:13 +00001668 Expr *RangeExpr = RangeVar->getInit();
1669 if (!RangeExpr->isTypeDependent() &&
1670 RangeExpr->getType()->isObjCObjectPointerType())
1671 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1672 RParenLoc);
1673 }
1674 }
1675 }
1676
Richard Smith02e85f32011-04-14 22:09:26 +00001677 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001678 Cond, Inc, LoopVar, RParenLoc,
1679 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001680 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001681
1682 /// \brief Build a new C++0x range-based for statement.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001686 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001687 bool IsIfExists,
1688 NestedNameSpecifierLoc QualifierLoc,
1689 DeclarationNameInfo NameInfo,
1690 Stmt *Nested) {
1691 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1692 QualifierLoc, NameInfo, Nested);
1693 }
1694
Richard Smith02e85f32011-04-14 22:09:26 +00001695 /// \brief Attach body to a C++0x range-based for statement.
1696 ///
1697 /// By default, performs semantic analysis to finish the new statement.
1698 /// Subclasses may override this routine to provide different behavior.
1699 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1700 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1701 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001702
David Majnemerfad8f482013-10-15 09:33:02 +00001703 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001704 Stmt *TryBlock, Stmt *Handler) {
1705 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001706 }
1707
David Majnemerfad8f482013-10-15 09:33:02 +00001708 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001709 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001710 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001711 }
1712
David Majnemerfad8f482013-10-15 09:33:02 +00001713 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001714 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001715 }
1716
Alexey Bataevec474782014-10-09 08:45:04 +00001717 /// \brief Build a new predefined expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
1721 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1722 PredefinedExpr::IdentType IT) {
1723 return getSema().BuildPredefinedExpr(Loc, IT);
1724 }
1725
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 /// \brief Build a new expression that references a declaration.
1727 ///
1728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001730 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001731 LookupResult &R,
1732 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001733 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1734 }
1735
1736
1737 /// \brief Build a new expression that references a declaration.
1738 ///
1739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001741 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001742 ValueDecl *VD,
1743 const DeclarationNameInfo &NameInfo,
1744 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001745 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001746 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001747
1748 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001749
1750 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregora16548e2009-08-11 05:31:07 +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 RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001759 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 }
1761
Douglas Gregorad8a3362009-09-04 17:36:40 +00001762 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001763 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001766 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001767 SourceLocation OperatorLoc,
1768 bool isArrow,
1769 CXXScopeSpec &SS,
1770 TypeSourceInfo *ScopeType,
1771 SourceLocation CCLoc,
1772 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001773 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001776 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001779 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001780 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001781 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001782 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 }
Mike Stump11289f42009-09-09 15:08:12 +00001784
Douglas Gregor882211c2010-04-28 22:16:22 +00001785 /// \brief Build a new builtin offsetof expression.
1786 ///
1787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001790 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001791 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001792 unsigned NumComponents,
1793 SourceLocation RParenLoc) {
1794 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1795 NumComponents, RParenLoc);
1796 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001797
1798 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001799 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001800 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001803 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1804 SourceLocation OpLoc,
1805 UnaryExprOrTypeTrait ExprKind,
1806 SourceRange R) {
1807 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
1809
Peter Collingbournee190dee2011-03-11 19:24:49 +00001810 /// \brief Build a new sizeof, alignof or vec step expression with an
1811 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001812 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001815 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1816 UnaryExprOrTypeTrait ExprKind,
1817 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001818 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001819 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001822
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001823 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 }
Mike Stump11289f42009-09-09 15:08:12 +00001825
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001827 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001832 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001834 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001835 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 RBracketLoc);
1837 }
1838
1839 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001840 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001845 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001846 Expr *ExecConfig = nullptr) {
1847 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001848 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
1850
1851 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001856 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001857 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001858 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001859 const DeclarationNameInfo &MemberNameInfo,
1860 ValueDecl *Member,
1861 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001862 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001863 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001864 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1865 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001866 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001867 // We have a reference to an unnamed field. This is always the
1868 // base of an anonymous struct/union member access, i.e. the
1869 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001870 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001871 assert(Member->getType()->isRecordType() &&
1872 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001873
Richard Smithcab9a7d2011-10-26 19:06:56 +00001874 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001875 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001876 QualifierLoc.getNestedNameSpecifier(),
1877 FoundDecl, Member);
1878 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001879 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001880 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001881 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001882 MemberExpr *ME = new (getSema().Context)
1883 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1884 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001885 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001886 }
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001888 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001889 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001890
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001891 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001892 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001893
John McCall16df1e52010-03-30 21:47:33 +00001894 // FIXME: this involves duplicating earlier analysis in a lot of
1895 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001896 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001897 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001898 R.resolveKind();
1899
John McCallb268a282010-08-23 23:25:46 +00001900 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001901 SS, TemplateKWLoc,
1902 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001903 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001907 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001910 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001911 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001912 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001913 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 }
1915
1916 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001917 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001920 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001921 SourceLocation QuestionLoc,
1922 Expr *LHS,
1923 SourceLocation ColonLoc,
1924 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001925 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1926 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 }
1928
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001930 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001933 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001934 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001937 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001938 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 }
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001942 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// By default, performs semantic analysis to build the new expression.
1944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001945 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001946 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001948 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001949 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001950 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 }
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001954 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 SourceLocation OpLoc,
1959 SourceLocation AccessorLoc,
1960 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001961
John McCall10eae182009-11-30 22:42:35 +00001962 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001963 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001964 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001965 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001966 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001967 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001968 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001969 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 }
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001973 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001976 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001977 MultiExprArg Inits,
1978 SourceLocation RBraceLoc,
1979 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001981 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001982 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001983 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001984
Douglas Gregord3d93062009-11-09 17:16:50 +00001985 // Patch in the result type we were given, which may have been computed
1986 // when the initial InitListExpr was built.
1987 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1988 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001989 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 }
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001993 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 MultiExprArg ArrayExprs,
1998 SourceLocation EqualOrColonLoc,
1999 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002000 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002003 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002006
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002007 return Result;
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 value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 /// By default, builds the implicit value initialization without performing
2013 /// any semantic analysis. Subclasses may override this routine to provide
2014 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002015 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002016 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 }
Mike Stump11289f42009-09-09 15:08:12 +00002018
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002020 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002023 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002024 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002025 SourceLocation RParenLoc) {
2026 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002027 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002028 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 }
2030
2031 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002032 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002036 MultiExprArg SubExprs,
2037 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002038 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 }
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002042 ///
2043 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// rather than attempting to map the label statement itself.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002047 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002048 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 }
Mike Stump11289f42009-09-09 15:08:12 +00002050
Douglas Gregora16548e2009-08-11 05:31:07 +00002051 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002052 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002055 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002056 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002058 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 }
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 /// \brief Build a new __builtin_choose_expr expression.
2062 ///
2063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002065 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002066 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 SourceLocation RParenLoc) {
2068 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 RParenLoc);
2071 }
Mike Stump11289f42009-09-09 15:08:12 +00002072
Peter Collingbourne91147592011-04-15 00:35:48 +00002073 /// \brief Build a new generic selection expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
2077 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2078 SourceLocation DefaultLoc,
2079 SourceLocation RParenLoc,
2080 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002081 ArrayRef<TypeSourceInfo *> Types,
2082 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002083 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002084 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002085 }
2086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 /// \brief Build a new overloaded operator call expression.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// The semantic analysis provides the behavior of template instantiation,
2091 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002092 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 /// argument-dependent lookup, etc. Subclasses may override this routine to
2094 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002095 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002097 Expr *Callee,
2098 Expr *First,
2099 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002100
2101 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 /// reinterpret_cast.
2103 ///
2104 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002105 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002107 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 Stmt::StmtClass Class,
2109 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002110 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 SourceLocation RAngleLoc,
2112 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002113 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 SourceLocation RParenLoc) {
2115 switch (Class) {
2116 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002117 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002118 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002119 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002120
2121 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002122 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002123 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002124 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002125
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002127 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002128 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002129 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002133 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002134 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002135 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002136
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002138 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 }
Mike Stump11289f42009-09-09 15:08:12 +00002141
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 /// \brief Build a new C++ static_cast expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002146 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002148 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002149 SourceLocation RAngleLoc,
2150 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002151 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002153 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002154 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002155 SourceRange(LAngleLoc, RAngleLoc),
2156 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 }
2158
2159 /// \brief Build a new C++ dynamic_cast expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002163 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002165 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 SourceLocation RAngleLoc,
2167 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002168 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002170 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002171 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002172 SourceRange(LAngleLoc, RAngleLoc),
2173 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 }
2175
2176 /// \brief Build a new C++ reinterpret_cast expression.
2177 ///
2178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002180 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002182 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 SourceLocation RAngleLoc,
2184 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002185 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002187 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002188 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002189 SourceRange(LAngleLoc, RAngleLoc),
2190 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 }
2192
2193 /// \brief Build a new C++ const_cast expression.
2194 ///
2195 /// By default, performs semantic analysis to build the new expression.
2196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002197 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002199 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 SourceLocation RAngleLoc,
2201 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002202 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002204 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002205 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002206 SourceRange(LAngleLoc, RAngleLoc),
2207 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 }
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 /// \brief Build a new C++ functional-style cast expression.
2211 ///
2212 /// By default, performs semantic analysis to build the new expression.
2213 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002214 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2215 SourceLocation LParenLoc,
2216 Expr *Sub,
2217 SourceLocation RParenLoc) {
2218 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002219 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 RParenLoc);
2221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// \brief Build a new C++ typeid(type) expression.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002228 SourceLocation TypeidLoc,
2229 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002231 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002232 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Francois Pichet9f4f2072010-09-08 12:20:18 +00002235
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 /// \brief Build a new C++ typeid(expr) expression.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002241 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002242 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002244 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002245 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002246 }
2247
Francois Pichet9f4f2072010-09-08 12:20:18 +00002248 /// \brief Build a new C++ __uuidof(type) expression.
2249 ///
2250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
2252 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2253 SourceLocation TypeidLoc,
2254 TypeSourceInfo *Operand,
2255 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002256 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002257 RParenLoc);
2258 }
2259
2260 /// \brief Build a new C++ __uuidof(expr) expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
2264 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2265 SourceLocation TypeidLoc,
2266 Expr *Operand,
2267 SourceLocation RParenLoc) {
2268 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2269 RParenLoc);
2270 }
2271
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 /// \brief Build a new C++ "this" expression.
2273 ///
2274 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002275 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002278 QualType ThisType,
2279 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002280 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002281 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 }
2283
2284 /// \brief Build a new C++ throw expression.
2285 ///
2286 /// By default, performs semantic analysis to build the new expression.
2287 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002288 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2289 bool IsThrownVariableInScope) {
2290 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 }
2292
2293 /// \brief Build a new C++ default-argument expression.
2294 ///
2295 /// By default, builds a new default-argument expression, which does not
2296 /// require any semantic analysis. Subclasses may override this routine to
2297 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002298 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002299 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002300 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
2302
Richard Smith852c9db2013-04-20 22:23:05 +00002303 /// \brief Build a new C++11 default-initialization expression.
2304 ///
2305 /// By default, builds a new default field initialization expression, which
2306 /// does not require any semantic analysis. Subclasses may override this
2307 /// routine to provide different behavior.
2308 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2309 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002310 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002311 }
2312
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 /// \brief Build a new C++ zero-initialization expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002317 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2318 SourceLocation LParenLoc,
2319 SourceLocation RParenLoc) {
2320 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002321 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 }
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 /// \brief Build a new C++ "new" expression.
2325 ///
2326 /// By default, performs semantic analysis to build the new expression.
2327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002328 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002329 bool UseGlobal,
2330 SourceLocation PlacementLParen,
2331 MultiExprArg PlacementArgs,
2332 SourceLocation PlacementRParen,
2333 SourceRange TypeIdParens,
2334 QualType AllocatedType,
2335 TypeSourceInfo *AllocatedTypeInfo,
2336 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002337 SourceRange DirectInitRange,
2338 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002339 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002341 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002343 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002344 AllocatedType,
2345 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002346 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002347 DirectInitRange,
2348 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 }
Mike Stump11289f42009-09-09 15:08:12 +00002350
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 /// \brief Build a new C++ "delete" expression.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002355 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 bool IsGlobalDelete,
2357 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002358 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002360 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 }
Mike Stump11289f42009-09-09 15:08:12 +00002362
Douglas Gregor29c42f22012-02-24 07:38:34 +00002363 /// \brief Build a new type trait expression.
2364 ///
2365 /// By default, performs semantic analysis to build the new expression.
2366 /// Subclasses may override this routine to provide different behavior.
2367 ExprResult RebuildTypeTrait(TypeTrait Trait,
2368 SourceLocation StartLoc,
2369 ArrayRef<TypeSourceInfo *> Args,
2370 SourceLocation RParenLoc) {
2371 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002373
John Wiegley6242b6a2011-04-28 00:16:57 +00002374 /// \brief Build a new array type trait expression.
2375 ///
2376 /// By default, performs semantic analysis to build the new expression.
2377 /// Subclasses may override this routine to provide different behavior.
2378 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2379 SourceLocation StartLoc,
2380 TypeSourceInfo *TSInfo,
2381 Expr *DimExpr,
2382 SourceLocation RParenLoc) {
2383 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2384 }
2385
John Wiegleyf9f65842011-04-25 06:54:41 +00002386 /// \brief Build a new expression trait expression.
2387 ///
2388 /// By default, performs semantic analysis to build the new expression.
2389 /// Subclasses may override this routine to provide different behavior.
2390 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2391 SourceLocation StartLoc,
2392 Expr *Queried,
2393 SourceLocation RParenLoc) {
2394 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2395 }
2396
Mike Stump11289f42009-09-09 15:08:12 +00002397 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 /// expression.
2399 ///
2400 /// By default, performs semantic analysis to build the new expression.
2401 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002402 ExprResult RebuildDependentScopeDeclRefExpr(
2403 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002404 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002405 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002406 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002407 bool IsAddressOfOperand,
2408 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002410 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002411
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002412 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002413 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2414 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002415
Reid Kleckner32506ed2014-06-12 23:03:48 +00002416 return getSema().BuildQualifiedDeclarationNameExpr(
2417 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 }
2419
2420 /// \brief Build a new template-id expression.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002424 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002425 SourceLocation TemplateKWLoc,
2426 LookupResult &R,
2427 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002428 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002429 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2430 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 }
2432
2433 /// \brief Build a new object-construction expression.
2434 ///
2435 /// By default, performs semantic analysis to build the new expression.
2436 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002437 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002438 SourceLocation Loc,
2439 CXXConstructorDecl *Constructor,
2440 bool IsElidable,
2441 MultiExprArg Args,
2442 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002443 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002444 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002445 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002446 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002447 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002448 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002449 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002450 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002451 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002452
Douglas Gregordb121ba2009-12-14 16:27:04 +00002453 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002454 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002455 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002456 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002457 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002458 RequiresZeroInit, ConstructKind,
2459 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 }
2461
2462 /// \brief Build a new object-construction expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002466 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2467 SourceLocation LParenLoc,
2468 MultiExprArg Args,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002472 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 RParenLoc);
2474 }
2475
2476 /// \brief Build a new object-construction expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002480 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2481 SourceLocation LParenLoc,
2482 MultiExprArg Args,
2483 SourceLocation RParenLoc) {
2484 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002486 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002487 RParenLoc);
2488 }
Mike Stump11289f42009-09-09 15:08:12 +00002489
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 /// \brief Build a new member reference expression.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002494 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002495 QualType BaseType,
2496 bool IsArrow,
2497 SourceLocation OperatorLoc,
2498 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002499 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002500 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002501 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002502 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002504 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002505
John McCallb268a282010-08-23 23:25:46 +00002506 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002507 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002508 SS, TemplateKWLoc,
2509 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002510 MemberNameInfo,
2511 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 }
2513
John McCall10eae182009-11-30 22:42:35 +00002514 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002518 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2519 SourceLocation OperatorLoc,
2520 bool IsArrow,
2521 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002522 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002523 NamedDecl *FirstQualifierInScope,
2524 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002525 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002526 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002527 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002528
John McCallb268a282010-08-23 23:25:46 +00002529 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002530 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002531 SS, TemplateKWLoc,
2532 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002533 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002534 }
Mike Stump11289f42009-09-09 15:08:12 +00002535
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002536 /// \brief Build a new noexcept expression.
2537 ///
2538 /// By default, performs semantic analysis to build the new expression.
2539 /// Subclasses may override this routine to provide different behavior.
2540 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2541 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2542 }
2543
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002544 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002545 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2546 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002547 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002548 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002549 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002550 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2551 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002552 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002553
2554 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2555 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002556 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002557 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002558
Patrick Beard0caa3942012-04-19 00:25:12 +00002559 /// \brief Build a new Objective-C boxed expression.
2560 ///
2561 /// By default, performs semantic analysis to build the new expression.
2562 /// Subclasses may override this routine to provide different behavior.
2563 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2564 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002566
Ted Kremeneke65b0862012-03-06 20:05:56 +00002567 /// \brief Build a new Objective-C array literal.
2568 ///
2569 /// By default, performs semantic analysis to build the new expression.
2570 /// Subclasses may override this routine to provide different behavior.
2571 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2572 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002573 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002574 MultiExprArg(Elements, NumElements));
2575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002576
2577 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002578 Expr *Base, Expr *Key,
2579 ObjCMethodDecl *getterMethod,
2580 ObjCMethodDecl *setterMethod) {
2581 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2582 getterMethod, setterMethod);
2583 }
2584
2585 /// \brief Build a new Objective-C dictionary literal.
2586 ///
2587 /// By default, performs semantic analysis to build the new expression.
2588 /// Subclasses may override this routine to provide different behavior.
2589 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2590 ObjCDictionaryElement *Elements,
2591 unsigned NumElements) {
2592 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2593 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002594
James Dennett2a4d13c2012-06-15 07:13:21 +00002595 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002596 ///
2597 /// By default, performs semantic analysis to build the new expression.
2598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002599 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002600 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002602 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002603 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002604
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002605 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002606 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002607 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002608 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002609 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002610 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002611 MultiExprArg Args,
2612 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002613 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2614 ReceiverTypeInfo->getType(),
2615 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002616 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002617 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002618 }
2619
2620 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002621 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002622 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002623 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002624 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002625 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002626 MultiExprArg Args,
2627 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002628 return SemaRef.BuildInstanceMessage(Receiver,
2629 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002630 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002631 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002632 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002633 }
2634
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002635 /// \brief Build a new Objective-C instance/class message to 'super'.
2636 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2637 Selector Sel,
2638 ArrayRef<SourceLocation> SelectorLocs,
2639 ObjCMethodDecl *Method,
2640 SourceLocation LBracLoc,
2641 MultiExprArg Args,
2642 SourceLocation RBracLoc) {
2643 ObjCInterfaceDecl *Class = Method->getClassInterface();
2644 QualType ReceiverTy = SemaRef.Context.getObjCInterfaceType(Class);
2645
2646 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2647 ReceiverTy,
2648 SuperLoc,
2649 Sel, Method, LBracLoc, SelectorLocs,
2650 RBracLoc, Args)
2651 : SemaRef.BuildClassMessage(nullptr,
2652 ReceiverTy,
2653 SuperLoc,
2654 Sel, Method, LBracLoc, SelectorLocs,
2655 RBracLoc, Args);
2656
2657
2658 }
2659
Douglas Gregord51d90d2010-04-26 20:11:03 +00002660 /// \brief Build a new Objective-C ivar reference expression.
2661 ///
2662 /// By default, performs semantic analysis to build the new expression.
2663 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002664 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002665 SourceLocation IvarLoc,
2666 bool IsArrow, bool IsFreeIvar) {
2667 // FIXME: We lose track of the IsFreeIvar bit.
2668 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002669 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2670 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002671 /*FIXME:*/IvarLoc, IsArrow,
2672 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002673 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002674 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002675 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002676 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002677
2678 /// \brief Build a new Objective-C property reference expression.
2679 ///
2680 /// By default, performs semantic analysis to build the new expression.
2681 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002682 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002683 ObjCPropertyDecl *Property,
2684 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002685 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002686 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2687 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2688 /*FIXME:*/PropertyLoc,
2689 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002690 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002691 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002692 NameInfo,
2693 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002695
John McCallb7bd14f2010-12-02 01:19:52 +00002696 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002697 ///
2698 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002699 /// Subclasses may override this routine to provide different behavior.
2700 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2701 ObjCMethodDecl *Getter,
2702 ObjCMethodDecl *Setter,
2703 SourceLocation PropertyLoc) {
2704 // Since these expressions can only be value-dependent, we do not
2705 // need to perform semantic analysis again.
2706 return Owned(
2707 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2708 VK_LValue, OK_ObjCProperty,
2709 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002710 }
2711
Douglas Gregord51d90d2010-04-26 20:11:03 +00002712 /// \brief Build a new Objective-C "isa" expression.
2713 ///
2714 /// By default, performs semantic analysis to build the new expression.
2715 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002716 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002717 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002718 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002719 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2720 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002721 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002722 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002723 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002724 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002725 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002726 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002727
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 /// \brief Build a new shuffle vector expression.
2729 ///
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002732 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002733 MultiExprArg SubExprs,
2734 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002735 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002736 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002737 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2738 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2739 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002740 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002741
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002743 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002744 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2745 SemaRef.Context.BuiltinFnTy,
2746 VK_RValue, BuiltinLoc);
2747 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2748 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002749 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002750
2751 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002752 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002753 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002754 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002755
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002757 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002758 }
John McCall31f82722010-11-12 08:19:04 +00002759
Hal Finkelc4d7c822013-09-18 03:29:45 +00002760 /// \brief Build a new convert vector expression.
2761 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2762 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2763 SourceLocation RParenLoc) {
2764 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2765 BuiltinLoc, RParenLoc);
2766 }
2767
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002768 /// \brief Build a new template argument pack expansion.
2769 ///
2770 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002771 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002772 /// different behavior.
2773 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002774 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002775 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002776 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002777 case TemplateArgument::Expression: {
2778 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002779 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2780 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002781 if (Result.isInvalid())
2782 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002783
Douglas Gregor98318c22011-01-03 21:37:45 +00002784 return TemplateArgumentLoc(Result.get(), Result.get());
2785 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002786
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002787 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002788 return TemplateArgumentLoc(TemplateArgument(
2789 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002790 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002791 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002792 Pattern.getTemplateNameLoc(),
2793 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002794
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002795 case TemplateArgument::Null:
2796 case TemplateArgument::Integral:
2797 case TemplateArgument::Declaration:
2798 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002799 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002800 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002801 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002802
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002803 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002804 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002805 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002806 EllipsisLoc,
2807 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002808 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2809 Expansion);
2810 break;
2811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002812
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002813 return TemplateArgumentLoc();
2814 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002815
Douglas Gregor968f23a2011-01-03 19:31:53 +00002816 /// \brief Build a new expression pack expansion.
2817 ///
2818 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002819 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002820 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002821 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002822 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002823 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002824 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002825
Richard Smith0f0af192014-11-08 05:07:16 +00002826 /// \brief Build a new C++1z fold-expression.
2827 ///
2828 /// By default, performs semantic analysis in order to build a new fold
2829 /// expression.
2830 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2831 BinaryOperatorKind Operator,
2832 SourceLocation EllipsisLoc, Expr *RHS,
2833 SourceLocation RParenLoc) {
2834 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2835 RHS, RParenLoc);
2836 }
2837
2838 /// \brief Build an empty C++1z fold-expression with the given operator.
2839 ///
2840 /// By default, produces the fallback value for the fold-expression, or
2841 /// produce an error if there is no fallback value.
2842 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2843 BinaryOperatorKind Operator) {
2844 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2845 }
2846
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002847 /// \brief Build a new atomic operation expression.
2848 ///
2849 /// By default, performs semantic analysis to build the new expression.
2850 /// Subclasses may override this routine to provide different behavior.
2851 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2852 MultiExprArg SubExprs,
2853 QualType RetTy,
2854 AtomicExpr::AtomicOp Op,
2855 SourceLocation RParenLoc) {
2856 // Just create the expression; there is not any interesting semantic
2857 // analysis here because we can't actually build an AtomicExpr until
2858 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002859 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002860 RParenLoc);
2861 }
2862
John McCall31f82722010-11-12 08:19:04 +00002863private:
Douglas Gregor14454802011-02-25 02:25:35 +00002864 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2865 QualType ObjectType,
2866 NamedDecl *FirstQualifierInScope,
2867 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002868
2869 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2870 QualType ObjectType,
2871 NamedDecl *FirstQualifierInScope,
2872 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002873
2874 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2875 NamedDecl *FirstQualifierInScope,
2876 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002877};
Douglas Gregora16548e2009-08-11 05:31:07 +00002878
Douglas Gregorebe10102009-08-20 07:17:43 +00002879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002880StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002881 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002882 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002883
Douglas Gregorebe10102009-08-20 07:17:43 +00002884 switch (S->getStmtClass()) {
2885 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002886
Douglas Gregorebe10102009-08-20 07:17:43 +00002887 // Transform individual statement nodes
2888#define STMT(Node, Parent) \
2889 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002890#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002891#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002892#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002893
Douglas Gregorebe10102009-08-20 07:17:43 +00002894 // Transform expressions by calling TransformExpr.
2895#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002896#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002897#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002898#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002899 {
John McCalldadc5752010-08-24 06:29:42 +00002900 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002901 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002902 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002903
Richard Smith945f8d32013-01-14 22:39:08 +00002904 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002905 }
Mike Stump11289f42009-09-09 15:08:12 +00002906 }
2907
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002908 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002909}
Mike Stump11289f42009-09-09 15:08:12 +00002910
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002911template<typename Derived>
2912OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2913 if (!S)
2914 return S;
2915
2916 switch (S->getClauseKind()) {
2917 default: break;
2918 // Transform individual clause nodes
2919#define OPENMP_CLAUSE(Name, Class) \
2920 case OMPC_ ## Name : \
2921 return getDerived().Transform ## Class(cast<Class>(S));
2922#include "clang/Basic/OpenMPKinds.def"
2923 }
2924
2925 return S;
2926}
2927
Mike Stump11289f42009-09-09 15:08:12 +00002928
Douglas Gregore922c772009-08-04 22:27:00 +00002929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002930ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002931 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002932 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002933
2934 switch (E->getStmtClass()) {
2935 case Stmt::NoStmtClass: break;
2936#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002937#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002938#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002939 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002940#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002941 }
2942
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002943 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002944}
2945
2946template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002947ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002948 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002949 // Initializers are instantiated like expressions, except that various outer
2950 // layers are stripped.
2951 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002952 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002953
2954 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2955 Init = ExprTemp->getSubExpr();
2956
Richard Smithe6ca4752013-05-30 22:40:16 +00002957 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2958 Init = MTE->GetTemporaryExpr();
2959
Richard Smithd59b8322012-12-19 01:39:02 +00002960 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2961 Init = Binder->getSubExpr();
2962
2963 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2964 Init = ICE->getSubExprAsWritten();
2965
Richard Smithcc1b96d2013-06-12 22:31:48 +00002966 if (CXXStdInitializerListExpr *ILE =
2967 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002968 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002969
Richard Smithc6abd962014-07-25 01:12:44 +00002970 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002971 // InitListExprs. Other forms of copy-initialization will be a no-op if
2972 // the initializer is already the right type.
2973 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002974 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002975 return getDerived().TransformExpr(Init);
2976
2977 // Revert value-initialization back to empty parens.
2978 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2979 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002980 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002981 Parens.getEnd());
2982 }
2983
2984 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2985 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002986 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002987 SourceLocation());
2988
2989 // Revert initialization by constructor back to a parenthesized or braced list
2990 // of expressions. Any other form of initializer can just be reused directly.
2991 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002992 return getDerived().TransformExpr(Init);
2993
Richard Smithf8adcdc2014-07-17 05:12:35 +00002994 // If the initialization implicitly converted an initializer list to a
2995 // std::initializer_list object, unwrap the std::initializer_list too.
2996 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002997 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002998
Richard Smithd59b8322012-12-19 01:39:02 +00002999 SmallVector<Expr*, 8> NewArgs;
3000 bool ArgChanged = false;
3001 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003002 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003003 return ExprError();
3004
3005 // If this was list initialization, revert to list form.
3006 if (Construct->isListInitialization())
3007 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3008 Construct->getLocEnd(),
3009 Construct->getType());
3010
Richard Smithd59b8322012-12-19 01:39:02 +00003011 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003012 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003013 if (Parens.isInvalid()) {
3014 // This was a variable declaration's initialization for which no initializer
3015 // was specified.
3016 assert(NewArgs.empty() &&
3017 "no parens or braces but have direct init with arguments?");
3018 return ExprEmpty();
3019 }
Richard Smithd59b8322012-12-19 01:39:02 +00003020 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3021 Parens.getEnd());
3022}
3023
3024template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003025bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3026 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003027 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003028 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003029 bool *ArgChanged) {
3030 for (unsigned I = 0; I != NumInputs; ++I) {
3031 // If requested, drop call arguments that need to be dropped.
3032 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3033 if (ArgChanged)
3034 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003035
Douglas Gregora3efea12011-01-03 19:04:46 +00003036 break;
3037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003038
Douglas Gregor968f23a2011-01-03 19:31:53 +00003039 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3040 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003041
Chris Lattner01cf8db2011-07-20 06:58:45 +00003042 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003043 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3044 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003045
Douglas Gregor968f23a2011-01-03 19:31:53 +00003046 // Determine whether the set of unexpanded parameter packs can and should
3047 // be expanded.
3048 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003049 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003050 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3051 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003052 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3053 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003054 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003055 Expand, RetainExpansion,
3056 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003057 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003058
Douglas Gregor968f23a2011-01-03 19:31:53 +00003059 if (!Expand) {
3060 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003061 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003062 // expansion.
3063 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3064 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3065 if (OutPattern.isInvalid())
3066 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003067
3068 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003069 Expansion->getEllipsisLoc(),
3070 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003071 if (Out.isInvalid())
3072 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003073
Douglas Gregor968f23a2011-01-03 19:31:53 +00003074 if (ArgChanged)
3075 *ArgChanged = true;
3076 Outputs.push_back(Out.get());
3077 continue;
3078 }
John McCall542e7c62011-07-06 07:30:07 +00003079
3080 // Record right away that the argument was changed. This needs
3081 // to happen even if the array expands to nothing.
3082 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003083
Douglas Gregor968f23a2011-01-03 19:31:53 +00003084 // The transform has determined that we should perform an elementwise
3085 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003086 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003087 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3088 ExprResult Out = getDerived().TransformExpr(Pattern);
3089 if (Out.isInvalid())
3090 return true;
3091
Richard Smith9467be42014-06-06 17:33:35 +00003092 // FIXME: Can this happen? We should not try to expand the pack
3093 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003094 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003095 Out = getDerived().RebuildPackExpansion(
3096 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003097 if (Out.isInvalid())
3098 return true;
3099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
Douglas Gregor968f23a2011-01-03 19:31:53 +00003101 Outputs.push_back(Out.get());
3102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003103
Richard Smith9467be42014-06-06 17:33:35 +00003104 // If we're supposed to retain a pack expansion, do so by temporarily
3105 // forgetting the partially-substituted parameter pack.
3106 if (RetainExpansion) {
3107 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3108
3109 ExprResult Out = getDerived().TransformExpr(Pattern);
3110 if (Out.isInvalid())
3111 return true;
3112
3113 Out = getDerived().RebuildPackExpansion(
3114 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3115 if (Out.isInvalid())
3116 return true;
3117
3118 Outputs.push_back(Out.get());
3119 }
3120
Douglas Gregor968f23a2011-01-03 19:31:53 +00003121 continue;
3122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
Richard Smithd59b8322012-12-19 01:39:02 +00003124 ExprResult Result =
3125 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3126 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003127 if (Result.isInvalid())
3128 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003129
Douglas Gregora3efea12011-01-03 19:04:46 +00003130 if (Result.get() != Inputs[I] && ArgChanged)
3131 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003132
3133 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003134 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003135
Douglas Gregora3efea12011-01-03 19:04:46 +00003136 return false;
3137}
3138
3139template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003140NestedNameSpecifierLoc
3141TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3142 NestedNameSpecifierLoc NNS,
3143 QualType ObjectType,
3144 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003145 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003146 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003147 Qualifier = Qualifier.getPrefix())
3148 Qualifiers.push_back(Qualifier);
3149
3150 CXXScopeSpec SS;
3151 while (!Qualifiers.empty()) {
3152 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3153 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003154
Douglas Gregor14454802011-02-25 02:25:35 +00003155 switch (QNNS->getKind()) {
3156 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003157 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003158 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003159 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003160 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003161 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003162 FirstQualifierInScope, false))
3163 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003164
Douglas Gregor14454802011-02-25 02:25:35 +00003165 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Douglas Gregor14454802011-02-25 02:25:35 +00003167 case NestedNameSpecifier::Namespace: {
3168 NamespaceDecl *NS
3169 = cast_or_null<NamespaceDecl>(
3170 getDerived().TransformDecl(
3171 Q.getLocalBeginLoc(),
3172 QNNS->getAsNamespace()));
3173 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3174 break;
3175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003176
Douglas Gregor14454802011-02-25 02:25:35 +00003177 case NestedNameSpecifier::NamespaceAlias: {
3178 NamespaceAliasDecl *Alias
3179 = cast_or_null<NamespaceAliasDecl>(
3180 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3181 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003182 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003183 Q.getLocalEndLoc());
3184 break;
3185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003186
Douglas Gregor14454802011-02-25 02:25:35 +00003187 case NestedNameSpecifier::Global:
3188 // There is no meaningful transformation that one could perform on the
3189 // global scope.
3190 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3191 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003192
Nikola Smiljanic67860242014-09-26 00:28:20 +00003193 case NestedNameSpecifier::Super: {
3194 CXXRecordDecl *RD =
3195 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3196 SourceLocation(), QNNS->getAsRecordDecl()));
3197 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3198 break;
3199 }
3200
Douglas Gregor14454802011-02-25 02:25:35 +00003201 case NestedNameSpecifier::TypeSpecWithTemplate:
3202 case NestedNameSpecifier::TypeSpec: {
3203 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3204 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003205
Douglas Gregor14454802011-02-25 02:25:35 +00003206 if (!TL)
3207 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003208
Douglas Gregor14454802011-02-25 02:25:35 +00003209 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003210 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003211 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003212 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003213 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003214 if (TL.getType()->isEnumeralType())
3215 SemaRef.Diag(TL.getBeginLoc(),
3216 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003217 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3218 Q.getLocalEndLoc());
3219 break;
3220 }
Richard Trieude756fb2011-05-07 01:36:37 +00003221 // If the nested-name-specifier is an invalid type def, don't emit an
3222 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003223 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3224 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003225 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003226 << TL.getType() << SS.getRange();
3227 }
Douglas Gregor14454802011-02-25 02:25:35 +00003228 return NestedNameSpecifierLoc();
3229 }
Douglas Gregore16af532011-02-28 18:50:33 +00003230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003231
Douglas Gregore16af532011-02-28 18:50:33 +00003232 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003233 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003234 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003236
Douglas Gregor14454802011-02-25 02:25:35 +00003237 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003238 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003239 !getDerived().AlwaysRebuild())
3240 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003241
3242 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003243 // nested-name-specifier, do so.
3244 if (SS.location_size() == NNS.getDataLength() &&
3245 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3246 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3247
3248 // Allocate new nested-name-specifier location information.
3249 return SS.getWithLocInContext(SemaRef.Context);
3250}
3251
3252template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003253DeclarationNameInfo
3254TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003255::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003256 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003257 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003258 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003259
3260 switch (Name.getNameKind()) {
3261 case DeclarationName::Identifier:
3262 case DeclarationName::ObjCZeroArgSelector:
3263 case DeclarationName::ObjCOneArgSelector:
3264 case DeclarationName::ObjCMultiArgSelector:
3265 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003266 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003267 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003268 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003269
Douglas Gregorf816bd72009-09-03 22:13:48 +00003270 case DeclarationName::CXXConstructorName:
3271 case DeclarationName::CXXDestructorName:
3272 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003273 TypeSourceInfo *NewTInfo;
3274 CanQualType NewCanTy;
3275 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003276 NewTInfo = getDerived().TransformType(OldTInfo);
3277 if (!NewTInfo)
3278 return DeclarationNameInfo();
3279 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003280 }
3281 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003282 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003283 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003284 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003285 if (NewT.isNull())
3286 return DeclarationNameInfo();
3287 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3288 }
Mike Stump11289f42009-09-09 15:08:12 +00003289
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003290 DeclarationName NewName
3291 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3292 NewCanTy);
3293 DeclarationNameInfo NewNameInfo(NameInfo);
3294 NewNameInfo.setName(NewName);
3295 NewNameInfo.setNamedTypeInfo(NewTInfo);
3296 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003297 }
Mike Stump11289f42009-09-09 15:08:12 +00003298 }
3299
David Blaikie83d382b2011-09-23 05:06:16 +00003300 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003301}
3302
3303template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003304TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003305TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3306 TemplateName Name,
3307 SourceLocation NameLoc,
3308 QualType ObjectType,
3309 NamedDecl *FirstQualifierInScope) {
3310 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3311 TemplateDecl *Template = QTN->getTemplateDecl();
3312 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregor9db53502011-03-02 18:07:45 +00003314 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003315 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003316 Template));
3317 if (!TransTemplate)
3318 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003319
Douglas Gregor9db53502011-03-02 18:07:45 +00003320 if (!getDerived().AlwaysRebuild() &&
3321 SS.getScopeRep() == QTN->getQualifier() &&
3322 TransTemplate == Template)
3323 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregor9db53502011-03-02 18:07:45 +00003325 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3326 TransTemplate);
3327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003328
Douglas Gregor9db53502011-03-02 18:07:45 +00003329 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3330 if (SS.getScopeRep()) {
3331 // These apply to the scope specifier, not the template.
3332 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003333 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003334 }
3335
Douglas Gregor9db53502011-03-02 18:07:45 +00003336 if (!getDerived().AlwaysRebuild() &&
3337 SS.getScopeRep() == DTN->getQualifier() &&
3338 ObjectType.isNull())
3339 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
Douglas Gregor9db53502011-03-02 18:07:45 +00003341 if (DTN->isIdentifier()) {
3342 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003343 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003344 NameLoc,
3345 ObjectType,
3346 FirstQualifierInScope);
3347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003348
Douglas Gregor9db53502011-03-02 18:07:45 +00003349 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3350 ObjectType);
3351 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003352
Douglas Gregor9db53502011-03-02 18:07:45 +00003353 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3354 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003355 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003356 Template));
3357 if (!TransTemplate)
3358 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
Douglas Gregor9db53502011-03-02 18:07:45 +00003360 if (!getDerived().AlwaysRebuild() &&
3361 TransTemplate == Template)
3362 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Douglas Gregor9db53502011-03-02 18:07:45 +00003364 return TemplateName(TransTemplate);
3365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003366
Douglas Gregor9db53502011-03-02 18:07:45 +00003367 if (SubstTemplateTemplateParmPackStorage *SubstPack
3368 = Name.getAsSubstTemplateTemplateParmPack()) {
3369 TemplateTemplateParmDecl *TransParam
3370 = cast_or_null<TemplateTemplateParmDecl>(
3371 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3372 if (!TransParam)
3373 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003374
Douglas Gregor9db53502011-03-02 18:07:45 +00003375 if (!getDerived().AlwaysRebuild() &&
3376 TransParam == SubstPack->getParameterPack())
3377 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003378
3379 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003380 SubstPack->getArgumentPack());
3381 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003382
Douglas Gregor9db53502011-03-02 18:07:45 +00003383 // These should be getting filtered out before they reach the AST.
3384 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003385}
3386
3387template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003388void TreeTransform<Derived>::InventTemplateArgumentLoc(
3389 const TemplateArgument &Arg,
3390 TemplateArgumentLoc &Output) {
3391 SourceLocation Loc = getDerived().getBaseLocation();
3392 switch (Arg.getKind()) {
3393 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003394 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003395 break;
3396
3397 case TemplateArgument::Type:
3398 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003399 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003400
John McCall0ad16662009-10-29 08:12:44 +00003401 break;
3402
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003403 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003404 case TemplateArgument::TemplateExpansion: {
3405 NestedNameSpecifierLocBuilder Builder;
3406 TemplateName Template = Arg.getAsTemplate();
3407 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3408 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3409 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3410 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Douglas Gregor9d802122011-03-02 17:09:35 +00003412 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003413 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003414 Builder.getWithLocInContext(SemaRef.Context),
3415 Loc);
3416 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003417 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003418 Builder.getWithLocInContext(SemaRef.Context),
3419 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003420
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003421 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003422 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003423
John McCall0ad16662009-10-29 08:12:44 +00003424 case TemplateArgument::Expression:
3425 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3426 break;
3427
3428 case TemplateArgument::Declaration:
3429 case TemplateArgument::Integral:
3430 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003431 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003432 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003433 break;
3434 }
3435}
3436
3437template<typename Derived>
3438bool TreeTransform<Derived>::TransformTemplateArgument(
3439 const TemplateArgumentLoc &Input,
3440 TemplateArgumentLoc &Output) {
3441 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003442 switch (Arg.getKind()) {
3443 case TemplateArgument::Null:
3444 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003445 case TemplateArgument::Pack:
3446 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003447 case TemplateArgument::NullPtr:
3448 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003449
Douglas Gregore922c772009-08-04 22:27:00 +00003450 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003451 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003452 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003453 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003454
3455 DI = getDerived().TransformType(DI);
3456 if (!DI) return true;
3457
3458 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3459 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003460 }
Mike Stump11289f42009-09-09 15:08:12 +00003461
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003462 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003463 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3464 if (QualifierLoc) {
3465 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3466 if (!QualifierLoc)
3467 return true;
3468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregordf846d12011-03-02 18:46:51 +00003470 CXXScopeSpec SS;
3471 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003472 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003473 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3474 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003475 if (Template.isNull())
3476 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Douglas Gregor9d802122011-03-02 17:09:35 +00003478 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003479 Input.getTemplateNameLoc());
3480 return false;
3481 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003482
3483 case TemplateArgument::TemplateExpansion:
3484 llvm_unreachable("Caller should expand pack expansions");
3485
Douglas Gregore922c772009-08-04 22:27:00 +00003486 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003487 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003488 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003489 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003490
John McCall0ad16662009-10-29 08:12:44 +00003491 Expr *InputExpr = Input.getSourceExpression();
3492 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3493
Chris Lattnercdb591a2011-04-25 20:37:58 +00003494 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003495 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003496 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003497 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003498 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003499 }
Douglas Gregore922c772009-08-04 22:27:00 +00003500 }
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregore922c772009-08-04 22:27:00 +00003502 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003503 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003504}
3505
Douglas Gregorfe921a72010-12-20 23:36:19 +00003506/// \brief Iterator adaptor that invents template argument location information
3507/// for each of the template arguments in its underlying iterator.
3508template<typename Derived, typename InputIterator>
3509class TemplateArgumentLocInventIterator {
3510 TreeTransform<Derived> &Self;
3511 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003512
Douglas Gregorfe921a72010-12-20 23:36:19 +00003513public:
3514 typedef TemplateArgumentLoc value_type;
3515 typedef TemplateArgumentLoc reference;
3516 typedef typename std::iterator_traits<InputIterator>::difference_type
3517 difference_type;
3518 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregorfe921a72010-12-20 23:36:19 +00003520 class pointer {
3521 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003522
Douglas Gregorfe921a72010-12-20 23:36:19 +00003523 public:
3524 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregorfe921a72010-12-20 23:36:19 +00003526 const TemplateArgumentLoc *operator->() const { return &Arg; }
3527 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003528
Douglas Gregorfe921a72010-12-20 23:36:19 +00003529 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003530
Douglas Gregorfe921a72010-12-20 23:36:19 +00003531 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3532 InputIterator Iter)
3533 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregorfe921a72010-12-20 23:36:19 +00003535 TemplateArgumentLocInventIterator &operator++() {
3536 ++Iter;
3537 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregorfe921a72010-12-20 23:36:19 +00003540 TemplateArgumentLocInventIterator operator++(int) {
3541 TemplateArgumentLocInventIterator Old(*this);
3542 ++(*this);
3543 return Old;
3544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregorfe921a72010-12-20 23:36:19 +00003546 reference operator*() const {
3547 TemplateArgumentLoc Result;
3548 Self.InventTemplateArgumentLoc(*Iter, Result);
3549 return Result;
3550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregorfe921a72010-12-20 23:36:19 +00003552 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregorfe921a72010-12-20 23:36:19 +00003554 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3555 const TemplateArgumentLocInventIterator &Y) {
3556 return X.Iter == Y.Iter;
3557 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003558
Douglas Gregorfe921a72010-12-20 23:36:19 +00003559 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3560 const TemplateArgumentLocInventIterator &Y) {
3561 return X.Iter != Y.Iter;
3562 }
3563};
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Douglas Gregor42cafa82010-12-20 17:42:22 +00003565template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003566template<typename InputIterator>
3567bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3568 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003569 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003570 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003571 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003572 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003574 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3575 // Unpack argument packs, which we translate them into separate
3576 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003577 // FIXME: We could do much better if we could guarantee that the
3578 // TemplateArgumentLocInfo for the pack expansion would be usable for
3579 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003580 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003581 TemplateArgument::pack_iterator>
3582 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003583 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003584 In.getArgument().pack_begin()),
3585 PackLocIterator(*this,
3586 In.getArgument().pack_end()),
3587 Outputs))
3588 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003590 continue;
3591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003593 if (In.getArgument().isPackExpansion()) {
3594 // We have a pack expansion, for which we will be substituting into
3595 // the pattern.
3596 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003597 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003598 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003599 = getSema().getTemplateArgumentPackExpansionPattern(
3600 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003601
Chris Lattner01cf8db2011-07-20 06:58:45 +00003602 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003603 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3604 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003606 // Determine whether the set of unexpanded parameter packs can and should
3607 // be expanded.
3608 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003609 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003610 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003611 if (getDerived().TryExpandParameterPacks(Ellipsis,
3612 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003613 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003614 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003615 RetainExpansion,
3616 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003617 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003619 if (!Expand) {
3620 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003621 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003622 // expansion.
3623 TemplateArgumentLoc OutPattern;
3624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3625 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3626 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003628 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3629 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003630 if (Out.getArgument().isNull())
3631 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003632
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003633 Outputs.addArgument(Out);
3634 continue;
3635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003636
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003637 // The transform has determined that we should perform an elementwise
3638 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003639 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003640 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3641
3642 if (getDerived().TransformTemplateArgument(Pattern, Out))
3643 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003644
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003645 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003646 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3647 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003648 if (Out.getArgument().isNull())
3649 return true;
3650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003651
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003652 Outputs.addArgument(Out);
3653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
Douglas Gregor48d24112011-01-10 20:53:55 +00003655 // If we're supposed to retain a pack expansion, do so by temporarily
3656 // forgetting the partially-substituted parameter pack.
3657 if (RetainExpansion) {
3658 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
Douglas Gregor48d24112011-01-10 20:53:55 +00003660 if (getDerived().TransformTemplateArgument(Pattern, Out))
3661 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003662
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003663 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3664 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003665 if (Out.getArgument().isNull())
3666 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Douglas Gregor48d24112011-01-10 20:53:55 +00003668 Outputs.addArgument(Out);
3669 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003670
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003671 continue;
3672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003673
3674 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003675 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003676 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
Douglas Gregor42cafa82010-12-20 17:42:22 +00003678 Outputs.addArgument(Out);
3679 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003680
Douglas Gregor42cafa82010-12-20 17:42:22 +00003681 return false;
3682
3683}
3684
Douglas Gregord6ff3322009-08-04 16:50:30 +00003685//===----------------------------------------------------------------------===//
3686// Type transformation
3687//===----------------------------------------------------------------------===//
3688
3689template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003690QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003691 if (getDerived().AlreadyTransformed(T))
3692 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003693
John McCall550e0c22009-10-21 00:40:46 +00003694 // Temporary workaround. All of these transformations should
3695 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003696 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3697 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
John McCall31f82722010-11-12 08:19:04 +00003699 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003700
John McCall550e0c22009-10-21 00:40:46 +00003701 if (!NewDI)
3702 return QualType();
3703
3704 return NewDI->getType();
3705}
3706
3707template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003708TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003709 // Refine the base location to the type's location.
3710 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3711 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003712 if (getDerived().AlreadyTransformed(DI->getType()))
3713 return DI;
3714
3715 TypeLocBuilder TLB;
3716
3717 TypeLoc TL = DI->getTypeLoc();
3718 TLB.reserve(TL.getFullDataSize());
3719
John McCall31f82722010-11-12 08:19:04 +00003720 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003721 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003722 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003723
John McCallbcd03502009-12-07 02:54:59 +00003724 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003725}
3726
3727template<typename Derived>
3728QualType
John McCall31f82722010-11-12 08:19:04 +00003729TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003730 switch (T.getTypeLocClass()) {
3731#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003732#define TYPELOC(CLASS, PARENT) \
3733 case TypeLoc::CLASS: \
3734 return getDerived().Transform##CLASS##Type(TLB, \
3735 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003736#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003737 }
Mike Stump11289f42009-09-09 15:08:12 +00003738
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003739 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003740}
3741
3742/// FIXME: By default, this routine adds type qualifiers only to types
3743/// that can have qualifiers, and silently suppresses those qualifiers
3744/// that are not permitted (e.g., qualifiers on reference or function
3745/// types). This is the right thing for template instantiation, but
3746/// probably not for other clients.
3747template<typename Derived>
3748QualType
3749TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003750 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003751 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003752
John McCall31f82722010-11-12 08:19:04 +00003753 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003754 if (Result.isNull())
3755 return QualType();
3756
3757 // Silently suppress qualifiers if the result type can't be qualified.
3758 // FIXME: this is the right thing for template instantiation, but
3759 // probably not for other clients.
3760 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003761 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003762
John McCall31168b02011-06-15 23:02:42 +00003763 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003764 // resulting type.
3765 if (Quals.hasObjCLifetime()) {
3766 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3767 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003768 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003769 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003770 // A lifetime qualifier applied to a substituted template parameter
3771 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003772 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003773 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003774 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3775 QualType Replacement = SubstTypeParam->getReplacementType();
3776 Qualifiers Qs = Replacement.getQualifiers();
3777 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003778 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003779 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3780 Qs);
3781 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003782 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003783 Replacement);
3784 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003785 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3786 // 'auto' types behave the same way as template parameters.
3787 QualType Deduced = AutoTy->getDeducedType();
3788 Qualifiers Qs = Deduced.getQualifiers();
3789 Qs.removeObjCLifetime();
3790 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3791 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003792 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3793 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003794 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003795 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003796 // Otherwise, complain about the addition of a qualifier to an
3797 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003798 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003799 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003800 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003801
Douglas Gregore46db902011-06-17 22:11:49 +00003802 Quals.removeObjCLifetime();
3803 }
3804 }
3805 }
John McCallcb0f89a2010-06-05 06:41:15 +00003806 if (!Quals.empty()) {
3807 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003808 // BuildQualifiedType might not add qualifiers if they are invalid.
3809 if (Result.hasLocalQualifiers())
3810 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003811 // No location information to preserve.
3812 }
John McCall550e0c22009-10-21 00:40:46 +00003813
3814 return Result;
3815}
3816
Douglas Gregor14454802011-02-25 02:25:35 +00003817template<typename Derived>
3818TypeLoc
3819TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3820 QualType ObjectType,
3821 NamedDecl *UnqualLookup,
3822 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003823 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003824 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003826 TypeSourceInfo *TSI =
3827 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3828 if (TSI)
3829 return TSI->getTypeLoc();
3830 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003831}
3832
Douglas Gregor579c15f2011-03-02 18:32:08 +00003833template<typename Derived>
3834TypeSourceInfo *
3835TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3836 QualType ObjectType,
3837 NamedDecl *UnqualLookup,
3838 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003839 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003840 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003842 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3843 UnqualLookup, SS);
3844}
3845
3846template <typename Derived>
3847TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3848 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3849 CXXScopeSpec &SS) {
3850 QualType T = TL.getType();
3851 assert(!getDerived().AlreadyTransformed(T));
3852
Douglas Gregor579c15f2011-03-02 18:32:08 +00003853 TypeLocBuilder TLB;
3854 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003855
Douglas Gregor579c15f2011-03-02 18:32:08 +00003856 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003857 TemplateSpecializationTypeLoc SpecTL =
3858 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor579c15f2011-03-02 18:32:08 +00003860 TemplateName Template
3861 = getDerived().TransformTemplateName(SS,
3862 SpecTL.getTypePtr()->getTemplateName(),
3863 SpecTL.getTemplateNameLoc(),
3864 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003865 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003866 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
3868 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003869 Template);
3870 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003871 DependentTemplateSpecializationTypeLoc SpecTL =
3872 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003873
Douglas Gregor579c15f2011-03-02 18:32:08 +00003874 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003875 = getDerived().RebuildTemplateName(SS,
3876 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003877 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003878 ObjectType, UnqualLookup);
3879 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003880 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
3882 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003883 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003884 Template,
3885 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003886 } else {
3887 // Nothing special needs to be done for these.
3888 Result = getDerived().TransformType(TLB, TL);
3889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003890
3891 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003892 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003893
Douglas Gregor579c15f2011-03-02 18:32:08 +00003894 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3895}
3896
John McCall550e0c22009-10-21 00:40:46 +00003897template <class TyLoc> static inline
3898QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3899 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3900 NewT.setNameLoc(T.getNameLoc());
3901 return T.getType();
3902}
3903
John McCall550e0c22009-10-21 00:40:46 +00003904template<typename Derived>
3905QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003906 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003907 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3908 NewT.setBuiltinLoc(T.getBuiltinLoc());
3909 if (T.needsExtraLocalData())
3910 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3911 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912}
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003915QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003916 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003917 // FIXME: recurse?
3918 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003919}
Mike Stump11289f42009-09-09 15:08:12 +00003920
Reid Kleckner0503a872013-12-05 01:23:43 +00003921template <typename Derived>
3922QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3923 AdjustedTypeLoc TL) {
3924 // Adjustments applied during transformation are handled elsewhere.
3925 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3926}
3927
Douglas Gregord6ff3322009-08-04 16:50:30 +00003928template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003929QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3930 DecayedTypeLoc TL) {
3931 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3932 if (OriginalType.isNull())
3933 return QualType();
3934
3935 QualType Result = TL.getType();
3936 if (getDerived().AlwaysRebuild() ||
3937 OriginalType != TL.getOriginalLoc().getType())
3938 Result = SemaRef.Context.getDecayedType(OriginalType);
3939 TLB.push<DecayedTypeLoc>(Result);
3940 // Nothing to set for DecayedTypeLoc.
3941 return Result;
3942}
3943
3944template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003945QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003946 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003947 QualType PointeeType
3948 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003949 if (PointeeType.isNull())
3950 return QualType();
3951
3952 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003953 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003954 // A dependent pointer type 'T *' has is being transformed such
3955 // that an Objective-C class type is being replaced for 'T'. The
3956 // resulting pointer type is an ObjCObjectPointerType, not a
3957 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003958 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003959
John McCall8b07ec22010-05-15 11:32:37 +00003960 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3961 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003962 return Result;
3963 }
John McCall31f82722010-11-12 08:19:04 +00003964
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003965 if (getDerived().AlwaysRebuild() ||
3966 PointeeType != TL.getPointeeLoc().getType()) {
3967 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3968 if (Result.isNull())
3969 return QualType();
3970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003971
John McCall31168b02011-06-15 23:02:42 +00003972 // Objective-C ARC can add lifetime qualifiers to the type that we're
3973 // pointing to.
3974 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003975
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003976 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3977 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003978 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003979}
Mike Stump11289f42009-09-09 15:08:12 +00003980
3981template<typename Derived>
3982QualType
John McCall550e0c22009-10-21 00:40:46 +00003983TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003984 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003985 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003986 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3987 if (PointeeType.isNull())
3988 return QualType();
3989
3990 QualType Result = TL.getType();
3991 if (getDerived().AlwaysRebuild() ||
3992 PointeeType != TL.getPointeeLoc().getType()) {
3993 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003994 TL.getSigilLoc());
3995 if (Result.isNull())
3996 return QualType();
3997 }
3998
Douglas Gregor049211a2010-04-22 16:50:51 +00003999 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004000 NewT.setSigilLoc(TL.getSigilLoc());
4001 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004002}
4003
John McCall70dd5f62009-10-30 00:06:24 +00004004/// Transforms a reference type. Note that somewhat paradoxically we
4005/// don't care whether the type itself is an l-value type or an r-value
4006/// type; we only care if the type was *written* as an l-value type
4007/// or an r-value type.
4008template<typename Derived>
4009QualType
4010TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004011 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004012 const ReferenceType *T = TL.getTypePtr();
4013
4014 // Note that this works with the pointee-as-written.
4015 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4016 if (PointeeType.isNull())
4017 return QualType();
4018
4019 QualType Result = TL.getType();
4020 if (getDerived().AlwaysRebuild() ||
4021 PointeeType != T->getPointeeTypeAsWritten()) {
4022 Result = getDerived().RebuildReferenceType(PointeeType,
4023 T->isSpelledAsLValue(),
4024 TL.getSigilLoc());
4025 if (Result.isNull())
4026 return QualType();
4027 }
4028
John McCall31168b02011-06-15 23:02:42 +00004029 // Objective-C ARC can add lifetime qualifiers to the type that we're
4030 // referring to.
4031 TLB.TypeWasModifiedSafely(
4032 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4033
John McCall70dd5f62009-10-30 00:06:24 +00004034 // r-value references can be rebuilt as l-value references.
4035 ReferenceTypeLoc NewTL;
4036 if (isa<LValueReferenceType>(Result))
4037 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4038 else
4039 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4040 NewTL.setSigilLoc(TL.getSigilLoc());
4041
4042 return Result;
4043}
4044
Mike Stump11289f42009-09-09 15:08:12 +00004045template<typename Derived>
4046QualType
John McCall550e0c22009-10-21 00:40:46 +00004047TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004048 LValueReferenceTypeLoc TL) {
4049 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050}
4051
Mike Stump11289f42009-09-09 15:08:12 +00004052template<typename Derived>
4053QualType
John McCall550e0c22009-10-21 00:40:46 +00004054TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004055 RValueReferenceTypeLoc TL) {
4056 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004057}
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregord6ff3322009-08-04 16:50:30 +00004059template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004060QualType
John McCall550e0c22009-10-21 00:40:46 +00004061TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004062 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004063 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064 if (PointeeType.isNull())
4065 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004066
Abramo Bagnara509357842011-03-05 14:42:21 +00004067 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004068 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004069 if (OldClsTInfo) {
4070 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4071 if (!NewClsTInfo)
4072 return QualType();
4073 }
4074
4075 const MemberPointerType *T = TL.getTypePtr();
4076 QualType OldClsType = QualType(T->getClass(), 0);
4077 QualType NewClsType;
4078 if (NewClsTInfo)
4079 NewClsType = NewClsTInfo->getType();
4080 else {
4081 NewClsType = getDerived().TransformType(OldClsType);
4082 if (NewClsType.isNull())
4083 return QualType();
4084 }
Mike Stump11289f42009-09-09 15:08:12 +00004085
John McCall550e0c22009-10-21 00:40:46 +00004086 QualType Result = TL.getType();
4087 if (getDerived().AlwaysRebuild() ||
4088 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004089 NewClsType != OldClsType) {
4090 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004091 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004092 if (Result.isNull())
4093 return QualType();
4094 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095
Reid Kleckner0503a872013-12-05 01:23:43 +00004096 // If we had to adjust the pointee type when building a member pointer, make
4097 // sure to push TypeLoc info for it.
4098 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4099 if (MPT && PointeeType != MPT->getPointeeType()) {
4100 assert(isa<AdjustedType>(MPT->getPointeeType()));
4101 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4102 }
4103
John McCall550e0c22009-10-21 00:40:46 +00004104 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4105 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004106 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004107
4108 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004109}
4110
Mike Stump11289f42009-09-09 15:08:12 +00004111template<typename Derived>
4112QualType
John McCall550e0c22009-10-21 00:40:46 +00004113TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004114 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004115 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004116 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004117 if (ElementType.isNull())
4118 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004119
John McCall550e0c22009-10-21 00:40:46 +00004120 QualType Result = TL.getType();
4121 if (getDerived().AlwaysRebuild() ||
4122 ElementType != T->getElementType()) {
4123 Result = getDerived().RebuildConstantArrayType(ElementType,
4124 T->getSizeModifier(),
4125 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004126 T->getIndexTypeCVRQualifiers(),
4127 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004128 if (Result.isNull())
4129 return QualType();
4130 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004131
4132 // We might have either a ConstantArrayType or a VariableArrayType now:
4133 // a ConstantArrayType is allowed to have an element type which is a
4134 // VariableArrayType if the type is dependent. Fortunately, all array
4135 // types have the same location layout.
4136 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004137 NewTL.setLBracketLoc(TL.getLBracketLoc());
4138 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004139
John McCall550e0c22009-10-21 00:40:46 +00004140 Expr *Size = TL.getSizeExpr();
4141 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004142 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4143 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004144 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4145 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004146 }
4147 NewTL.setSizeExpr(Size);
4148
4149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150}
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004153QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004154 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004155 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004156 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004157 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004158 if (ElementType.isNull())
4159 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004160
John McCall550e0c22009-10-21 00:40:46 +00004161 QualType Result = TL.getType();
4162 if (getDerived().AlwaysRebuild() ||
4163 ElementType != T->getElementType()) {
4164 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004165 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004166 T->getIndexTypeCVRQualifiers(),
4167 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004168 if (Result.isNull())
4169 return QualType();
4170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004171
John McCall550e0c22009-10-21 00:40:46 +00004172 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4173 NewTL.setLBracketLoc(TL.getLBracketLoc());
4174 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004175 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004176
4177 return Result;
4178}
4179
4180template<typename Derived>
4181QualType
4182TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004183 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004184 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004185 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4186 if (ElementType.isNull())
4187 return QualType();
4188
John McCalldadc5752010-08-24 06:29:42 +00004189 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004190 = getDerived().TransformExpr(T->getSizeExpr());
4191 if (SizeResult.isInvalid())
4192 return QualType();
4193
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004194 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004195
4196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 ElementType != T->getElementType() ||
4199 Size != T->getSizeExpr()) {
4200 Result = getDerived().RebuildVariableArrayType(ElementType,
4201 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004202 Size,
John McCall550e0c22009-10-21 00:40:46 +00004203 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004204 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004205 if (Result.isNull())
4206 return QualType();
4207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004208
Serge Pavlov774c6d02014-02-06 03:49:11 +00004209 // We might have constant size array now, but fortunately it has the same
4210 // location layout.
4211 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004212 NewTL.setLBracketLoc(TL.getLBracketLoc());
4213 NewTL.setRBracketLoc(TL.getRBracketLoc());
4214 NewTL.setSizeExpr(Size);
4215
4216 return Result;
4217}
4218
4219template<typename Derived>
4220QualType
4221TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004222 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004223 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004224 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4225 if (ElementType.isNull())
4226 return QualType();
4227
Richard Smith764d2fe2011-12-20 02:08:33 +00004228 // Array bounds are constant expressions.
4229 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4230 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004231
John McCall33ddac02011-01-19 10:06:00 +00004232 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4233 Expr *origSize = TL.getSizeExpr();
4234 if (!origSize) origSize = T->getSizeExpr();
4235
4236 ExprResult sizeResult
4237 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004238 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004239 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004240 return QualType();
4241
John McCall33ddac02011-01-19 10:06:00 +00004242 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004243
4244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() ||
4246 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004247 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004248 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4249 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004250 size,
John McCall550e0c22009-10-21 00:40:46 +00004251 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004252 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004253 if (Result.isNull())
4254 return QualType();
4255 }
John McCall550e0c22009-10-21 00:40:46 +00004256
4257 // We might have any sort of array type now, but fortunately they
4258 // all have the same location layout.
4259 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4260 NewTL.setLBracketLoc(TL.getLBracketLoc());
4261 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004262 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004263
4264 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265}
Mike Stump11289f42009-09-09 15:08:12 +00004266
4267template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004268QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004269 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004270 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004271 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004272
4273 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004274 QualType ElementType = getDerived().TransformType(T->getElementType());
4275 if (ElementType.isNull())
4276 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004277
Richard Smith764d2fe2011-12-20 02:08:33 +00004278 // Vector sizes are constant expressions.
4279 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4280 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004281
John McCalldadc5752010-08-24 06:29:42 +00004282 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004283 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004284 if (Size.isInvalid())
4285 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004286
John McCall550e0c22009-10-21 00:40:46 +00004287 QualType Result = TL.getType();
4288 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004289 ElementType != T->getElementType() ||
4290 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004291 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004292 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004293 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004294 if (Result.isNull())
4295 return QualType();
4296 }
John McCall550e0c22009-10-21 00:40:46 +00004297
4298 // Result might be dependent or not.
4299 if (isa<DependentSizedExtVectorType>(Result)) {
4300 DependentSizedExtVectorTypeLoc NewTL
4301 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4302 NewTL.setNameLoc(TL.getNameLoc());
4303 } else {
4304 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4305 NewTL.setNameLoc(TL.getNameLoc());
4306 }
4307
4308 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
4311template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004312QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004313 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004314 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004315 QualType ElementType = getDerived().TransformType(T->getElementType());
4316 if (ElementType.isNull())
4317 return QualType();
4318
John McCall550e0c22009-10-21 00:40:46 +00004319 QualType Result = TL.getType();
4320 if (getDerived().AlwaysRebuild() ||
4321 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004322 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004323 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004324 if (Result.isNull())
4325 return QualType();
4326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004327
John McCall550e0c22009-10-21 00:40:46 +00004328 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4329 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004330
John McCall550e0c22009-10-21 00:40:46 +00004331 return Result;
4332}
4333
4334template<typename Derived>
4335QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004336 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004337 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004338 QualType ElementType = getDerived().TransformType(T->getElementType());
4339 if (ElementType.isNull())
4340 return QualType();
4341
4342 QualType Result = TL.getType();
4343 if (getDerived().AlwaysRebuild() ||
4344 ElementType != T->getElementType()) {
4345 Result = getDerived().RebuildExtVectorType(ElementType,
4346 T->getNumElements(),
4347 /*FIXME*/ SourceLocation());
4348 if (Result.isNull())
4349 return QualType();
4350 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004351
John McCall550e0c22009-10-21 00:40:46 +00004352 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4353 NewTL.setNameLoc(TL.getNameLoc());
4354
4355 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004356}
Mike Stump11289f42009-09-09 15:08:12 +00004357
David Blaikie05785d12013-02-20 22:23:23 +00004358template <typename Derived>
4359ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4360 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4361 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004362 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004363 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004364
Douglas Gregor715e4612011-01-14 22:40:04 +00004365 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004366 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004367 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004368 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004369 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004370
Douglas Gregor715e4612011-01-14 22:40:04 +00004371 TypeLocBuilder TLB;
4372 TypeLoc NewTL = OldDI->getTypeLoc();
4373 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004374
4375 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004376 OldExpansionTL.getPatternLoc());
4377 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004378 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004379
4380 Result = RebuildPackExpansionType(Result,
4381 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004382 OldExpansionTL.getEllipsisLoc(),
4383 NumExpansions);
4384 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004385 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004386
Douglas Gregor715e4612011-01-14 22:40:04 +00004387 PackExpansionTypeLoc NewExpansionTL
4388 = TLB.push<PackExpansionTypeLoc>(Result);
4389 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4390 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4391 } else
4392 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004393 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004394 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004395
John McCall8fb0d9d2011-05-01 22:35:37 +00004396 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004397 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004398
4399 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4400 OldParm->getDeclContext(),
4401 OldParm->getInnerLocStart(),
4402 OldParm->getLocation(),
4403 OldParm->getIdentifier(),
4404 NewDI->getType(),
4405 NewDI,
4406 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004407 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004408 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4409 OldParm->getFunctionScopeIndex() + indexAdjustment);
4410 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004411}
4412
4413template<typename Derived>
4414bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004415 TransformFunctionTypeParams(SourceLocation Loc,
4416 ParmVarDecl **Params, unsigned NumParams,
4417 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004418 SmallVectorImpl<QualType> &OutParamTypes,
4419 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004420 int indexAdjustment = 0;
4421
Douglas Gregordd472162011-01-07 00:20:55 +00004422 for (unsigned i = 0; i != NumParams; ++i) {
4423 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004424 assert(OldParm->getFunctionScopeIndex() == i);
4425
David Blaikie05785d12013-02-20 22:23:23 +00004426 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004427 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004428 if (OldParm->isParameterPack()) {
4429 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004430 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004431
Douglas Gregor5499af42011-01-05 23:12:31 +00004432 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004433 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004434 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004435 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4436 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004437 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4438
Douglas Gregor5499af42011-01-05 23:12:31 +00004439 // Determine whether we should expand the parameter packs.
4440 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004441 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004442 Optional<unsigned> OrigNumExpansions =
4443 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004444 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004445 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4446 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004447 Unexpanded,
4448 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004449 RetainExpansion,
4450 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004451 return true;
4452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004453
Douglas Gregor5499af42011-01-05 23:12:31 +00004454 if (ShouldExpand) {
4455 // Expand the function parameter pack into multiple, separate
4456 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004457 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004458 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004459 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004460 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004461 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004462 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004463 OrigNumExpansions,
4464 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004465 if (!NewParm)
4466 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004467
Douglas Gregordd472162011-01-07 00:20:55 +00004468 OutParamTypes.push_back(NewParm->getType());
4469 if (PVars)
4470 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004471 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004472
4473 // If we're supposed to retain a pack expansion, do so by temporarily
4474 // forgetting the partially-substituted parameter pack.
4475 if (RetainExpansion) {
4476 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004477 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004478 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004479 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004480 OrigNumExpansions,
4481 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004482 if (!NewParm)
4483 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004484
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004485 OutParamTypes.push_back(NewParm->getType());
4486 if (PVars)
4487 PVars->push_back(NewParm);
4488 }
4489
John McCall8fb0d9d2011-05-01 22:35:37 +00004490 // The next parameter should have the same adjustment as the
4491 // last thing we pushed, but we post-incremented indexAdjustment
4492 // on every push. Also, if we push nothing, the adjustment should
4493 // go down by one.
4494 indexAdjustment--;
4495
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 // We're done with the pack expansion.
4497 continue;
4498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004499
4500 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004501 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004502 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4503 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004504 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004505 NumExpansions,
4506 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004507 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004508 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004509 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004510 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004511
John McCall58f10c32010-03-11 09:03:00 +00004512 if (!NewParm)
4513 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004514
Douglas Gregordd472162011-01-07 00:20:55 +00004515 OutParamTypes.push_back(NewParm->getType());
4516 if (PVars)
4517 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004518 continue;
4519 }
John McCall58f10c32010-03-11 09:03:00 +00004520
4521 // Deal with the possibility that we don't have a parameter
4522 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004523 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004524 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004525 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004526 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004527 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004528 = dyn_cast<PackExpansionType>(OldType)) {
4529 // We have a function parameter pack that may need to be expanded.
4530 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004531 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004532 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004533
Douglas Gregor5499af42011-01-05 23:12:31 +00004534 // Determine whether we should expand the parameter packs.
4535 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004536 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004537 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004538 Unexpanded,
4539 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004540 RetainExpansion,
4541 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004542 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004544
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004546 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004547 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004548 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004549 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4550 QualType NewType = getDerived().TransformType(Pattern);
4551 if (NewType.isNull())
4552 return true;
John McCall58f10c32010-03-11 09:03:00 +00004553
Douglas Gregordd472162011-01-07 00:20:55 +00004554 OutParamTypes.push_back(NewType);
4555 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004556 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004557 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004558
Douglas Gregor5499af42011-01-05 23:12:31 +00004559 // We're done with the pack expansion.
4560 continue;
4561 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004562
Douglas Gregor48d24112011-01-10 20:53:55 +00004563 // If we're supposed to retain a pack expansion, do so by temporarily
4564 // forgetting the partially-substituted parameter pack.
4565 if (RetainExpansion) {
4566 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4567 QualType NewType = getDerived().TransformType(Pattern);
4568 if (NewType.isNull())
4569 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004570
Douglas Gregor48d24112011-01-10 20:53:55 +00004571 OutParamTypes.push_back(NewType);
4572 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004573 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004574 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004575
Chad Rosier1dcde962012-08-08 18:46:20 +00004576 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004577 // expansion.
4578 OldType = Expansion->getPattern();
4579 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004580 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4581 NewType = getDerived().TransformType(OldType);
4582 } else {
4583 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004585
Douglas Gregor5499af42011-01-05 23:12:31 +00004586 if (NewType.isNull())
4587 return true;
4588
4589 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004590 NewType = getSema().Context.getPackExpansionType(NewType,
4591 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004592
Douglas Gregordd472162011-01-07 00:20:55 +00004593 OutParamTypes.push_back(NewType);
4594 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004595 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004596 }
4597
John McCall8fb0d9d2011-05-01 22:35:37 +00004598#ifndef NDEBUG
4599 if (PVars) {
4600 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4601 if (ParmVarDecl *parm = (*PVars)[i])
4602 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004603 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004604#endif
4605
4606 return false;
4607}
John McCall58f10c32010-03-11 09:03:00 +00004608
4609template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004610QualType
John McCall550e0c22009-10-21 00:40:46 +00004611TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004612 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004613 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004614 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004615 return getDerived().TransformFunctionProtoType(
4616 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004617 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4618 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4619 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004620 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004621}
4622
Richard Smith2e321552014-11-12 02:00:47 +00004623template<typename Derived> template<typename Fn>
4624QualType TreeTransform<Derived>::TransformFunctionProtoType(
4625 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4626 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004627 // Transform the parameters and return type.
4628 //
Richard Smithf623c962012-04-17 00:58:00 +00004629 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004630 // When the function has a trailing return type, we instantiate the
4631 // parameters before the return type, since the return type can then refer
4632 // to the parameters themselves (via decltype, sizeof, etc.).
4633 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004634 SmallVector<QualType, 4> ParamTypes;
4635 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004636 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004637
Douglas Gregor7fb25412010-10-01 18:44:50 +00004638 QualType ResultType;
4639
Richard Smith1226c602012-08-14 22:51:13 +00004640 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004641 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004642 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004643 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004644 return QualType();
4645
Douglas Gregor3024f072012-04-16 07:05:22 +00004646 {
4647 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004648 // If a declaration declares a member function or member function
4649 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004650 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004651 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004652 // declarator.
4653 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004654
Alp Toker42a16a62014-01-25 23:51:36 +00004655 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004656 if (ResultType.isNull())
4657 return QualType();
4658 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004659 }
4660 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004661 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004662 if (ResultType.isNull())
4663 return QualType();
4664
Alp Toker9cacbab2014-01-20 20:26:09 +00004665 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004666 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004667 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004668 return QualType();
4669 }
4670
Richard Smith2e321552014-11-12 02:00:47 +00004671 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4672
4673 bool EPIChanged = false;
4674 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4675 return QualType();
4676
4677 // FIXME: Need to transform ConsumedParameters for variadic template
4678 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004679
John McCall550e0c22009-10-21 00:40:46 +00004680 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004681 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004682 T->getNumParams() != ParamTypes.size() ||
4683 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004684 ParamTypes.begin()) || EPIChanged) {
4685 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004686 if (Result.isNull())
4687 return QualType();
4688 }
Mike Stump11289f42009-09-09 15:08:12 +00004689
John McCall550e0c22009-10-21 00:40:46 +00004690 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004691 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004692 NewTL.setLParenLoc(TL.getLParenLoc());
4693 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004694 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004695 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4696 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004697
4698 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699}
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregord6ff3322009-08-04 16:50:30 +00004701template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004702bool TreeTransform<Derived>::TransformExceptionSpec(
4703 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4704 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4705 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4706
4707 // Instantiate a dynamic noexcept expression, if any.
4708 if (ESI.Type == EST_ComputedNoexcept) {
4709 EnterExpressionEvaluationContext Unevaluated(getSema(),
4710 Sema::ConstantEvaluated);
4711 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4712 if (NoexceptExpr.isInvalid())
4713 return true;
4714
4715 NoexceptExpr = getSema().CheckBooleanCondition(
4716 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4717 if (NoexceptExpr.isInvalid())
4718 return true;
4719
4720 if (!NoexceptExpr.get()->isValueDependent()) {
4721 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4722 NoexceptExpr.get(), nullptr,
4723 diag::err_noexcept_needs_constant_expression,
4724 /*AllowFold*/false);
4725 if (NoexceptExpr.isInvalid())
4726 return true;
4727 }
4728
4729 if (ESI.NoexceptExpr != NoexceptExpr.get())
4730 Changed = true;
4731 ESI.NoexceptExpr = NoexceptExpr.get();
4732 }
4733
4734 if (ESI.Type != EST_Dynamic)
4735 return false;
4736
4737 // Instantiate a dynamic exception specification's type.
4738 for (QualType T : ESI.Exceptions) {
4739 if (const PackExpansionType *PackExpansion =
4740 T->getAs<PackExpansionType>()) {
4741 Changed = true;
4742
4743 // We have a pack expansion. Instantiate it.
4744 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4745 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4746 Unexpanded);
4747 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4748
4749 // Determine whether the set of unexpanded parameter packs can and
4750 // should
4751 // be expanded.
4752 bool Expand = false;
4753 bool RetainExpansion = false;
4754 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4755 // FIXME: Track the location of the ellipsis (and track source location
4756 // information for the types in the exception specification in general).
4757 if (getDerived().TryExpandParameterPacks(
4758 Loc, SourceRange(), Unexpanded, Expand,
4759 RetainExpansion, NumExpansions))
4760 return true;
4761
4762 if (!Expand) {
4763 // We can't expand this pack expansion into separate arguments yet;
4764 // just substitute into the pattern and create a new pack expansion
4765 // type.
4766 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4767 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4768 if (U.isNull())
4769 return true;
4770
4771 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4772 Exceptions.push_back(U);
4773 continue;
4774 }
4775
4776 // Substitute into the pack expansion pattern for each slice of the
4777 // pack.
4778 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4779 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4780
4781 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4782 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4783 return true;
4784
4785 Exceptions.push_back(U);
4786 }
4787 } else {
4788 QualType U = getDerived().TransformType(T);
4789 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4790 return true;
4791 if (T != U)
4792 Changed = true;
4793
4794 Exceptions.push_back(U);
4795 }
4796 }
4797
4798 ESI.Exceptions = Exceptions;
4799 return false;
4800}
4801
4802template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004803QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004804 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004805 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004806 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004807 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004808 if (ResultType.isNull())
4809 return QualType();
4810
4811 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004812 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004813 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4814
4815 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004816 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004817 NewTL.setLParenLoc(TL.getLParenLoc());
4818 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004819 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004820
4821 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004822}
Mike Stump11289f42009-09-09 15:08:12 +00004823
John McCallb96ec562009-12-04 22:46:56 +00004824template<typename Derived> QualType
4825TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004826 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004827 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004828 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004829 if (!D)
4830 return QualType();
4831
4832 QualType Result = TL.getType();
4833 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4834 Result = getDerived().RebuildUnresolvedUsingType(D);
4835 if (Result.isNull())
4836 return QualType();
4837 }
4838
4839 // We might get an arbitrary type spec type back. We should at
4840 // least always get a type spec type, though.
4841 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4842 NewTL.setNameLoc(TL.getNameLoc());
4843
4844 return Result;
4845}
4846
Douglas Gregord6ff3322009-08-04 16:50:30 +00004847template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004848QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004849 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004850 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004851 TypedefNameDecl *Typedef
4852 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4853 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004854 if (!Typedef)
4855 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004856
John McCall550e0c22009-10-21 00:40:46 +00004857 QualType Result = TL.getType();
4858 if (getDerived().AlwaysRebuild() ||
4859 Typedef != T->getDecl()) {
4860 Result = getDerived().RebuildTypedefType(Typedef);
4861 if (Result.isNull())
4862 return QualType();
4863 }
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCall550e0c22009-10-21 00:40:46 +00004865 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4866 NewTL.setNameLoc(TL.getNameLoc());
4867
4868 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004869}
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregord6ff3322009-08-04 16:50:30 +00004871template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004872QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004873 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004874 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004875 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4876 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004877
John McCalldadc5752010-08-24 06:29:42 +00004878 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004879 if (E.isInvalid())
4880 return QualType();
4881
Eli Friedmane4f22df2012-02-29 04:03:55 +00004882 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4883 if (E.isInvalid())
4884 return QualType();
4885
John McCall550e0c22009-10-21 00:40:46 +00004886 QualType Result = TL.getType();
4887 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004888 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004889 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004890 if (Result.isNull())
4891 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004893 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004894
John McCall550e0c22009-10-21 00:40:46 +00004895 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004896 NewTL.setTypeofLoc(TL.getTypeofLoc());
4897 NewTL.setLParenLoc(TL.getLParenLoc());
4898 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004899
4900 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004901}
Mike Stump11289f42009-09-09 15:08:12 +00004902
4903template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004904QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004905 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004906 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4907 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4908 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004909 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004910
John McCall550e0c22009-10-21 00:40:46 +00004911 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004912 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4913 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004914 if (Result.isNull())
4915 return QualType();
4916 }
Mike Stump11289f42009-09-09 15:08:12 +00004917
John McCall550e0c22009-10-21 00:40:46 +00004918 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004919 NewTL.setTypeofLoc(TL.getTypeofLoc());
4920 NewTL.setLParenLoc(TL.getLParenLoc());
4921 NewTL.setRParenLoc(TL.getRParenLoc());
4922 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004923
4924 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925}
Mike Stump11289f42009-09-09 15:08:12 +00004926
4927template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004928QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004929 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004930 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004931
Douglas Gregore922c772009-08-04 22:27:00 +00004932 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004933 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4934 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004935
John McCalldadc5752010-08-24 06:29:42 +00004936 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004937 if (E.isInvalid())
4938 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004939
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004940 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004941 if (E.isInvalid())
4942 return QualType();
4943
John McCall550e0c22009-10-21 00:40:46 +00004944 QualType Result = TL.getType();
4945 if (getDerived().AlwaysRebuild() ||
4946 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004947 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004948 if (Result.isNull())
4949 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004950 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004951 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004952
John McCall550e0c22009-10-21 00:40:46 +00004953 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4954 NewTL.setNameLoc(TL.getNameLoc());
4955
4956 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004957}
4958
4959template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004960QualType TreeTransform<Derived>::TransformUnaryTransformType(
4961 TypeLocBuilder &TLB,
4962 UnaryTransformTypeLoc TL) {
4963 QualType Result = TL.getType();
4964 if (Result->isDependentType()) {
4965 const UnaryTransformType *T = TL.getTypePtr();
4966 QualType NewBase =
4967 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4968 Result = getDerived().RebuildUnaryTransformType(NewBase,
4969 T->getUTTKind(),
4970 TL.getKWLoc());
4971 if (Result.isNull())
4972 return QualType();
4973 }
4974
4975 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4976 NewTL.setKWLoc(TL.getKWLoc());
4977 NewTL.setParensRange(TL.getParensRange());
4978 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4979 return Result;
4980}
4981
4982template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004983QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4984 AutoTypeLoc TL) {
4985 const AutoType *T = TL.getTypePtr();
4986 QualType OldDeduced = T->getDeducedType();
4987 QualType NewDeduced;
4988 if (!OldDeduced.isNull()) {
4989 NewDeduced = getDerived().TransformType(OldDeduced);
4990 if (NewDeduced.isNull())
4991 return QualType();
4992 }
4993
4994 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004995 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4996 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004997 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004998 if (Result.isNull())
4999 return QualType();
5000 }
5001
5002 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5003 NewTL.setNameLoc(TL.getNameLoc());
5004
5005 return Result;
5006}
5007
5008template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005009QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005010 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005011 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005012 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005013 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5014 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005015 if (!Record)
5016 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005017
John McCall550e0c22009-10-21 00:40:46 +00005018 QualType Result = TL.getType();
5019 if (getDerived().AlwaysRebuild() ||
5020 Record != T->getDecl()) {
5021 Result = getDerived().RebuildRecordType(Record);
5022 if (Result.isNull())
5023 return QualType();
5024 }
Mike Stump11289f42009-09-09 15:08:12 +00005025
John McCall550e0c22009-10-21 00:40:46 +00005026 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5027 NewTL.setNameLoc(TL.getNameLoc());
5028
5029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005030}
Mike Stump11289f42009-09-09 15:08:12 +00005031
5032template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005033QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005034 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005035 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005036 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005037 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5038 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005039 if (!Enum)
5040 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005041
John McCall550e0c22009-10-21 00:40:46 +00005042 QualType Result = TL.getType();
5043 if (getDerived().AlwaysRebuild() ||
5044 Enum != T->getDecl()) {
5045 Result = getDerived().RebuildEnumType(Enum);
5046 if (Result.isNull())
5047 return QualType();
5048 }
Mike Stump11289f42009-09-09 15:08:12 +00005049
John McCall550e0c22009-10-21 00:40:46 +00005050 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5051 NewTL.setNameLoc(TL.getNameLoc());
5052
5053 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005054}
John McCallfcc33b02009-09-05 00:15:47 +00005055
John McCalle78aac42010-03-10 03:28:59 +00005056template<typename Derived>
5057QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5058 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005059 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005060 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5061 TL.getTypePtr()->getDecl());
5062 if (!D) return QualType();
5063
5064 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5065 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5066 return T;
5067}
5068
Douglas Gregord6ff3322009-08-04 16:50:30 +00005069template<typename Derived>
5070QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005071 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005072 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005073 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005074}
5075
Mike Stump11289f42009-09-09 15:08:12 +00005076template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005077QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005078 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005079 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005080 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005081
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005082 // Substitute into the replacement type, which itself might involve something
5083 // that needs to be transformed. This only tends to occur with default
5084 // template arguments of template template parameters.
5085 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5086 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5087 if (Replacement.isNull())
5088 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005089
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005090 // Always canonicalize the replacement type.
5091 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5092 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005093 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005094 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005095
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005096 // Propagate type-source information.
5097 SubstTemplateTypeParmTypeLoc NewTL
5098 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5099 NewTL.setNameLoc(TL.getNameLoc());
5100 return Result;
5101
John McCallcebee162009-10-18 09:09:24 +00005102}
5103
5104template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005105QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5106 TypeLocBuilder &TLB,
5107 SubstTemplateTypeParmPackTypeLoc TL) {
5108 return TransformTypeSpecType(TLB, TL);
5109}
5110
5111template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005112QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005113 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005114 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005115 const TemplateSpecializationType *T = TL.getTypePtr();
5116
Douglas Gregordf846d12011-03-02 18:46:51 +00005117 // The nested-name-specifier never matters in a TemplateSpecializationType,
5118 // because we can't have a dependent nested-name-specifier anyway.
5119 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005120 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005121 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5122 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005123 if (Template.isNull())
5124 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005125
John McCall31f82722010-11-12 08:19:04 +00005126 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5127}
5128
Eli Friedman0dfb8892011-10-06 23:00:33 +00005129template<typename Derived>
5130QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5131 AtomicTypeLoc TL) {
5132 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5133 if (ValueType.isNull())
5134 return QualType();
5135
5136 QualType Result = TL.getType();
5137 if (getDerived().AlwaysRebuild() ||
5138 ValueType != TL.getValueLoc().getType()) {
5139 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5140 if (Result.isNull())
5141 return QualType();
5142 }
5143
5144 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5145 NewTL.setKWLoc(TL.getKWLoc());
5146 NewTL.setLParenLoc(TL.getLParenLoc());
5147 NewTL.setRParenLoc(TL.getRParenLoc());
5148
5149 return Result;
5150}
5151
Chad Rosier1dcde962012-08-08 18:46:20 +00005152 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005153 /// container that provides a \c getArgLoc() member function.
5154 ///
5155 /// This iterator is intended to be used with the iterator form of
5156 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5157 template<typename ArgLocContainer>
5158 class TemplateArgumentLocContainerIterator {
5159 ArgLocContainer *Container;
5160 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005161
Douglas Gregorfe921a72010-12-20 23:36:19 +00005162 public:
5163 typedef TemplateArgumentLoc value_type;
5164 typedef TemplateArgumentLoc reference;
5165 typedef int difference_type;
5166 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005167
Douglas Gregorfe921a72010-12-20 23:36:19 +00005168 class pointer {
5169 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005170
Douglas Gregorfe921a72010-12-20 23:36:19 +00005171 public:
5172 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005173
Douglas Gregorfe921a72010-12-20 23:36:19 +00005174 const TemplateArgumentLoc *operator->() const {
5175 return &Arg;
5176 }
5177 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005178
5179
Douglas Gregorfe921a72010-12-20 23:36:19 +00005180 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005181
Douglas Gregorfe921a72010-12-20 23:36:19 +00005182 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5183 unsigned Index)
5184 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005185
Douglas Gregorfe921a72010-12-20 23:36:19 +00005186 TemplateArgumentLocContainerIterator &operator++() {
5187 ++Index;
5188 return *this;
5189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
Douglas Gregorfe921a72010-12-20 23:36:19 +00005191 TemplateArgumentLocContainerIterator operator++(int) {
5192 TemplateArgumentLocContainerIterator Old(*this);
5193 ++(*this);
5194 return Old;
5195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005196
Douglas Gregorfe921a72010-12-20 23:36:19 +00005197 TemplateArgumentLoc operator*() const {
5198 return Container->getArgLoc(Index);
5199 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005200
Douglas Gregorfe921a72010-12-20 23:36:19 +00005201 pointer operator->() const {
5202 return pointer(Container->getArgLoc(Index));
5203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005204
Douglas Gregorfe921a72010-12-20 23:36:19 +00005205 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005206 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005207 return X.Container == Y.Container && X.Index == Y.Index;
5208 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005209
Douglas Gregorfe921a72010-12-20 23:36:19 +00005210 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005211 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005212 return !(X == Y);
5213 }
5214 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005215
5216
John McCall31f82722010-11-12 08:19:04 +00005217template <typename Derived>
5218QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5219 TypeLocBuilder &TLB,
5220 TemplateSpecializationTypeLoc TL,
5221 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005222 TemplateArgumentListInfo NewTemplateArgs;
5223 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5224 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005225 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5226 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005227 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005228 ArgIterator(TL, TL.getNumArgs()),
5229 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005230 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005231
John McCall0ad16662009-10-29 08:12:44 +00005232 // FIXME: maybe don't rebuild if all the template arguments are the same.
5233
5234 QualType Result =
5235 getDerived().RebuildTemplateSpecializationType(Template,
5236 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005237 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005238
5239 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005240 // Specializations of template template parameters are represented as
5241 // TemplateSpecializationTypes, and substitution of type alias templates
5242 // within a dependent context can transform them into
5243 // DependentTemplateSpecializationTypes.
5244 if (isa<DependentTemplateSpecializationType>(Result)) {
5245 DependentTemplateSpecializationTypeLoc NewTL
5246 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005247 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005248 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005249 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005250 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005251 NewTL.setLAngleLoc(TL.getLAngleLoc());
5252 NewTL.setRAngleLoc(TL.getRAngleLoc());
5253 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5254 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5255 return Result;
5256 }
5257
John McCall0ad16662009-10-29 08:12:44 +00005258 TemplateSpecializationTypeLoc NewTL
5259 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005260 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005261 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5262 NewTL.setLAngleLoc(TL.getLAngleLoc());
5263 NewTL.setRAngleLoc(TL.getRAngleLoc());
5264 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5265 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005266 }
Mike Stump11289f42009-09-09 15:08:12 +00005267
John McCall0ad16662009-10-29 08:12:44 +00005268 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005269}
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregor5a064722011-02-28 17:23:35 +00005271template <typename Derived>
5272QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5273 TypeLocBuilder &TLB,
5274 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005275 TemplateName Template,
5276 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005277 TemplateArgumentListInfo NewTemplateArgs;
5278 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5279 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5280 typedef TemplateArgumentLocContainerIterator<
5281 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005282 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005283 ArgIterator(TL, TL.getNumArgs()),
5284 NewTemplateArgs))
5285 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005286
Douglas Gregor5a064722011-02-28 17:23:35 +00005287 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005288
Douglas Gregor5a064722011-02-28 17:23:35 +00005289 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5290 QualType Result
5291 = getSema().Context.getDependentTemplateSpecializationType(
5292 TL.getTypePtr()->getKeyword(),
5293 DTN->getQualifier(),
5294 DTN->getIdentifier(),
5295 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005296
Douglas Gregor5a064722011-02-28 17:23:35 +00005297 DependentTemplateSpecializationTypeLoc NewTL
5298 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005299 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005300 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005301 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005302 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005303 NewTL.setLAngleLoc(TL.getLAngleLoc());
5304 NewTL.setRAngleLoc(TL.getRAngleLoc());
5305 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5306 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5307 return Result;
5308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005309
5310 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005311 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005312 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005313 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005314
Douglas Gregor5a064722011-02-28 17:23:35 +00005315 if (!Result.isNull()) {
5316 /// FIXME: Wrap this in an elaborated-type-specifier?
5317 TemplateSpecializationTypeLoc NewTL
5318 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005319 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005320 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005321 NewTL.setLAngleLoc(TL.getLAngleLoc());
5322 NewTL.setRAngleLoc(TL.getRAngleLoc());
5323 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5324 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005326
Douglas Gregor5a064722011-02-28 17:23:35 +00005327 return Result;
5328}
5329
Mike Stump11289f42009-09-09 15:08:12 +00005330template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005331QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005332TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005333 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005334 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005335
Douglas Gregor844cb502011-03-01 18:12:44 +00005336 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005337 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005338 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005339 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005340 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5341 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005342 return QualType();
5343 }
Mike Stump11289f42009-09-09 15:08:12 +00005344
John McCall31f82722010-11-12 08:19:04 +00005345 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5346 if (NamedT.isNull())
5347 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005348
Richard Smith3f1b5d02011-05-05 21:57:07 +00005349 // C++0x [dcl.type.elab]p2:
5350 // If the identifier resolves to a typedef-name or the simple-template-id
5351 // resolves to an alias template specialization, the
5352 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005353 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5354 if (const TemplateSpecializationType *TST =
5355 NamedT->getAs<TemplateSpecializationType>()) {
5356 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005357 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5358 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005359 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5360 diag::err_tag_reference_non_tag) << 4;
5361 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5362 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005363 }
5364 }
5365
John McCall550e0c22009-10-21 00:40:46 +00005366 QualType Result = TL.getType();
5367 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005368 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005369 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005370 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005371 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005372 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005373 if (Result.isNull())
5374 return QualType();
5375 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005376
Abramo Bagnara6150c882010-05-11 21:36:43 +00005377 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005378 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005379 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005380 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005381}
Mike Stump11289f42009-09-09 15:08:12 +00005382
5383template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005384QualType TreeTransform<Derived>::TransformAttributedType(
5385 TypeLocBuilder &TLB,
5386 AttributedTypeLoc TL) {
5387 const AttributedType *oldType = TL.getTypePtr();
5388 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5389 if (modifiedType.isNull())
5390 return QualType();
5391
5392 QualType result = TL.getType();
5393
5394 // FIXME: dependent operand expressions?
5395 if (getDerived().AlwaysRebuild() ||
5396 modifiedType != oldType->getModifiedType()) {
5397 // TODO: this is really lame; we should really be rebuilding the
5398 // equivalent type from first principles.
5399 QualType equivalentType
5400 = getDerived().TransformType(oldType->getEquivalentType());
5401 if (equivalentType.isNull())
5402 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005403
5404 // Check whether we can add nullability; it is only represented as
5405 // type sugar, and therefore cannot be diagnosed in any other way.
5406 if (auto nullability = oldType->getImmediateNullability()) {
5407 if (!modifiedType->canHaveNullability()) {
5408 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005409 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005410 return QualType();
5411 }
5412 }
5413
John McCall81904512011-01-06 01:58:22 +00005414 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5415 modifiedType,
5416 equivalentType);
5417 }
5418
5419 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5420 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5421 if (TL.hasAttrOperand())
5422 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5423 if (TL.hasAttrExprOperand())
5424 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5425 else if (TL.hasAttrEnumOperand())
5426 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5427
5428 return result;
5429}
5430
5431template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005432QualType
5433TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5434 ParenTypeLoc TL) {
5435 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5436 if (Inner.isNull())
5437 return QualType();
5438
5439 QualType Result = TL.getType();
5440 if (getDerived().AlwaysRebuild() ||
5441 Inner != TL.getInnerLoc().getType()) {
5442 Result = getDerived().RebuildParenType(Inner);
5443 if (Result.isNull())
5444 return QualType();
5445 }
5446
5447 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5448 NewTL.setLParenLoc(TL.getLParenLoc());
5449 NewTL.setRParenLoc(TL.getRParenLoc());
5450 return Result;
5451}
5452
5453template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005454QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005455 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005456 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005457
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005458 NestedNameSpecifierLoc QualifierLoc
5459 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5460 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005461 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005462
John McCallc392f372010-06-11 00:33:02 +00005463 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005464 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005465 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005466 QualifierLoc,
5467 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005468 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005469 if (Result.isNull())
5470 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005471
Abramo Bagnarad7548482010-05-19 21:37:53 +00005472 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5473 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005474 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5475
Abramo Bagnarad7548482010-05-19 21:37:53 +00005476 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005477 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005478 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005479 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005480 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005481 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005482 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005483 NewTL.setNameLoc(TL.getNameLoc());
5484 }
John McCall550e0c22009-10-21 00:40:46 +00005485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregord6ff3322009-08-04 16:50:30 +00005488template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005489QualType TreeTransform<Derived>::
5490 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005491 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005492 NestedNameSpecifierLoc QualifierLoc;
5493 if (TL.getQualifierLoc()) {
5494 QualifierLoc
5495 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5496 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005497 return QualType();
5498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005499
John McCall31f82722010-11-12 08:19:04 +00005500 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005501 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005502}
5503
5504template<typename Derived>
5505QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005506TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5507 DependentTemplateSpecializationTypeLoc TL,
5508 NestedNameSpecifierLoc QualifierLoc) {
5509 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005510
Douglas Gregora7a795b2011-03-01 20:11:18 +00005511 TemplateArgumentListInfo NewTemplateArgs;
5512 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5513 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005514
Douglas Gregora7a795b2011-03-01 20:11:18 +00005515 typedef TemplateArgumentLocContainerIterator<
5516 DependentTemplateSpecializationTypeLoc> ArgIterator;
5517 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5518 ArgIterator(TL, TL.getNumArgs()),
5519 NewTemplateArgs))
5520 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005521
Douglas Gregora7a795b2011-03-01 20:11:18 +00005522 QualType Result
5523 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5524 QualifierLoc,
5525 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005526 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005527 NewTemplateArgs);
5528 if (Result.isNull())
5529 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005530
Douglas Gregora7a795b2011-03-01 20:11:18 +00005531 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5532 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005533
Douglas Gregora7a795b2011-03-01 20:11:18 +00005534 // Copy information relevant to the template specialization.
5535 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005536 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005537 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005538 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005539 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5540 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005541 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005542 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005543
Douglas Gregora7a795b2011-03-01 20:11:18 +00005544 // Copy information relevant to the elaborated type.
5545 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005546 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005547 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005548 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5549 DependentTemplateSpecializationTypeLoc SpecTL
5550 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005551 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005552 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005553 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005554 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005555 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5556 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005557 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005558 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005559 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005560 TemplateSpecializationTypeLoc SpecTL
5561 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005562 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005563 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005564 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5565 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005566 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005567 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005568 }
5569 return Result;
5570}
5571
5572template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005573QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5574 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005575 QualType Pattern
5576 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005577 if (Pattern.isNull())
5578 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005579
5580 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005581 if (getDerived().AlwaysRebuild() ||
5582 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005583 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005584 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005585 TL.getEllipsisLoc(),
5586 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005587 if (Result.isNull())
5588 return QualType();
5589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005590
Douglas Gregor822d0302011-01-12 17:07:58 +00005591 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5592 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5593 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005594}
5595
5596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005597QualType
5598TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005599 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005600 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005601 TLB.pushFullCopy(TL);
5602 return TL.getType();
5603}
5604
5605template<typename Derived>
5606QualType
5607TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005608 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005609 // ObjCObjectType is never dependent.
5610 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005611 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005612}
Mike Stump11289f42009-09-09 15:08:12 +00005613
5614template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005615QualType
5616TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005617 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005618 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005619 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005620 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005621}
5622
Douglas Gregord6ff3322009-08-04 16:50:30 +00005623//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005624// Statement transformation
5625//===----------------------------------------------------------------------===//
5626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005627StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005628TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005629 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005630}
5631
5632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005633StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005634TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5635 return getDerived().TransformCompoundStmt(S, false);
5636}
5637
5638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005639StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005640TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005641 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005642 Sema::CompoundScopeRAII CompoundScope(getSema());
5643
John McCall1ababa62010-08-27 19:56:05 +00005644 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005645 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005646 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005647 for (auto *B : S->body()) {
5648 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005649 if (Result.isInvalid()) {
5650 // Immediately fail if this was a DeclStmt, since it's very
5651 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005652 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005653 return StmtError();
5654
5655 // Otherwise, just keep processing substatements and fail later.
5656 SubStmtInvalid = true;
5657 continue;
5658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005660 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005661 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005662 }
Mike Stump11289f42009-09-09 15:08:12 +00005663
John McCall1ababa62010-08-27 19:56:05 +00005664 if (SubStmtInvalid)
5665 return StmtError();
5666
Douglas Gregorebe10102009-08-20 07:17:43 +00005667 if (!getDerived().AlwaysRebuild() &&
5668 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005669 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005670
5671 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005672 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 S->getRBracLoc(),
5674 IsStmtExpr);
5675}
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregorebe10102009-08-20 07:17:43 +00005677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005678StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005679TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005680 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005681 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005682 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5683 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005684
Eli Friedman06577382009-11-19 03:14:00 +00005685 // Transform the left-hand case value.
5686 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005687 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005688 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005689 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005690
Eli Friedman06577382009-11-19 03:14:00 +00005691 // Transform the right-hand case value (for the GNU case-range extension).
5692 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005693 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005694 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005695 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005696 }
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 // Build the case statement.
5699 // Case statements are always rebuilt so that they will attached to their
5700 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005701 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005702 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005703 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005704 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005705 S->getColonLoc());
5706 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005707 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005708
Douglas Gregorebe10102009-08-20 07:17:43 +00005709 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005710 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005711 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005712 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregorebe10102009-08-20 07:17:43 +00005714 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005715 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005716}
5717
5718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005719StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005720TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005721 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005722 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005723 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005724 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregorebe10102009-08-20 07:17:43 +00005726 // Default statements are always rebuilt
5727 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005728 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005729}
Mike Stump11289f42009-09-09 15:08:12 +00005730
Douglas Gregorebe10102009-08-20 07:17:43 +00005731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005732StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005733TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005734 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005735 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005737
Chris Lattnercab02a62011-02-17 20:34:02 +00005738 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5739 S->getDecl());
5740 if (!LD)
5741 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005742
5743
Douglas Gregorebe10102009-08-20 07:17:43 +00005744 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005745 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005746 cast<LabelDecl>(LD), SourceLocation(),
5747 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005748}
Mike Stump11289f42009-09-09 15:08:12 +00005749
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005750template <typename Derived>
5751const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5752 if (!R)
5753 return R;
5754
5755 switch (R->getKind()) {
5756// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5757#define ATTR(X)
5758#define PRAGMA_SPELLING_ATTR(X) \
5759 case attr::X: \
5760 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5761#include "clang/Basic/AttrList.inc"
5762 default:
5763 return R;
5764 }
5765}
5766
5767template <typename Derived>
5768StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5769 bool AttrsChanged = false;
5770 SmallVector<const Attr *, 1> Attrs;
5771
5772 // Visit attributes and keep track if any are transformed.
5773 for (const auto *I : S->getAttrs()) {
5774 const Attr *R = getDerived().TransformAttr(I);
5775 AttrsChanged |= (I != R);
5776 Attrs.push_back(R);
5777 }
5778
Richard Smithc202b282012-04-14 00:33:13 +00005779 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5780 if (SubStmt.isInvalid())
5781 return StmtError();
5782
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005783 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005784 return S;
5785
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005786 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005787 SubStmt.get());
5788}
5789
5790template<typename Derived>
5791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005792TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005793 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005794 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005795 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005796 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005797 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005798 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005799 getDerived().TransformDefinition(
5800 S->getConditionVariable()->getLocation(),
5801 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005802 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005803 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005804 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005805 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005806
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005807 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005808 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005809
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005810 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005811 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005812 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005813 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005814 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005816
John McCallb268a282010-08-23 23:25:46 +00005817 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005818 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005820
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005821 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005822 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005823 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005824
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005826 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005827 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005828 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005829
Douglas Gregorebe10102009-08-20 07:17:43 +00005830 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005831 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005832 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005833 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregorebe10102009-08-20 07:17:43 +00005835 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005836 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005837 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005838 Then.get() == S->getThen() &&
5839 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005840 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005842 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005843 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005844 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005845}
5846
5847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005848StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005849TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005850 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005851 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005852 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005853 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005854 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005855 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005856 getDerived().TransformDefinition(
5857 S->getConditionVariable()->getLocation(),
5858 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005859 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005861 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005862 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005864 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005865 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005866 }
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregorebe10102009-08-20 07:17:43 +00005868 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005869 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005870 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005871 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005872 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregorebe10102009-08-20 07:17:43 +00005875 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005876 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005877 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005879
Douglas Gregorebe10102009-08-20 07:17:43 +00005880 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005881 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5882 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005883}
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregorebe10102009-08-20 07:17:43 +00005885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005886StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005887TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005888 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005889 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005890 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005891 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005892 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005893 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005894 getDerived().TransformDefinition(
5895 S->getConditionVariable()->getLocation(),
5896 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005897 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005899 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005900 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005902 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005904
5905 if (S->getCond()) {
5906 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005907 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5908 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005909 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005910 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005912 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005913 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005914 }
Mike Stump11289f42009-09-09 15:08:12 +00005915
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005916 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005917 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005919
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005921 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005922 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005923 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005924
Douglas Gregorebe10102009-08-20 07:17:43 +00005925 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005926 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005927 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005928 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005929 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005930
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005931 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005932 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005933}
Mike Stump11289f42009-09-09 15:08:12 +00005934
Douglas Gregorebe10102009-08-20 07:17:43 +00005935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005936StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005937TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005938 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005939 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005940 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005941 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005943 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005944 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005945 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005946 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005947
Douglas Gregorebe10102009-08-20 07:17:43 +00005948 if (!getDerived().AlwaysRebuild() &&
5949 Cond.get() == S->getCond() &&
5950 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005951 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005952
John McCallb268a282010-08-23 23:25:46 +00005953 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5954 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005955 S->getRParenLoc());
5956}
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregorebe10102009-08-20 07:17:43 +00005958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005959StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005960TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005961 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005962 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005963 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregorebe10102009-08-20 07:17:43 +00005966 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005967 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005968 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005969 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005970 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005971 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005972 getDerived().TransformDefinition(
5973 S->getConditionVariable()->getLocation(),
5974 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005975 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005976 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005977 } else {
5978 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005979
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005980 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005982
5983 if (S->getCond()) {
5984 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005985 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5986 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005987 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005988 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005989 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005990
John McCallb268a282010-08-23 23:25:46 +00005991 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005992 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005993 }
Mike Stump11289f42009-09-09 15:08:12 +00005994
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005995 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005996 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005997 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005998
Douglas Gregorebe10102009-08-20 07:17:43 +00005999 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006000 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006001 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006003
Richard Smith945f8d32013-01-14 22:39:08 +00006004 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006005 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006007
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006009 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006010 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006012
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 if (!getDerived().AlwaysRebuild() &&
6014 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006015 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006016 Inc.get() == S->getInc() &&
6017 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006018 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006019
Douglas Gregorebe10102009-08-20 07:17:43 +00006020 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006021 Init.get(), FullCond, ConditionVar,
6022 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006023}
6024
6025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006026StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006027TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006028 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6029 S->getLabel());
6030 if (!LD)
6031 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006032
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006034 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006035 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006036}
6037
6038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006039StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006040TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006041 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006042 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006044 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 if (!getDerived().AlwaysRebuild() &&
6047 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006048 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006049
6050 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006051 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
6053
6054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006056TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006057 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006058}
Mike Stump11289f42009-09-09 15:08:12 +00006059
Douglas Gregorebe10102009-08-20 07:17:43 +00006060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006061StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006062TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006063 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006064}
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregorebe10102009-08-20 07:17:43 +00006066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006067StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006068TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006069 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6070 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006071 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006073
Mike Stump11289f42009-09-09 15:08:12 +00006074 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006075 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006076 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006077}
Mike Stump11289f42009-09-09 15:08:12 +00006078
Douglas Gregorebe10102009-08-20 07:17:43 +00006079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006080StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006081TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006083 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006084 for (auto *D : S->decls()) {
6085 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006086 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006087 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006088
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006089 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregorebe10102009-08-20 07:17:43 +00006092 Decls.push_back(Transformed);
6093 }
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006096 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006097
Rafael Espindolaab417692013-07-09 12:05:01 +00006098 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006099}
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregorebe10102009-08-20 07:17:43 +00006101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006102StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006103TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006104
Benjamin Kramerf0623432012-08-23 22:51:59 +00006105 SmallVector<Expr*, 8> Constraints;
6106 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006107 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006108
John McCalldadc5752010-08-24 06:29:42 +00006109 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006110 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006111
6112 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006113
Anders Carlssonaaeef072010-01-24 05:50:09 +00006114 // Go through the outputs.
6115 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006116 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006117
Anders Carlssonaaeef072010-01-24 05:50:09 +00006118 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006119 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006120
Anders Carlssonaaeef072010-01-24 05:50:09 +00006121 // Transform the output expr.
6122 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006123 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006124 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
Anders Carlssonaaeef072010-01-24 05:50:09 +00006127 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006128
John McCallb268a282010-08-23 23:25:46 +00006129 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006130 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006131
Anders Carlssonaaeef072010-01-24 05:50:09 +00006132 // Go through the inputs.
6133 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006134 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006135
Anders Carlssonaaeef072010-01-24 05:50:09 +00006136 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006137 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006138
Anders Carlssonaaeef072010-01-24 05:50:09 +00006139 // Transform the input expr.
6140 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006141 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006142 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006144
Anders Carlssonaaeef072010-01-24 05:50:09 +00006145 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006146
John McCallb268a282010-08-23 23:25:46 +00006147 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006148 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006149
Anders Carlssonaaeef072010-01-24 05:50:09 +00006150 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006151 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006152
6153 // Go through the clobbers.
6154 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006155 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006156
6157 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006158 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006159 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6160 S->isVolatile(), S->getNumOutputs(),
6161 S->getNumInputs(), Names.data(),
6162 Constraints, Exprs, AsmString.get(),
6163 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006164}
6165
Chad Rosier32503022012-06-11 20:47:18 +00006166template<typename Derived>
6167StmtResult
6168TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006169 ArrayRef<Token> AsmToks =
6170 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006171
John McCallf413f5e2013-05-03 00:10:13 +00006172 bool HadError = false, HadChange = false;
6173
6174 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6175 SmallVector<Expr*, 8> TransformedExprs;
6176 TransformedExprs.reserve(SrcExprs.size());
6177 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6178 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6179 if (!Result.isUsable()) {
6180 HadError = true;
6181 } else {
6182 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006183 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006184 }
6185 }
6186
6187 if (HadError) return StmtError();
6188 if (!HadChange && !getDerived().AlwaysRebuild())
6189 return Owned(S);
6190
Chad Rosierb6f46c12012-08-15 16:53:30 +00006191 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006192 AsmToks, S->getAsmString(),
6193 S->getNumOutputs(), S->getNumInputs(),
6194 S->getAllConstraints(), S->getClobbers(),
6195 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006196}
Douglas Gregorebe10102009-08-20 07:17:43 +00006197
6198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006199StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006200TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006201 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006202 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006203 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006204 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006205
Douglas Gregor96c79492010-04-23 22:50:49 +00006206 // Transform the @catch statements (if present).
6207 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006208 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006209 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006210 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006211 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006213 if (Catch.get() != S->getCatchStmt(I))
6214 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006215 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006217
Douglas Gregor306de2f2010-04-22 23:59:56 +00006218 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006219 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006220 if (S->getFinallyStmt()) {
6221 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6222 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006224 }
6225
6226 // If nothing changed, just retain this statement.
6227 if (!getDerived().AlwaysRebuild() &&
6228 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006229 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006230 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006231 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006232
Douglas Gregor306de2f2010-04-22 23:59:56 +00006233 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006234 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006235 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006236}
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregorebe10102009-08-20 07:17:43 +00006238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006239StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006240TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006241 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006242 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006243 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006244 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006245 if (FromVar->getTypeSourceInfo()) {
6246 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6247 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006248 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006250
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006251 QualType T;
6252 if (TSInfo)
6253 T = TSInfo->getType();
6254 else {
6255 T = getDerived().TransformType(FromVar->getType());
6256 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006257 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006259
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006260 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6261 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006262 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006264
John McCalldadc5752010-08-24 06:29:42 +00006265 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006266 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006267 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006268
6269 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006270 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006271 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006272}
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregorebe10102009-08-20 07:17:43 +00006274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006275StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006276TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006277 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006278 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006279 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006281
Douglas Gregor306de2f2010-04-22 23:59:56 +00006282 // If nothing changed, just retain this statement.
6283 if (!getDerived().AlwaysRebuild() &&
6284 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006285 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006286
6287 // Build a new statement.
6288 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006289 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006290}
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregorebe10102009-08-20 07:17:43 +00006292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006293StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006294TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006295 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006296 if (S->getThrowExpr()) {
6297 Operand = getDerived().TransformExpr(S->getThrowExpr());
6298 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006300 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006301
Douglas Gregor2900c162010-04-22 21:44:01 +00006302 if (!getDerived().AlwaysRebuild() &&
6303 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006304 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006305
John McCallb268a282010-08-23 23:25:46 +00006306 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006307}
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregorebe10102009-08-20 07:17:43 +00006309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006310StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006311TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006312 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006313 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006314 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006315 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006316 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006317 Object =
6318 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6319 Object.get());
6320 if (Object.isInvalid())
6321 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
Douglas Gregor6148de72010-04-22 22:01:21 +00006323 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006324 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006325 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006326 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006327
Douglas Gregor6148de72010-04-22 22:01:21 +00006328 // If nothing change, just retain the current statement.
6329 if (!getDerived().AlwaysRebuild() &&
6330 Object.get() == S->getSynchExpr() &&
6331 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006332 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006333
6334 // Build a new statement.
6335 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006336 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006337}
6338
6339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006340StmtResult
John McCall31168b02011-06-15 23:02:42 +00006341TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6342 ObjCAutoreleasePoolStmt *S) {
6343 // Transform the body.
6344 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6345 if (Body.isInvalid())
6346 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006347
John McCall31168b02011-06-15 23:02:42 +00006348 // If nothing changed, just retain this statement.
6349 if (!getDerived().AlwaysRebuild() &&
6350 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006351 return S;
John McCall31168b02011-06-15 23:02:42 +00006352
6353 // Build a new statement.
6354 return getDerived().RebuildObjCAutoreleasePoolStmt(
6355 S->getAtLoc(), Body.get());
6356}
6357
6358template<typename Derived>
6359StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006360TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006361 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006362 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006363 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006364 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006365 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006366
Douglas Gregorf68a5082010-04-22 23:10:45 +00006367 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006368 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006369 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006370 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006371
Douglas Gregorf68a5082010-04-22 23:10:45 +00006372 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006373 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006374 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006376
Douglas Gregorf68a5082010-04-22 23:10:45 +00006377 // If nothing changed, just retain this statement.
6378 if (!getDerived().AlwaysRebuild() &&
6379 Element.get() == S->getElement() &&
6380 Collection.get() == S->getCollection() &&
6381 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006382 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006383
Douglas Gregorf68a5082010-04-22 23:10:45 +00006384 // Build a new statement.
6385 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006386 Element.get(),
6387 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006388 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006389 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006390}
6391
David Majnemer5f7efef2013-10-15 09:50:08 +00006392template <typename Derived>
6393StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006394 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006395 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006396 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6397 TypeSourceInfo *T =
6398 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006399 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006400 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006401
David Majnemer5f7efef2013-10-15 09:50:08 +00006402 Var = getDerived().RebuildExceptionDecl(
6403 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6404 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006405 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006406 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006407 }
Mike Stump11289f42009-09-09 15:08:12 +00006408
Douglas Gregorebe10102009-08-20 07:17:43 +00006409 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006410 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006411 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006412 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006413
David Majnemer5f7efef2013-10-15 09:50:08 +00006414 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006415 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006416 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006417
David Majnemer5f7efef2013-10-15 09:50:08 +00006418 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006419}
Mike Stump11289f42009-09-09 15:08:12 +00006420
David Majnemer5f7efef2013-10-15 09:50:08 +00006421template <typename Derived>
6422StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006423 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006424 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006425 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregorebe10102009-08-20 07:17:43 +00006428 // Transform the handlers.
6429 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006430 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006431 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006432 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006433 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006434 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregorebe10102009-08-20 07:17:43 +00006436 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006437 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006438 }
Mike Stump11289f42009-09-09 15:08:12 +00006439
David Majnemer5f7efef2013-10-15 09:50:08 +00006440 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006441 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006442 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006443
John McCallb268a282010-08-23 23:25:46 +00006444 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006445 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006446}
Mike Stump11289f42009-09-09 15:08:12 +00006447
Richard Smith02e85f32011-04-14 22:09:26 +00006448template<typename Derived>
6449StmtResult
6450TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6451 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6452 if (Range.isInvalid())
6453 return StmtError();
6454
6455 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6456 if (BeginEnd.isInvalid())
6457 return StmtError();
6458
6459 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6460 if (Cond.isInvalid())
6461 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006462 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006463 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006464 if (Cond.isInvalid())
6465 return StmtError();
6466 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006467 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006468
6469 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6470 if (Inc.isInvalid())
6471 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006472 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006473 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006474
6475 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6476 if (LoopVar.isInvalid())
6477 return StmtError();
6478
6479 StmtResult NewStmt = S;
6480 if (getDerived().AlwaysRebuild() ||
6481 Range.get() != S->getRangeStmt() ||
6482 BeginEnd.get() != S->getBeginEndStmt() ||
6483 Cond.get() != S->getCond() ||
6484 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006485 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006486 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6487 S->getColonLoc(), Range.get(),
6488 BeginEnd.get(), Cond.get(),
6489 Inc.get(), LoopVar.get(),
6490 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006491 if (NewStmt.isInvalid())
6492 return StmtError();
6493 }
Richard Smith02e85f32011-04-14 22:09:26 +00006494
6495 StmtResult Body = getDerived().TransformStmt(S->getBody());
6496 if (Body.isInvalid())
6497 return StmtError();
6498
6499 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6500 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006501 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006502 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6503 S->getColonLoc(), Range.get(),
6504 BeginEnd.get(), Cond.get(),
6505 Inc.get(), LoopVar.get(),
6506 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006507 if (NewStmt.isInvalid())
6508 return StmtError();
6509 }
Richard Smith02e85f32011-04-14 22:09:26 +00006510
6511 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006512 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006513
6514 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6515}
6516
John Wiegley1c0675e2011-04-28 01:08:34 +00006517template<typename Derived>
6518StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006519TreeTransform<Derived>::TransformMSDependentExistsStmt(
6520 MSDependentExistsStmt *S) {
6521 // Transform the nested-name-specifier, if any.
6522 NestedNameSpecifierLoc QualifierLoc;
6523 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006524 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006525 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6526 if (!QualifierLoc)
6527 return StmtError();
6528 }
6529
6530 // Transform the declaration name.
6531 DeclarationNameInfo NameInfo = S->getNameInfo();
6532 if (NameInfo.getName()) {
6533 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6534 if (!NameInfo.getName())
6535 return StmtError();
6536 }
6537
6538 // Check whether anything changed.
6539 if (!getDerived().AlwaysRebuild() &&
6540 QualifierLoc == S->getQualifierLoc() &&
6541 NameInfo.getName() == S->getNameInfo().getName())
6542 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006543
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006544 // Determine whether this name exists, if we can.
6545 CXXScopeSpec SS;
6546 SS.Adopt(QualifierLoc);
6547 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006548 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006549 case Sema::IER_Exists:
6550 if (S->isIfExists())
6551 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006552
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006553 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6554
6555 case Sema::IER_DoesNotExist:
6556 if (S->isIfNotExists())
6557 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006558
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006559 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006560
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006561 case Sema::IER_Dependent:
6562 Dependent = true;
6563 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006564
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006565 case Sema::IER_Error:
6566 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006568
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006569 // We need to continue with the instantiation, so do so now.
6570 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6571 if (SubStmt.isInvalid())
6572 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006573
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006574 // If we have resolved the name, just transform to the substatement.
6575 if (!Dependent)
6576 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006577
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006578 // The name is still dependent, so build a dependent expression again.
6579 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6580 S->isIfExists(),
6581 QualifierLoc,
6582 NameInfo,
6583 SubStmt.get());
6584}
6585
6586template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006587ExprResult
6588TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6589 NestedNameSpecifierLoc QualifierLoc;
6590 if (E->getQualifierLoc()) {
6591 QualifierLoc
6592 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6593 if (!QualifierLoc)
6594 return ExprError();
6595 }
6596
6597 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6598 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6599 if (!PD)
6600 return ExprError();
6601
6602 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6603 if (Base.isInvalid())
6604 return ExprError();
6605
6606 return new (SemaRef.getASTContext())
6607 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6608 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6609 QualifierLoc, E->getMemberLoc());
6610}
6611
David Majnemerfad8f482013-10-15 09:33:02 +00006612template <typename Derived>
6613StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006614 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006615 if (TryBlock.isInvalid())
6616 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006617
6618 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006619 if (Handler.isInvalid())
6620 return StmtError();
6621
David Majnemerfad8f482013-10-15 09:33:02 +00006622 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6623 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006624 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006625
Warren Huntf6be4cb2014-07-25 20:52:51 +00006626 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6627 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006628}
6629
David Majnemerfad8f482013-10-15 09:33:02 +00006630template <typename Derived>
6631StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006632 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006633 if (Block.isInvalid())
6634 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006635
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006636 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006637}
6638
David Majnemerfad8f482013-10-15 09:33:02 +00006639template <typename Derived>
6640StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006641 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006642 if (FilterExpr.isInvalid())
6643 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006644
David Majnemer7e755502013-10-15 09:30:14 +00006645 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006646 if (Block.isInvalid())
6647 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006648
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006649 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6650 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006651}
6652
David Majnemerfad8f482013-10-15 09:33:02 +00006653template <typename Derived>
6654StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6655 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006656 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6657 else
6658 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6659}
6660
Nico Weber9b982072014-07-07 00:12:30 +00006661template<typename Derived>
6662StmtResult
6663TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6664 return S;
6665}
6666
Alexander Musman64d33f12014-06-04 07:53:32 +00006667//===----------------------------------------------------------------------===//
6668// OpenMP directive transformation
6669//===----------------------------------------------------------------------===//
6670template <typename Derived>
6671StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6672 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006673
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006674 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006675 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006676 ArrayRef<OMPClause *> Clauses = D->clauses();
6677 TClauses.reserve(Clauses.size());
6678 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6679 I != E; ++I) {
6680 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006681 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006682 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006683 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006684 if (Clause)
6685 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006686 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006687 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006688 }
6689 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006690 StmtResult AssociatedStmt;
6691 if (D->hasAssociatedStmt()) {
6692 if (!D->getAssociatedStmt()) {
6693 return StmtError();
6694 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006695 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6696 /*CurScope=*/nullptr);
6697 StmtResult Body;
6698 {
6699 Sema::CompoundScopeRAII CompoundScope(getSema());
6700 Body = getDerived().TransformStmt(
6701 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6702 }
6703 AssociatedStmt =
6704 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006705 if (AssociatedStmt.isInvalid()) {
6706 return StmtError();
6707 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006708 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006709 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006710 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006711 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006712
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006713 // Transform directive name for 'omp critical' directive.
6714 DeclarationNameInfo DirName;
6715 if (D->getDirectiveKind() == OMPD_critical) {
6716 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6717 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6718 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006719 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6720 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6721 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006722 } else if (D->getDirectiveKind() == OMPD_cancel) {
6723 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006724 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006725
Alexander Musman64d33f12014-06-04 07:53:32 +00006726 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006727 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6728 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006729}
6730
Alexander Musman64d33f12014-06-04 07:53:32 +00006731template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006732StmtResult
6733TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6734 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006735 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6736 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006737 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6738 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6739 return Res;
6740}
6741
Alexander Musman64d33f12014-06-04 07:53:32 +00006742template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006743StmtResult
6744TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6745 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006746 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6747 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006748 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6749 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006750 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006751}
6752
Alexey Bataevf29276e2014-06-18 04:14:57 +00006753template <typename Derived>
6754StmtResult
6755TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6756 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006757 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6758 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006759 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6760 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6761 return Res;
6762}
6763
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006764template <typename Derived>
6765StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006766TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6767 DeclarationNameInfo DirName;
6768 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6769 D->getLocStart());
6770 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6771 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6772 return Res;
6773}
6774
6775template <typename Derived>
6776StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006777TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6778 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006779 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6780 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006781 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6782 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6783 return Res;
6784}
6785
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006786template <typename Derived>
6787StmtResult
6788TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6789 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006790 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6791 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006792 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6793 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6794 return Res;
6795}
6796
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006797template <typename Derived>
6798StmtResult
6799TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6800 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006801 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6802 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006803 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6804 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6805 return Res;
6806}
6807
Alexey Bataev4acb8592014-07-07 13:01:15 +00006808template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006809StmtResult
6810TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6811 DeclarationNameInfo DirName;
6812 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6813 D->getLocStart());
6814 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6815 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6816 return Res;
6817}
6818
6819template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006820StmtResult
6821TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6822 getDerived().getSema().StartOpenMPDSABlock(
6823 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6824 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6825 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6826 return Res;
6827}
6828
6829template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006830StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6831 OMPParallelForDirective *D) {
6832 DeclarationNameInfo DirName;
6833 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6834 nullptr, D->getLocStart());
6835 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6836 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6837 return Res;
6838}
6839
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006840template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006841StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6842 OMPParallelForSimdDirective *D) {
6843 DeclarationNameInfo DirName;
6844 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6845 nullptr, D->getLocStart());
6846 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6847 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6848 return Res;
6849}
6850
6851template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006852StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6853 OMPParallelSectionsDirective *D) {
6854 DeclarationNameInfo DirName;
6855 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6856 nullptr, D->getLocStart());
6857 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6858 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6859 return Res;
6860}
6861
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006862template <typename Derived>
6863StmtResult
6864TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6865 DeclarationNameInfo DirName;
6866 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6867 D->getLocStart());
6868 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6869 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6870 return Res;
6871}
6872
Alexey Bataev68446b72014-07-18 07:47:19 +00006873template <typename Derived>
6874StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6875 OMPTaskyieldDirective *D) {
6876 DeclarationNameInfo DirName;
6877 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6878 D->getLocStart());
6879 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6880 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6881 return Res;
6882}
6883
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006884template <typename Derived>
6885StmtResult
6886TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6887 DeclarationNameInfo DirName;
6888 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6889 D->getLocStart());
6890 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6891 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6892 return Res;
6893}
6894
Alexey Bataev2df347a2014-07-18 10:17:07 +00006895template <typename Derived>
6896StmtResult
6897TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6898 DeclarationNameInfo DirName;
6899 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6900 D->getLocStart());
6901 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6902 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6903 return Res;
6904}
6905
Alexey Bataev6125da92014-07-21 11:26:11 +00006906template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00006907StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
6908 OMPTaskgroupDirective *D) {
6909 DeclarationNameInfo DirName;
6910 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
6911 D->getLocStart());
6912 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6913 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6914 return Res;
6915}
6916
6917template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00006918StmtResult
6919TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6920 DeclarationNameInfo DirName;
6921 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6922 D->getLocStart());
6923 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6924 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6925 return Res;
6926}
6927
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006928template <typename Derived>
6929StmtResult
6930TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6931 DeclarationNameInfo DirName;
6932 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6933 D->getLocStart());
6934 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6935 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6936 return Res;
6937}
6938
Alexey Bataev0162e452014-07-22 10:10:35 +00006939template <typename Derived>
6940StmtResult
6941TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6942 DeclarationNameInfo DirName;
6943 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6944 D->getLocStart());
6945 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6946 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6947 return Res;
6948}
6949
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006950template <typename Derived>
6951StmtResult
6952TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6953 DeclarationNameInfo DirName;
6954 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6955 D->getLocStart());
6956 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6957 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6958 return Res;
6959}
6960
Alexey Bataev13314bf2014-10-09 04:18:56 +00006961template <typename Derived>
6962StmtResult
6963TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6964 DeclarationNameInfo DirName;
6965 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6966 D->getLocStart());
6967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6968 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6969 return Res;
6970}
6971
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006972template <typename Derived>
6973StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
6974 OMPCancellationPointDirective *D) {
6975 DeclarationNameInfo DirName;
6976 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
6977 nullptr, D->getLocStart());
6978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6979 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6980 return Res;
6981}
6982
Alexey Bataev80909872015-07-02 11:25:17 +00006983template <typename Derived>
6984StmtResult
6985TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
6986 DeclarationNameInfo DirName;
6987 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
6988 D->getLocStart());
6989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6990 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6991 return Res;
6992}
6993
Alexander Musman64d33f12014-06-04 07:53:32 +00006994//===----------------------------------------------------------------------===//
6995// OpenMP clause transformation
6996//===----------------------------------------------------------------------===//
6997template <typename Derived>
6998OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006999 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7000 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007001 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007002 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007003 C->getLParenLoc(), C->getLocEnd());
7004}
7005
Alexander Musman64d33f12014-06-04 07:53:32 +00007006template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007007OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7008 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7009 if (Cond.isInvalid())
7010 return nullptr;
7011 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7012 C->getLParenLoc(), C->getLocEnd());
7013}
7014
7015template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007016OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007017TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7018 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7019 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007020 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007021 return getDerived().RebuildOMPNumThreadsClause(
7022 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007023}
7024
Alexey Bataev62c87d22014-03-21 04:51:18 +00007025template <typename Derived>
7026OMPClause *
7027TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7028 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7029 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007030 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007031 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007032 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007033}
7034
Alexander Musman8bd31e62014-05-27 15:12:19 +00007035template <typename Derived>
7036OMPClause *
7037TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7038 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7039 if (E.isInvalid())
7040 return 0;
7041 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007042 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007043}
7044
Alexander Musman64d33f12014-06-04 07:53:32 +00007045template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007046OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007047TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007048 return getDerived().RebuildOMPDefaultClause(
7049 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7050 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007051}
7052
Alexander Musman64d33f12014-06-04 07:53:32 +00007053template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007054OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007055TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007056 return getDerived().RebuildOMPProcBindClause(
7057 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7058 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007059}
7060
Alexander Musman64d33f12014-06-04 07:53:32 +00007061template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007062OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007063TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7064 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7065 if (E.isInvalid())
7066 return nullptr;
7067 return getDerived().RebuildOMPScheduleClause(
7068 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7069 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7070}
7071
7072template <typename Derived>
7073OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007074TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7075 // No need to rebuild this clause, no template-dependent parameters.
7076 return C;
7077}
7078
7079template <typename Derived>
7080OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007081TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7082 // No need to rebuild this clause, no template-dependent parameters.
7083 return C;
7084}
7085
7086template <typename Derived>
7087OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007088TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7089 // No need to rebuild this clause, no template-dependent parameters.
7090 return C;
7091}
7092
7093template <typename Derived>
7094OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007095TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7096 // No need to rebuild this clause, no template-dependent parameters.
7097 return C;
7098}
7099
7100template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007101OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7102 // No need to rebuild this clause, no template-dependent parameters.
7103 return C;
7104}
7105
7106template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007107OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7108 // No need to rebuild this clause, no template-dependent parameters.
7109 return C;
7110}
7111
7112template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007113OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007114TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7115 // No need to rebuild this clause, no template-dependent parameters.
7116 return C;
7117}
7118
7119template <typename Derived>
7120OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007121TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7122 // No need to rebuild this clause, no template-dependent parameters.
7123 return C;
7124}
7125
7126template <typename Derived>
7127OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007128TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7129 // No need to rebuild this clause, no template-dependent parameters.
7130 return C;
7131}
7132
7133template <typename Derived>
7134OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007135TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007136 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007137 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007138 for (auto *VE : C->varlists()) {
7139 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007140 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007141 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007142 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007143 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007144 return getDerived().RebuildOMPPrivateClause(
7145 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007146}
7147
Alexander Musman64d33f12014-06-04 07:53:32 +00007148template <typename Derived>
7149OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7150 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007151 llvm::SmallVector<Expr *, 16> Vars;
7152 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007153 for (auto *VE : C->varlists()) {
7154 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007155 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007156 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007157 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007158 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007159 return getDerived().RebuildOMPFirstprivateClause(
7160 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007161}
7162
Alexander Musman64d33f12014-06-04 07:53:32 +00007163template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007164OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007165TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7166 llvm::SmallVector<Expr *, 16> Vars;
7167 Vars.reserve(C->varlist_size());
7168 for (auto *VE : C->varlists()) {
7169 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7170 if (EVar.isInvalid())
7171 return nullptr;
7172 Vars.push_back(EVar.get());
7173 }
7174 return getDerived().RebuildOMPLastprivateClause(
7175 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7176}
7177
7178template <typename Derived>
7179OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007180TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7181 llvm::SmallVector<Expr *, 16> Vars;
7182 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007183 for (auto *VE : C->varlists()) {
7184 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007185 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007186 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007187 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007188 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007189 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7190 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007191}
7192
Alexander Musman64d33f12014-06-04 07:53:32 +00007193template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007194OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007195TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7196 llvm::SmallVector<Expr *, 16> Vars;
7197 Vars.reserve(C->varlist_size());
7198 for (auto *VE : C->varlists()) {
7199 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7200 if (EVar.isInvalid())
7201 return nullptr;
7202 Vars.push_back(EVar.get());
7203 }
7204 CXXScopeSpec ReductionIdScopeSpec;
7205 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7206
7207 DeclarationNameInfo NameInfo = C->getNameInfo();
7208 if (NameInfo.getName()) {
7209 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7210 if (!NameInfo.getName())
7211 return nullptr;
7212 }
7213 return getDerived().RebuildOMPReductionClause(
7214 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7215 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7216}
7217
7218template <typename Derived>
7219OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007220TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7221 llvm::SmallVector<Expr *, 16> Vars;
7222 Vars.reserve(C->varlist_size());
7223 for (auto *VE : C->varlists()) {
7224 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7225 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007226 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007227 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007228 }
7229 ExprResult Step = getDerived().TransformExpr(C->getStep());
7230 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007231 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007232 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7233 C->getLParenLoc(),
7234 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007235}
7236
Alexander Musman64d33f12014-06-04 07:53:32 +00007237template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007238OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007239TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7240 llvm::SmallVector<Expr *, 16> Vars;
7241 Vars.reserve(C->varlist_size());
7242 for (auto *VE : C->varlists()) {
7243 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7244 if (EVar.isInvalid())
7245 return nullptr;
7246 Vars.push_back(EVar.get());
7247 }
7248 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7249 if (Alignment.isInvalid())
7250 return nullptr;
7251 return getDerived().RebuildOMPAlignedClause(
7252 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7253 C->getColonLoc(), C->getLocEnd());
7254}
7255
Alexander Musman64d33f12014-06-04 07:53:32 +00007256template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007257OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007258TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7259 llvm::SmallVector<Expr *, 16> Vars;
7260 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007261 for (auto *VE : C->varlists()) {
7262 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007263 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007264 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007265 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007266 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007267 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7268 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007269}
7270
Alexey Bataevbae9a792014-06-27 10:37:06 +00007271template <typename Derived>
7272OMPClause *
7273TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7274 llvm::SmallVector<Expr *, 16> Vars;
7275 Vars.reserve(C->varlist_size());
7276 for (auto *VE : C->varlists()) {
7277 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7278 if (EVar.isInvalid())
7279 return nullptr;
7280 Vars.push_back(EVar.get());
7281 }
7282 return getDerived().RebuildOMPCopyprivateClause(
7283 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7284}
7285
Alexey Bataev6125da92014-07-21 11:26:11 +00007286template <typename Derived>
7287OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7288 llvm::SmallVector<Expr *, 16> Vars;
7289 Vars.reserve(C->varlist_size());
7290 for (auto *VE : C->varlists()) {
7291 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7292 if (EVar.isInvalid())
7293 return nullptr;
7294 Vars.push_back(EVar.get());
7295 }
7296 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7297 C->getLParenLoc(), C->getLocEnd());
7298}
7299
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007300template <typename Derived>
7301OMPClause *
7302TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7303 llvm::SmallVector<Expr *, 16> Vars;
7304 Vars.reserve(C->varlist_size());
7305 for (auto *VE : C->varlists()) {
7306 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7307 if (EVar.isInvalid())
7308 return nullptr;
7309 Vars.push_back(EVar.get());
7310 }
7311 return getDerived().RebuildOMPDependClause(
7312 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7313 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7314}
7315
Douglas Gregorebe10102009-08-20 07:17:43 +00007316//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007317// Expression transformation
7318//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007320ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007321TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007322 if (!E->isTypeDependent())
7323 return E;
7324
7325 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7326 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007327}
Mike Stump11289f42009-09-09 15:08:12 +00007328
7329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007330ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007331TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007332 NestedNameSpecifierLoc QualifierLoc;
7333 if (E->getQualifierLoc()) {
7334 QualifierLoc
7335 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7336 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007337 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007338 }
John McCallce546572009-12-08 09:08:17 +00007339
7340 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007341 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7342 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007343 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007345
John McCall815039a2010-08-17 21:27:17 +00007346 DeclarationNameInfo NameInfo = E->getNameInfo();
7347 if (NameInfo.getName()) {
7348 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7349 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007350 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007351 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007352
7353 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007354 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007355 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007356 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007357 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007358
7359 // Mark it referenced in the new context regardless.
7360 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007361 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007362
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007363 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007364 }
John McCallce546572009-12-08 09:08:17 +00007365
Craig Topperc3ec1492014-05-26 06:22:03 +00007366 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007367 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007368 TemplateArgs = &TransArgs;
7369 TransArgs.setLAngleLoc(E->getLAngleLoc());
7370 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007371 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7372 E->getNumTemplateArgs(),
7373 TransArgs))
7374 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007375 }
7376
Chad Rosier1dcde962012-08-08 18:46:20 +00007377 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007378 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007379}
Mike Stump11289f42009-09-09 15:08:12 +00007380
Douglas Gregora16548e2009-08-11 05:31:07 +00007381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007383TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007384 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007385}
Mike Stump11289f42009-09-09 15:08:12 +00007386
Douglas Gregora16548e2009-08-11 05:31:07 +00007387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007389TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007390 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007391}
Mike Stump11289f42009-09-09 15:08:12 +00007392
Douglas Gregora16548e2009-08-11 05:31:07 +00007393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007395TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007396 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007397}
Mike Stump11289f42009-09-09 15:08:12 +00007398
Douglas Gregora16548e2009-08-11 05:31:07 +00007399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007400ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007401TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007402 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007403}
Mike Stump11289f42009-09-09 15:08:12 +00007404
Douglas Gregora16548e2009-08-11 05:31:07 +00007405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007406ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007407TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007408 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007409}
7410
7411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007412ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007413TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007414 if (FunctionDecl *FD = E->getDirectCallee())
7415 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007416 return SemaRef.MaybeBindToTemporary(E);
7417}
7418
7419template<typename Derived>
7420ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007421TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7422 ExprResult ControllingExpr =
7423 getDerived().TransformExpr(E->getControllingExpr());
7424 if (ControllingExpr.isInvalid())
7425 return ExprError();
7426
Chris Lattner01cf8db2011-07-20 06:58:45 +00007427 SmallVector<Expr *, 4> AssocExprs;
7428 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007429 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7430 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7431 if (TS) {
7432 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7433 if (!AssocType)
7434 return ExprError();
7435 AssocTypes.push_back(AssocType);
7436 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007437 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007438 }
7439
7440 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7441 if (AssocExpr.isInvalid())
7442 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007443 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007444 }
7445
7446 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7447 E->getDefaultLoc(),
7448 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007449 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007450 AssocTypes,
7451 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007452}
7453
7454template<typename Derived>
7455ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007456TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007457 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007458 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007459 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007460
Douglas Gregora16548e2009-08-11 05:31:07 +00007461 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007462 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007463
John McCallb268a282010-08-23 23:25:46 +00007464 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007465 E->getRParen());
7466}
7467
Richard Smithdb2630f2012-10-21 03:28:35 +00007468/// \brief The operand of a unary address-of operator has special rules: it's
7469/// allowed to refer to a non-static member of a class even if there's no 'this'
7470/// object available.
7471template<typename Derived>
7472ExprResult
7473TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7474 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007475 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007476 else
7477 return getDerived().TransformExpr(E);
7478}
7479
Mike Stump11289f42009-09-09 15:08:12 +00007480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007481ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007482TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007483 ExprResult SubExpr;
7484 if (E->getOpcode() == UO_AddrOf)
7485 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7486 else
7487 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007488 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007489 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007490
Douglas Gregora16548e2009-08-11 05:31:07 +00007491 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007492 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007493
Douglas Gregora16548e2009-08-11 05:31:07 +00007494 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7495 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007496 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007497}
Mike Stump11289f42009-09-09 15:08:12 +00007498
Douglas Gregora16548e2009-08-11 05:31:07 +00007499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007500ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007501TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7502 // Transform the type.
7503 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7504 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007505 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007506
Douglas Gregor882211c2010-04-28 22:16:22 +00007507 // Transform all of the components into components similar to what the
7508 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007509 // FIXME: It would be slightly more efficient in the non-dependent case to
7510 // just map FieldDecls, rather than requiring the rebuilder to look for
7511 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007512 // template code that we don't care.
7513 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007514 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007515 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007516 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007517 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7518 const Node &ON = E->getComponent(I);
7519 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007520 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007521 Comp.LocStart = ON.getSourceRange().getBegin();
7522 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007523 switch (ON.getKind()) {
7524 case Node::Array: {
7525 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007526 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007527 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007528 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007529
Douglas Gregor882211c2010-04-28 22:16:22 +00007530 ExprChanged = ExprChanged || Index.get() != FromIndex;
7531 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007532 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007533 break;
7534 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007535
Douglas Gregor882211c2010-04-28 22:16:22 +00007536 case Node::Field:
7537 case Node::Identifier:
7538 Comp.isBrackets = false;
7539 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007540 if (!Comp.U.IdentInfo)
7541 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007542
Douglas Gregor882211c2010-04-28 22:16:22 +00007543 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007544
Douglas Gregord1702062010-04-29 00:18:15 +00007545 case Node::Base:
7546 // Will be recomputed during the rebuild.
7547 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007548 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007549
Douglas Gregor882211c2010-04-28 22:16:22 +00007550 Components.push_back(Comp);
7551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007552
Douglas Gregor882211c2010-04-28 22:16:22 +00007553 // If nothing changed, retain the existing expression.
7554 if (!getDerived().AlwaysRebuild() &&
7555 Type == E->getTypeSourceInfo() &&
7556 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007557 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007558
Douglas Gregor882211c2010-04-28 22:16:22 +00007559 // Build a new offsetof expression.
7560 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7561 Components.data(), Components.size(),
7562 E->getRParenLoc());
7563}
7564
7565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007566ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007567TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7568 assert(getDerived().AlreadyTransformed(E->getType()) &&
7569 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007570 return E;
John McCall8d69a212010-11-15 23:31:06 +00007571}
7572
7573template<typename Derived>
7574ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007575TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7576 return E;
7577}
7578
7579template<typename Derived>
7580ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007581TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007582 // Rebuild the syntactic form. The original syntactic form has
7583 // opaque-value expressions in it, so strip those away and rebuild
7584 // the result. This is a really awful way of doing this, but the
7585 // better solution (rebuilding the semantic expressions and
7586 // rebinding OVEs as necessary) doesn't work; we'd need
7587 // TreeTransform to not strip away implicit conversions.
7588 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7589 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007590 if (result.isInvalid()) return ExprError();
7591
7592 // If that gives us a pseudo-object result back, the pseudo-object
7593 // expression must have been an lvalue-to-rvalue conversion which we
7594 // should reapply.
7595 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007596 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007597
7598 return result;
7599}
7600
7601template<typename Derived>
7602ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007603TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7604 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007605 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007606 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007607
John McCallbcd03502009-12-07 02:54:59 +00007608 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007609 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007610 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007611
John McCall4c98fd82009-11-04 07:28:41 +00007612 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007613 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007614
Peter Collingbournee190dee2011-03-11 19:24:49 +00007615 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7616 E->getKind(),
7617 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007618 }
Mike Stump11289f42009-09-09 15:08:12 +00007619
Eli Friedmane4f22df2012-02-29 04:03:55 +00007620 // C++0x [expr.sizeof]p1:
7621 // The operand is either an expression, which is an unevaluated operand
7622 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007623 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7624 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007625
Reid Kleckner32506ed2014-06-12 23:03:48 +00007626 // Try to recover if we have something like sizeof(T::X) where X is a type.
7627 // Notably, there must be *exactly* one set of parens if X is a type.
7628 TypeSourceInfo *RecoveryTSI = nullptr;
7629 ExprResult SubExpr;
7630 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7631 if (auto *DRE =
7632 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7633 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7634 PE, DRE, false, &RecoveryTSI);
7635 else
7636 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7637
7638 if (RecoveryTSI) {
7639 return getDerived().RebuildUnaryExprOrTypeTrait(
7640 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7641 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007642 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007643
Eli Friedmane4f22df2012-02-29 04:03:55 +00007644 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007645 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007646
Peter Collingbournee190dee2011-03-11 19:24:49 +00007647 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7648 E->getOperatorLoc(),
7649 E->getKind(),
7650 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007651}
Mike Stump11289f42009-09-09 15:08:12 +00007652
Douglas Gregora16548e2009-08-11 05:31:07 +00007653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007655TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007656 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007657 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007659
John McCalldadc5752010-08-24 06:29:42 +00007660 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007663
7664
Douglas Gregora16548e2009-08-11 05:31:07 +00007665 if (!getDerived().AlwaysRebuild() &&
7666 LHS.get() == E->getLHS() &&
7667 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007668 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007669
John McCallb268a282010-08-23 23:25:46 +00007670 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007671 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007672 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007673 E->getRBracketLoc());
7674}
Mike Stump11289f42009-09-09 15:08:12 +00007675
7676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007678TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007680 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007681 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007682 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007683
7684 // Transform arguments.
7685 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007686 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007687 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007688 &ArgChanged))
7689 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007690
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 if (!getDerived().AlwaysRebuild() &&
7692 Callee.get() == E->getCallee() &&
7693 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007694 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007695
Douglas Gregora16548e2009-08-11 05:31:07 +00007696 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007697 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007698 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007699 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007700 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007701 E->getRParenLoc());
7702}
Mike Stump11289f42009-09-09 15:08:12 +00007703
7704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007706TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007707 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007708 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007710
Douglas Gregorea972d32011-02-28 21:54:11 +00007711 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007712 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007713 QualifierLoc
7714 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007715
Douglas Gregorea972d32011-02-28 21:54:11 +00007716 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007717 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007718 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007719 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007720
Eli Friedman2cfcef62009-12-04 06:40:45 +00007721 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007722 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7723 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007726
John McCall16df1e52010-03-30 21:47:33 +00007727 NamedDecl *FoundDecl = E->getFoundDecl();
7728 if (FoundDecl == E->getMemberDecl()) {
7729 FoundDecl = Member;
7730 } else {
7731 FoundDecl = cast_or_null<NamedDecl>(
7732 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7733 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007734 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007735 }
7736
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 if (!getDerived().AlwaysRebuild() &&
7738 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007739 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007740 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007741 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007742 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007743
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007744 // Mark it referenced in the new context regardless.
7745 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007746 SemaRef.MarkMemberReferenced(E);
7747
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007748 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007749 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007750
John McCall6b51f282009-11-23 01:53:49 +00007751 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007752 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007753 TransArgs.setLAngleLoc(E->getLAngleLoc());
7754 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007755 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7756 E->getNumTemplateArgs(),
7757 TransArgs))
7758 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007760
Douglas Gregora16548e2009-08-11 05:31:07 +00007761 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007762 SourceLocation FakeOperatorLoc =
7763 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007764
John McCall38836f02010-01-15 08:34:02 +00007765 // FIXME: to do this check properly, we will need to preserve the
7766 // first-qualifier-in-scope here, just in case we had a dependent
7767 // base (and therefore couldn't do the check) and a
7768 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007769 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007770
John McCallb268a282010-08-23 23:25:46 +00007771 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007772 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007773 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007774 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007775 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007776 Member,
John McCall16df1e52010-03-30 21:47:33 +00007777 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007778 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007779 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007780 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007781}
Mike Stump11289f42009-09-09 15:08:12 +00007782
Douglas Gregora16548e2009-08-11 05:31:07 +00007783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007785TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007786 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007787 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007789
John McCalldadc5752010-08-24 06:29:42 +00007790 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007791 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007792 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007793
Douglas Gregora16548e2009-08-11 05:31:07 +00007794 if (!getDerived().AlwaysRebuild() &&
7795 LHS.get() == E->getLHS() &&
7796 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007797 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007798
Lang Hames5de91cc2012-10-02 04:45:10 +00007799 Sema::FPContractStateRAII FPContractState(getSema());
7800 getSema().FPFeatures.fp_contract = E->isFPContractable();
7801
Douglas Gregora16548e2009-08-11 05:31:07 +00007802 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007803 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007804}
7805
Mike Stump11289f42009-09-09 15:08:12 +00007806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007807ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007808TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007809 CompoundAssignOperator *E) {
7810 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007811}
Mike Stump11289f42009-09-09 15:08:12 +00007812
Douglas Gregora16548e2009-08-11 05:31:07 +00007813template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007814ExprResult TreeTransform<Derived>::
7815TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7816 // Just rebuild the common and RHS expressions and see whether we
7817 // get any changes.
7818
7819 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7820 if (commonExpr.isInvalid())
7821 return ExprError();
7822
7823 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7824 if (rhs.isInvalid())
7825 return ExprError();
7826
7827 if (!getDerived().AlwaysRebuild() &&
7828 commonExpr.get() == e->getCommon() &&
7829 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007830 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007831
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007832 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007833 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007834 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007835 e->getColonLoc(),
7836 rhs.get());
7837}
7838
7839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007841TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007842 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007843 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007845
John McCalldadc5752010-08-24 06:29:42 +00007846 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007847 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007849
John McCalldadc5752010-08-24 06:29:42 +00007850 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007851 if (RHS.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 Cond.get() == E->getCond() &&
7856 LHS.get() == E->getLHS() &&
7857 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007858 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007859
John McCallb268a282010-08-23 23:25:46 +00007860 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007861 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007862 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007863 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007864 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007865}
Mike Stump11289f42009-09-09 15:08:12 +00007866
7867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007868ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007869TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007870 // Implicit casts are eliminated during transformation, since they
7871 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007872 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007873}
Mike Stump11289f42009-09-09 15:08:12 +00007874
Douglas Gregora16548e2009-08-11 05:31:07 +00007875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007876ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007877TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007878 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7879 if (!Type)
7880 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007881
John McCalldadc5752010-08-24 06:29:42 +00007882 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007883 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007884 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007886
Douglas Gregora16548e2009-08-11 05:31:07 +00007887 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007888 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007889 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007890 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007891
John McCall97513962010-01-15 18:39:57 +00007892 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007893 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007894 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007895 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007896}
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007900TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007901 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7902 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7903 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007905
John McCalldadc5752010-08-24 06:29:42 +00007906 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007907 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007908 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007909
Douglas Gregora16548e2009-08-11 05:31:07 +00007910 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007911 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007912 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007913 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007914
John McCall5d7aa7f2010-01-19 22:33:45 +00007915 // Note: the expression type doesn't necessarily match the
7916 // type-as-written, but that's okay, because it should always be
7917 // derivable from the initializer.
7918
John McCalle15bbff2010-01-18 19:35:47 +00007919 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007920 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007921 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007922}
Mike Stump11289f42009-09-09 15:08:12 +00007923
Douglas Gregora16548e2009-08-11 05:31:07 +00007924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007926TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007927 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007928 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007930
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 if (!getDerived().AlwaysRebuild() &&
7932 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007933 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007934
Douglas Gregora16548e2009-08-11 05:31:07 +00007935 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007936 SourceLocation FakeOperatorLoc =
7937 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007938 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007939 E->getAccessorLoc(),
7940 E->getAccessor());
7941}
Mike Stump11289f42009-09-09 15:08:12 +00007942
Douglas Gregora16548e2009-08-11 05:31:07 +00007943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007945TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00007946 if (InitListExpr *Syntactic = E->getSyntacticForm())
7947 E = Syntactic;
7948
Douglas Gregora16548e2009-08-11 05:31:07 +00007949 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007950
Benjamin Kramerf0623432012-08-23 22:51:59 +00007951 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007952 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007953 Inits, &InitChanged))
7954 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007955
Richard Smith520449d2015-02-05 06:15:50 +00007956 if (!getDerived().AlwaysRebuild() && !InitChanged) {
7957 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
7958 // in some cases. We can't reuse it in general, because the syntactic and
7959 // semantic forms are linked, and we can't know that semantic form will
7960 // match even if the syntactic form does.
7961 }
Mike Stump11289f42009-09-09 15:08:12 +00007962
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007963 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007964 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007965}
Mike Stump11289f42009-09-09 15:08:12 +00007966
Douglas Gregora16548e2009-08-11 05:31:07 +00007967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007968ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007969TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007970 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007971
Douglas Gregorebe10102009-08-20 07:17:43 +00007972 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007973 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregorebe10102009-08-20 07:17:43 +00007977 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007978 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007979 bool ExprChanged = false;
7980 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7981 DEnd = E->designators_end();
7982 D != DEnd; ++D) {
7983 if (D->isFieldDesignator()) {
7984 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7985 D->getDotLoc(),
7986 D->getFieldLoc()));
7987 continue;
7988 }
Mike Stump11289f42009-09-09 15:08:12 +00007989
Douglas Gregora16548e2009-08-11 05:31:07 +00007990 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007991 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007992 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007994
7995 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007996 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007997
Douglas Gregora16548e2009-08-11 05:31:07 +00007998 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007999 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008000 continue;
8001 }
Mike Stump11289f42009-09-09 15:08:12 +00008002
Douglas Gregora16548e2009-08-11 05:31:07 +00008003 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008004 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008005 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8006 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008008
John McCalldadc5752010-08-24 06:29:42 +00008009 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008012
8013 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008014 End.get(),
8015 D->getLBracketLoc(),
8016 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008017
Douglas Gregora16548e2009-08-11 05:31:07 +00008018 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8019 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008020
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008021 ArrayExprs.push_back(Start.get());
8022 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008023 }
Mike Stump11289f42009-09-09 15:08:12 +00008024
Douglas Gregora16548e2009-08-11 05:31:07 +00008025 if (!getDerived().AlwaysRebuild() &&
8026 Init.get() == E->getInit() &&
8027 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008028 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008029
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008030 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008031 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008032 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008033}
Mike Stump11289f42009-09-09 15:08:12 +00008034
Yunzhong Gaocb779302015-06-10 00:27:52 +00008035// Seems that if TransformInitListExpr() only works on the syntactic form of an
8036// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8037template<typename Derived>
8038ExprResult
8039TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8040 DesignatedInitUpdateExpr *E) {
8041 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8042 "initializer");
8043 return ExprError();
8044}
8045
8046template<typename Derived>
8047ExprResult
8048TreeTransform<Derived>::TransformNoInitExpr(
8049 NoInitExpr *E) {
8050 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8051 return ExprError();
8052}
8053
Douglas Gregora16548e2009-08-11 05:31:07 +00008054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008055ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008056TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008057 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008058 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008059
Douglas Gregor3da3c062009-10-28 00:29:27 +00008060 // FIXME: Will we ever have proper type location here? Will we actually
8061 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008062 QualType T = getDerived().TransformType(E->getType());
8063 if (T.isNull())
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 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008068 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008069
Douglas Gregora16548e2009-08-11 05:31:07 +00008070 return getDerived().RebuildImplicitValueInitExpr(T);
8071}
Mike Stump11289f42009-09-09 15:08:12 +00008072
Douglas Gregora16548e2009-08-11 05:31:07 +00008073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008074ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008075TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008076 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8077 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008079
John McCalldadc5752010-08-24 06:29:42 +00008080 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008081 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008083
Douglas Gregora16548e2009-08-11 05:31:07 +00008084 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008085 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008086 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008087 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008088
John McCallb268a282010-08-23 23:25:46 +00008089 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008090 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008091}
8092
8093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008095TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008096 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008097 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008098 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8099 &ArgumentChanged))
8100 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008101
Douglas Gregora16548e2009-08-11 05:31:07 +00008102 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008103 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008104 E->getRParenLoc());
8105}
Mike Stump11289f42009-09-09 15:08:12 +00008106
Douglas Gregora16548e2009-08-11 05:31:07 +00008107/// \brief Transform an address-of-label expression.
8108///
8109/// By default, the transformation of an address-of-label expression always
8110/// rebuilds the expression, so that the label identifier can be resolved to
8111/// the corresponding label statement by semantic analysis.
8112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008114TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008115 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8116 E->getLabel());
8117 if (!LD)
8118 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008119
Douglas Gregora16548e2009-08-11 05:31:07 +00008120 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008121 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008122}
Mike Stump11289f42009-09-09 15:08:12 +00008123
8124template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008126TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008127 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008128 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008129 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008130 if (SubStmt.isInvalid()) {
8131 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008132 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008133 }
Mike Stump11289f42009-09-09 15:08:12 +00008134
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008136 SubStmt.get() == E->getSubStmt()) {
8137 // Calling this an 'error' is unintuitive, but it does the right thing.
8138 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008139 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008140 }
Mike Stump11289f42009-09-09 15:08:12 +00008141
8142 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008143 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008144 E->getRParenLoc());
8145}
Mike Stump11289f42009-09-09 15:08:12 +00008146
Douglas Gregora16548e2009-08-11 05:31:07 +00008147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008149TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008150 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008151 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008152 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008153
John McCalldadc5752010-08-24 06:29:42 +00008154 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008157
John McCalldadc5752010-08-24 06:29:42 +00008158 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008159 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008161
Douglas Gregora16548e2009-08-11 05:31:07 +00008162 if (!getDerived().AlwaysRebuild() &&
8163 Cond.get() == E->getCond() &&
8164 LHS.get() == E->getLHS() &&
8165 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008166 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008167
Douglas Gregora16548e2009-08-11 05:31:07 +00008168 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008169 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 E->getRParenLoc());
8171}
Mike Stump11289f42009-09-09 15:08:12 +00008172
Douglas Gregora16548e2009-08-11 05:31:07 +00008173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008174ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008175TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008176 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008177}
8178
8179template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008180ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008181TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008182 switch (E->getOperator()) {
8183 case OO_New:
8184 case OO_Delete:
8185 case OO_Array_New:
8186 case OO_Array_Delete:
8187 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008188
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008189 case OO_Call: {
8190 // This is a call to an object's operator().
8191 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8192
8193 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008194 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008195 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008196 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008197
8198 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008199 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8200 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008201
8202 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008203 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008204 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008205 Args))
8206 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008207
John McCallb268a282010-08-23 23:25:46 +00008208 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008209 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008210 E->getLocEnd());
8211 }
8212
8213#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8214 case OO_##Name:
8215#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8216#include "clang/Basic/OperatorKinds.def"
8217 case OO_Subscript:
8218 // Handled below.
8219 break;
8220
8221 case OO_Conditional:
8222 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008223
8224 case OO_None:
8225 case NUM_OVERLOADED_OPERATORS:
8226 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008227 }
8228
John McCalldadc5752010-08-24 06:29:42 +00008229 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008230 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008232
Richard Smithdb2630f2012-10-21 03:28:35 +00008233 ExprResult First;
8234 if (E->getOperator() == OO_Amp)
8235 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8236 else
8237 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008238 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008239 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008240
John McCalldadc5752010-08-24 06:29:42 +00008241 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008242 if (E->getNumArgs() == 2) {
8243 Second = getDerived().TransformExpr(E->getArg(1));
8244 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008245 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008246 }
Mike Stump11289f42009-09-09 15:08:12 +00008247
Douglas Gregora16548e2009-08-11 05:31:07 +00008248 if (!getDerived().AlwaysRebuild() &&
8249 Callee.get() == E->getCallee() &&
8250 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008251 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008252 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008253
Lang Hames5de91cc2012-10-02 04:45:10 +00008254 Sema::FPContractStateRAII FPContractState(getSema());
8255 getSema().FPFeatures.fp_contract = E->isFPContractable();
8256
Douglas Gregora16548e2009-08-11 05:31:07 +00008257 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8258 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008259 Callee.get(),
8260 First.get(),
8261 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008262}
Mike Stump11289f42009-09-09 15:08:12 +00008263
Douglas Gregora16548e2009-08-11 05:31:07 +00008264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008266TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8267 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008268}
Mike Stump11289f42009-09-09 15:08:12 +00008269
Douglas Gregora16548e2009-08-11 05:31:07 +00008270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008271ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008272TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8273 // Transform the callee.
8274 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8275 if (Callee.isInvalid())
8276 return ExprError();
8277
8278 // Transform exec config.
8279 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8280 if (EC.isInvalid())
8281 return ExprError();
8282
8283 // Transform arguments.
8284 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008285 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008286 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008287 &ArgChanged))
8288 return ExprError();
8289
8290 if (!getDerived().AlwaysRebuild() &&
8291 Callee.get() == E->getCallee() &&
8292 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008293 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008294
8295 // FIXME: Wrong source location information for the '('.
8296 SourceLocation FakeLParenLoc
8297 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8298 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008299 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008300 E->getRParenLoc(), EC.get());
8301}
8302
8303template<typename Derived>
8304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008305TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008306 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8307 if (!Type)
8308 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008309
John McCalldadc5752010-08-24 06:29:42 +00008310 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008311 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008312 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008314
Douglas Gregora16548e2009-08-11 05:31:07 +00008315 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008316 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008317 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008318 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008319 return getDerived().RebuildCXXNamedCastExpr(
8320 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8321 Type, E->getAngleBrackets().getEnd(),
8322 // FIXME. this should be '(' location
8323 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008324}
Mike Stump11289f42009-09-09 15:08:12 +00008325
Douglas Gregora16548e2009-08-11 05:31:07 +00008326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008328TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8329 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008330}
Mike Stump11289f42009-09-09 15:08:12 +00008331
8332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008334TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8335 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008336}
8337
Douglas Gregora16548e2009-08-11 05:31:07 +00008338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008339ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008340TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008341 CXXReinterpretCastExpr *E) {
8342 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008343}
Mike Stump11289f42009-09-09 15:08:12 +00008344
Douglas Gregora16548e2009-08-11 05:31:07 +00008345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008346ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008347TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8348 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008349}
Mike Stump11289f42009-09-09 15:08:12 +00008350
Douglas Gregora16548e2009-08-11 05:31:07 +00008351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008352ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008353TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008354 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008355 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8356 if (!Type)
8357 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008358
John McCalldadc5752010-08-24 06:29:42 +00008359 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008360 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008361 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008363
Douglas Gregora16548e2009-08-11 05:31:07 +00008364 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008365 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008366 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008367 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008368
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008369 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008370 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008371 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008372 E->getRParenLoc());
8373}
Mike Stump11289f42009-09-09 15:08:12 +00008374
Douglas Gregora16548e2009-08-11 05:31:07 +00008375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008377TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008378 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008379 TypeSourceInfo *TInfo
8380 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8381 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008383
Douglas Gregora16548e2009-08-11 05:31:07 +00008384 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008385 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008386 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008387
Douglas Gregor9da64192010-04-26 22:37:10 +00008388 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8389 E->getLocStart(),
8390 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008391 E->getLocEnd());
8392 }
Mike Stump11289f42009-09-09 15:08:12 +00008393
Eli Friedman456f0182012-01-20 01:26:23 +00008394 // We don't know whether the subexpression is potentially evaluated until
8395 // after we perform semantic analysis. We speculatively assume it is
8396 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008397 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8399 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008400
John McCalldadc5752010-08-24 06:29:42 +00008401 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008402 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008404
Douglas Gregora16548e2009-08-11 05:31:07 +00008405 if (!getDerived().AlwaysRebuild() &&
8406 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008407 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008408
Douglas Gregor9da64192010-04-26 22:37:10 +00008409 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8410 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008411 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008412 E->getLocEnd());
8413}
8414
8415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008416ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008417TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8418 if (E->isTypeOperand()) {
8419 TypeSourceInfo *TInfo
8420 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8421 if (!TInfo)
8422 return ExprError();
8423
8424 if (!getDerived().AlwaysRebuild() &&
8425 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008426 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008427
Douglas Gregor69735112011-03-06 17:40:41 +00008428 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008429 E->getLocStart(),
8430 TInfo,
8431 E->getLocEnd());
8432 }
8433
Francois Pichet9f4f2072010-09-08 12:20:18 +00008434 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8435
8436 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8437 if (SubExpr.isInvalid())
8438 return ExprError();
8439
8440 if (!getDerived().AlwaysRebuild() &&
8441 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008442 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008443
8444 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8445 E->getLocStart(),
8446 SubExpr.get(),
8447 E->getLocEnd());
8448}
8449
8450template<typename Derived>
8451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008452TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008453 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008454}
Mike Stump11289f42009-09-09 15:08:12 +00008455
Douglas Gregora16548e2009-08-11 05:31:07 +00008456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008457ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008458TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008459 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008460 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008461}
Mike Stump11289f42009-09-09 15:08:12 +00008462
Douglas Gregora16548e2009-08-11 05:31:07 +00008463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008464ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008465TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008466 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008467
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008468 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8469 // Make sure that we capture 'this'.
8470 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008471 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008472 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008473
Douglas Gregorb15af892010-01-07 23:12:05 +00008474 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008475}
Mike Stump11289f42009-09-09 15:08:12 +00008476
Douglas Gregora16548e2009-08-11 05:31:07 +00008477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008478ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008479TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008480 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008481 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008483
Douglas Gregora16548e2009-08-11 05:31:07 +00008484 if (!getDerived().AlwaysRebuild() &&
8485 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008486 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008487
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008488 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8489 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008490}
Mike Stump11289f42009-09-09 15:08:12 +00008491
Douglas Gregora16548e2009-08-11 05:31:07 +00008492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008493ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008494TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008495 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008496 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8497 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008498 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008499 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008500
Chandler Carruth794da4c2010-02-08 06:42:49 +00008501 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008502 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008503 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008504
Douglas Gregor033f6752009-12-23 23:03:06 +00008505 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008506}
Mike Stump11289f42009-09-09 15:08:12 +00008507
Douglas Gregora16548e2009-08-11 05:31:07 +00008508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008509ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008510TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8511 FieldDecl *Field
8512 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8513 E->getField()));
8514 if (!Field)
8515 return ExprError();
8516
8517 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008518 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008519
8520 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8521}
8522
8523template<typename Derived>
8524ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008525TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8526 CXXScalarValueInitExpr *E) {
8527 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8528 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008529 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008530
Douglas Gregora16548e2009-08-11 05:31:07 +00008531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008532 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008533 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008534
Chad Rosier1dcde962012-08-08 18:46:20 +00008535 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008536 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008537 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008538}
Mike Stump11289f42009-09-09 15:08:12 +00008539
Douglas Gregora16548e2009-08-11 05:31:07 +00008540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008541ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008542TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008543 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008544 TypeSourceInfo *AllocTypeInfo
8545 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8546 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008547 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008548
Douglas Gregora16548e2009-08-11 05:31:07 +00008549 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008550 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008551 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008552 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008553
Douglas Gregora16548e2009-08-11 05:31:07 +00008554 // Transform the placement arguments (if any).
8555 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008556 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008557 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008558 E->getNumPlacementArgs(), true,
8559 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008561
Sebastian Redl6047f072012-02-16 12:22:20 +00008562 // Transform the initializer (if any).
8563 Expr *OldInit = E->getInitializer();
8564 ExprResult NewInit;
8565 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008566 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008567 if (NewInit.isInvalid())
8568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008569
Sebastian Redl6047f072012-02-16 12:22:20 +00008570 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008571 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008572 if (E->getOperatorNew()) {
8573 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008574 getDerived().TransformDecl(E->getLocStart(),
8575 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008576 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008577 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008578 }
8579
Craig Topperc3ec1492014-05-26 06:22:03 +00008580 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008581 if (E->getOperatorDelete()) {
8582 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008583 getDerived().TransformDecl(E->getLocStart(),
8584 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008585 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008586 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008587 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008588
Douglas Gregora16548e2009-08-11 05:31:07 +00008589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008590 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008591 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008592 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008593 OperatorNew == E->getOperatorNew() &&
8594 OperatorDelete == E->getOperatorDelete() &&
8595 !ArgumentChanged) {
8596 // Mark any declarations we need as referenced.
8597 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008598 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008599 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008600 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008601 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008602
Sebastian Redl6047f072012-02-16 12:22:20 +00008603 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008604 QualType ElementType
8605 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8606 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8607 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8608 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008609 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008610 }
8611 }
8612 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008613
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008614 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008615 }
Mike Stump11289f42009-09-09 15:08:12 +00008616
Douglas Gregor0744ef62010-09-07 21:49:58 +00008617 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008618 if (!ArraySize.get()) {
8619 // If no array size was specified, but the new expression was
8620 // instantiated with an array type (e.g., "new T" where T is
8621 // instantiated with "int[4]"), extract the outer bound from the
8622 // array type as our array size. We do this with constant and
8623 // dependently-sized array types.
8624 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8625 if (!ArrayT) {
8626 // Do nothing
8627 } else if (const ConstantArrayType *ConsArrayT
8628 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008629 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8630 SemaRef.Context.getSizeType(),
8631 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008632 AllocType = ConsArrayT->getElementType();
8633 } else if (const DependentSizedArrayType *DepArrayT
8634 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8635 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008636 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008637 AllocType = DepArrayT->getElementType();
8638 }
8639 }
8640 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008641
Douglas Gregora16548e2009-08-11 05:31:07 +00008642 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8643 E->isGlobalNew(),
8644 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008645 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008647 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008648 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008649 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008650 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008651 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008652 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008653}
Mike Stump11289f42009-09-09 15:08:12 +00008654
Douglas Gregora16548e2009-08-11 05:31:07 +00008655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008657TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008658 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008659 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008661
Douglas Gregord2d9da02010-02-26 00:38:10 +00008662 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008663 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008664 if (E->getOperatorDelete()) {
8665 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008666 getDerived().TransformDecl(E->getLocStart(),
8667 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008668 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008669 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008670 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008671
Douglas Gregora16548e2009-08-11 05:31:07 +00008672 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008673 Operand.get() == E->getArgument() &&
8674 OperatorDelete == E->getOperatorDelete()) {
8675 // Mark any declarations we need as referenced.
8676 // FIXME: instantiation-specific.
8677 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008678 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008679
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008680 if (!E->getArgument()->isTypeDependent()) {
8681 QualType Destroyed = SemaRef.Context.getBaseElementType(
8682 E->getDestroyedType());
8683 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8684 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008685 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008686 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008687 }
8688 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008689
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008690 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008691 }
Mike Stump11289f42009-09-09 15:08:12 +00008692
Douglas Gregora16548e2009-08-11 05:31:07 +00008693 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8694 E->isGlobalDelete(),
8695 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008696 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008697}
Mike Stump11289f42009-09-09 15:08:12 +00008698
Douglas Gregora16548e2009-08-11 05:31:07 +00008699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008700ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008701TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008702 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008703 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008704 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008706
John McCallba7bf592010-08-24 05:47:05 +00008707 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008708 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008709 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008710 E->getOperatorLoc(),
8711 E->isArrow()? tok::arrow : tok::period,
8712 ObjectTypePtr,
8713 MayBePseudoDestructor);
8714 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008715 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008716
John McCallba7bf592010-08-24 05:47:05 +00008717 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008718 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8719 if (QualifierLoc) {
8720 QualifierLoc
8721 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8722 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008723 return ExprError();
8724 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008725 CXXScopeSpec SS;
8726 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008727
Douglas Gregor678f90d2010-02-25 01:56:36 +00008728 PseudoDestructorTypeStorage Destroyed;
8729 if (E->getDestroyedTypeInfo()) {
8730 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008731 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008732 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008733 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008734 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008735 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008736 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008737 // We aren't likely to be able to resolve the identifier down to a type
8738 // now anyway, so just retain the identifier.
8739 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8740 E->getDestroyedTypeLoc());
8741 } else {
8742 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008743 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008744 *E->getDestroyedTypeIdentifier(),
8745 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008746 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008747 SS, ObjectTypePtr,
8748 false);
8749 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008750 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008751
Douglas Gregor678f90d2010-02-25 01:56:36 +00008752 Destroyed
8753 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8754 E->getDestroyedTypeLoc());
8755 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008756
Craig Topperc3ec1492014-05-26 06:22:03 +00008757 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008758 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008759 CXXScopeSpec EmptySS;
8760 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008761 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008762 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008763 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008765
John McCallb268a282010-08-23 23:25:46 +00008766 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008767 E->getOperatorLoc(),
8768 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008769 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008770 ScopeTypeInfo,
8771 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008772 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008773 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008774}
Mike Stump11289f42009-09-09 15:08:12 +00008775
Douglas Gregorad8a3362009-09-04 17:36:40 +00008776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008777ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008778TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008779 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008780 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8781 Sema::LookupOrdinaryName);
8782
8783 // Transform all the decls.
8784 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8785 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008786 NamedDecl *InstD = static_cast<NamedDecl*>(
8787 getDerived().TransformDecl(Old->getNameLoc(),
8788 *I));
John McCall84d87672009-12-10 09:41:52 +00008789 if (!InstD) {
8790 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8791 // This can happen because of dependent hiding.
8792 if (isa<UsingShadowDecl>(*I))
8793 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008794 else {
8795 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008796 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008797 }
John McCall84d87672009-12-10 09:41:52 +00008798 }
John McCalle66edc12009-11-24 19:00:30 +00008799
8800 // Expand using declarations.
8801 if (isa<UsingDecl>(InstD)) {
8802 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008803 for (auto *I : UD->shadows())
8804 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008805 continue;
8806 }
8807
8808 R.addDecl(InstD);
8809 }
8810
8811 // Resolve a kind, but don't do any further analysis. If it's
8812 // ambiguous, the callee needs to deal with it.
8813 R.resolveKind();
8814
8815 // Rebuild the nested-name qualifier, if present.
8816 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008817 if (Old->getQualifierLoc()) {
8818 NestedNameSpecifierLoc QualifierLoc
8819 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8820 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008821 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008822
Douglas Gregor0da1d432011-02-28 20:01:57 +00008823 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008824 }
8825
Douglas Gregor9262f472010-04-27 18:19:34 +00008826 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008827 CXXRecordDecl *NamingClass
8828 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8829 Old->getNameLoc(),
8830 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008831 if (!NamingClass) {
8832 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008833 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008834 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008835
Douglas Gregorda7be082010-04-27 16:10:10 +00008836 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008837 }
8838
Abramo Bagnara7945c982012-01-27 09:46:47 +00008839 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8840
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008841 // If we have neither explicit template arguments, nor the template keyword,
8842 // it's a normal declaration name.
8843 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008844 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8845
8846 // If we have template arguments, rebuild them, then rebuild the
8847 // templateid expression.
8848 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008849 if (Old->hasExplicitTemplateArgs() &&
8850 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008851 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008852 TransArgs)) {
8853 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008854 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008855 }
John McCalle66edc12009-11-24 19:00:30 +00008856
Abramo Bagnara7945c982012-01-27 09:46:47 +00008857 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008858 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008859}
Mike Stump11289f42009-09-09 15:08:12 +00008860
Douglas Gregora16548e2009-08-11 05:31:07 +00008861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008862ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008863TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8864 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008865 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008866 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8867 TypeSourceInfo *From = E->getArg(I);
8868 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008869 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008870 TypeLocBuilder TLB;
8871 TLB.reserve(FromTL.getFullDataSize());
8872 QualType To = getDerived().TransformType(TLB, FromTL);
8873 if (To.isNull())
8874 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008875
Douglas Gregor29c42f22012-02-24 07:38:34 +00008876 if (To == From->getType())
8877 Args.push_back(From);
8878 else {
8879 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8880 ArgChanged = true;
8881 }
8882 continue;
8883 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008884
Douglas Gregor29c42f22012-02-24 07:38:34 +00008885 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008886
Douglas Gregor29c42f22012-02-24 07:38:34 +00008887 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008888 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008889 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8890 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8891 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008892
Douglas Gregor29c42f22012-02-24 07:38:34 +00008893 // Determine whether the set of unexpanded parameter packs can and should
8894 // be expanded.
8895 bool Expand = true;
8896 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008897 Optional<unsigned> OrigNumExpansions =
8898 ExpansionTL.getTypePtr()->getNumExpansions();
8899 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008900 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8901 PatternTL.getSourceRange(),
8902 Unexpanded,
8903 Expand, RetainExpansion,
8904 NumExpansions))
8905 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008906
Douglas Gregor29c42f22012-02-24 07:38:34 +00008907 if (!Expand) {
8908 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008909 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008910 // expansion.
8911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008912
Douglas Gregor29c42f22012-02-24 07:38:34 +00008913 TypeLocBuilder TLB;
8914 TLB.reserve(From->getTypeLoc().getFullDataSize());
8915
8916 QualType To = getDerived().TransformType(TLB, PatternTL);
8917 if (To.isNull())
8918 return ExprError();
8919
Chad Rosier1dcde962012-08-08 18:46:20 +00008920 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008921 PatternTL.getSourceRange(),
8922 ExpansionTL.getEllipsisLoc(),
8923 NumExpansions);
8924 if (To.isNull())
8925 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008926
Douglas Gregor29c42f22012-02-24 07:38:34 +00008927 PackExpansionTypeLoc ToExpansionTL
8928 = TLB.push<PackExpansionTypeLoc>(To);
8929 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8930 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8931 continue;
8932 }
8933
8934 // Expand the pack expansion by substituting for each argument in the
8935 // pack(s).
8936 for (unsigned I = 0; I != *NumExpansions; ++I) {
8937 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8938 TypeLocBuilder TLB;
8939 TLB.reserve(PatternTL.getFullDataSize());
8940 QualType To = getDerived().TransformType(TLB, PatternTL);
8941 if (To.isNull())
8942 return ExprError();
8943
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008944 if (To->containsUnexpandedParameterPack()) {
8945 To = getDerived().RebuildPackExpansionType(To,
8946 PatternTL.getSourceRange(),
8947 ExpansionTL.getEllipsisLoc(),
8948 NumExpansions);
8949 if (To.isNull())
8950 return ExprError();
8951
8952 PackExpansionTypeLoc ToExpansionTL
8953 = TLB.push<PackExpansionTypeLoc>(To);
8954 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8955 }
8956
Douglas Gregor29c42f22012-02-24 07:38:34 +00008957 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008959
Douglas Gregor29c42f22012-02-24 07:38:34 +00008960 if (!RetainExpansion)
8961 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008962
Douglas Gregor29c42f22012-02-24 07:38:34 +00008963 // If we're supposed to retain a pack expansion, do so by temporarily
8964 // forgetting the partially-substituted parameter pack.
8965 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8966
8967 TypeLocBuilder TLB;
8968 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008969
Douglas Gregor29c42f22012-02-24 07:38:34 +00008970 QualType To = getDerived().TransformType(TLB, PatternTL);
8971 if (To.isNull())
8972 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008973
8974 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008975 PatternTL.getSourceRange(),
8976 ExpansionTL.getEllipsisLoc(),
8977 NumExpansions);
8978 if (To.isNull())
8979 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008980
Douglas Gregor29c42f22012-02-24 07:38:34 +00008981 PackExpansionTypeLoc ToExpansionTL
8982 = TLB.push<PackExpansionTypeLoc>(To);
8983 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8984 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8985 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008986
Douglas Gregor29c42f22012-02-24 07:38:34 +00008987 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008988 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008989
8990 return getDerived().RebuildTypeTrait(E->getTrait(),
8991 E->getLocStart(),
8992 Args,
8993 E->getLocEnd());
8994}
8995
8996template<typename Derived>
8997ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008998TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8999 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9000 if (!T)
9001 return ExprError();
9002
9003 if (!getDerived().AlwaysRebuild() &&
9004 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009005 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009006
9007 ExprResult SubExpr;
9008 {
9009 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9010 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9011 if (SubExpr.isInvalid())
9012 return ExprError();
9013
9014 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009015 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009016 }
9017
9018 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9019 E->getLocStart(),
9020 T,
9021 SubExpr.get(),
9022 E->getLocEnd());
9023}
9024
9025template<typename Derived>
9026ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009027TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9028 ExprResult SubExpr;
9029 {
9030 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9031 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9032 if (SubExpr.isInvalid())
9033 return ExprError();
9034
9035 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009036 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009037 }
9038
9039 return getDerived().RebuildExpressionTrait(
9040 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9041}
9042
Reid Kleckner32506ed2014-06-12 23:03:48 +00009043template <typename Derived>
9044ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9045 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9046 TypeSourceInfo **RecoveryTSI) {
9047 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9048 DRE, AddrTaken, RecoveryTSI);
9049
9050 // Propagate both errors and recovered types, which return ExprEmpty.
9051 if (!NewDRE.isUsable())
9052 return NewDRE;
9053
9054 // We got an expr, wrap it up in parens.
9055 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9056 return PE;
9057 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9058 PE->getRParen());
9059}
9060
9061template <typename Derived>
9062ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9063 DependentScopeDeclRefExpr *E) {
9064 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9065 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009066}
9067
9068template<typename Derived>
9069ExprResult
9070TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9071 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009072 bool IsAddressOfOperand,
9073 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009074 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009075 NestedNameSpecifierLoc QualifierLoc
9076 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9077 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009078 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009079 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009080
John McCall31f82722010-11-12 08:19:04 +00009081 // TODO: If this is a conversion-function-id, verify that the
9082 // destination type name (if present) resolves the same way after
9083 // instantiation as it did in the local scope.
9084
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009085 DeclarationNameInfo NameInfo
9086 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9087 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009088 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009089
John McCalle66edc12009-11-24 19:00:30 +00009090 if (!E->hasExplicitTemplateArgs()) {
9091 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009092 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009093 // Note: it is sufficient to compare the Name component of NameInfo:
9094 // if name has not changed, DNLoc has not changed either.
9095 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009096 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009097
Reid Kleckner32506ed2014-06-12 23:03:48 +00009098 return getDerived().RebuildDependentScopeDeclRefExpr(
9099 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9100 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009101 }
John McCall6b51f282009-11-23 01:53:49 +00009102
9103 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009104 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9105 E->getNumTemplateArgs(),
9106 TransArgs))
9107 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009108
Reid Kleckner32506ed2014-06-12 23:03:48 +00009109 return getDerived().RebuildDependentScopeDeclRefExpr(
9110 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9111 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009112}
9113
9114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009115ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009116TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009117 // CXXConstructExprs other than for list-initialization and
9118 // CXXTemporaryObjectExpr are always implicit, so when we have
9119 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009120 if ((E->getNumArgs() == 1 ||
9121 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009122 (!getDerived().DropCallArgument(E->getArg(0))) &&
9123 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009124 return getDerived().TransformExpr(E->getArg(0));
9125
Douglas Gregora16548e2009-08-11 05:31:07 +00009126 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9127
9128 QualType T = getDerived().TransformType(E->getType());
9129 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009130 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009131
9132 CXXConstructorDecl *Constructor
9133 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009134 getDerived().TransformDecl(E->getLocStart(),
9135 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009136 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009138
Douglas Gregora16548e2009-08-11 05:31:07 +00009139 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009140 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009141 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009142 &ArgumentChanged))
9143 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009144
Douglas Gregora16548e2009-08-11 05:31:07 +00009145 if (!getDerived().AlwaysRebuild() &&
9146 T == E->getType() &&
9147 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009148 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009149 // Mark the constructor as referenced.
9150 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009151 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009152 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009153 }
Mike Stump11289f42009-09-09 15:08:12 +00009154
Douglas Gregordb121ba2009-12-14 16:27:04 +00009155 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9156 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009157 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009158 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009159 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009160 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009161 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009162 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009163 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009164}
Mike Stump11289f42009-09-09 15:08:12 +00009165
Douglas Gregora16548e2009-08-11 05:31:07 +00009166/// \brief Transform a C++ temporary-binding expression.
9167///
Douglas Gregor363b1512009-12-24 18:51:59 +00009168/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9169/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009171ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009172TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009173 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009174}
Mike Stump11289f42009-09-09 15:08:12 +00009175
John McCall5d413782010-12-06 08:20:24 +00009176/// \brief Transform a C++ expression that contains cleanups that should
9177/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009178///
John McCall5d413782010-12-06 08:20:24 +00009179/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009180/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009182ExprResult
John McCall5d413782010-12-06 08:20:24 +00009183TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009184 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009185}
Mike Stump11289f42009-09-09 15:08:12 +00009186
Douglas Gregora16548e2009-08-11 05:31:07 +00009187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009188ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009189TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009190 CXXTemporaryObjectExpr *E) {
9191 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9192 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009194
Douglas Gregora16548e2009-08-11 05:31:07 +00009195 CXXConstructorDecl *Constructor
9196 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009197 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009198 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009199 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009200 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009201
Douglas Gregora16548e2009-08-11 05:31:07 +00009202 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009203 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009204 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009205 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009206 &ArgumentChanged))
9207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009208
Douglas Gregora16548e2009-08-11 05:31:07 +00009209 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009210 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009211 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009212 !ArgumentChanged) {
9213 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009214 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009215 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009217
Richard Smithd59b8322012-12-19 01:39:02 +00009218 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009219 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9220 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009221 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009222 E->getLocEnd());
9223}
Mike Stump11289f42009-09-09 15:08:12 +00009224
Douglas Gregora16548e2009-08-11 05:31:07 +00009225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009226ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009227TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009228 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009229 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009230 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009231 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9232 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009233 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009234 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009235 CEnd = E->capture_end();
9236 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009237 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009238 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009239 EnterExpressionEvaluationContext EEEC(getSema(),
9240 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009241 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9242 C->getCapturedVar()->getInit(),
9243 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009244
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009245 if (NewExprInitResult.isInvalid())
9246 return ExprError();
9247 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009248
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009249 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009250 QualType NewInitCaptureType =
9251 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9252 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009253 NewExprInit);
9254 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009255 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9256 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009257 }
9258
Faisal Vali2cba1332013-10-23 06:44:28 +00009259 // Transform the template parameters, and add them to the current
9260 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009261 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009262 E->getTemplateParameterList());
9263
Richard Smith01014ce2014-11-20 23:53:14 +00009264 // Transform the type of the original lambda's call operator.
9265 // The transformation MUST be done in the CurrentInstantiationScope since
9266 // it introduces a mapping of the original to the newly created
9267 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009268 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009269 {
9270 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9271 FunctionProtoTypeLoc OldCallOpFPTL =
9272 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009273
9274 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009275 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009276 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009277 QualType NewCallOpType = TransformFunctionProtoType(
9278 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009279 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9280 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9281 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009282 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009283 if (NewCallOpType.isNull())
9284 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009285 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9286 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009287 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009288
Richard Smithc38498f2015-04-27 21:27:54 +00009289 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9290 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9291 LSI->GLTemplateParameterList = TPL;
9292
Eli Friedmand564afb2012-09-19 01:18:11 +00009293 // Create the local class that will describe the lambda.
9294 CXXRecordDecl *Class
9295 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009296 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009297 /*KnownDependent=*/false,
9298 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009299 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9300
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009301 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009302 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9303 Class, E->getIntroducerRange(), NewCallOpTSI,
9304 E->getCallOperator()->getLocEnd(),
9305 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009306 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009307
Faisal Vali2cba1332013-10-23 06:44:28 +00009308 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009309 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009310
Douglas Gregorb4328232012-02-14 00:00:48 +00009311 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009312 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009313 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009314
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009315 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009316 getSema().buildLambdaScope(LSI, NewCallOperator,
9317 E->getIntroducerRange(),
9318 E->getCaptureDefault(),
9319 E->getCaptureDefaultLoc(),
9320 E->hasExplicitParameters(),
9321 E->hasExplicitResultType(),
9322 E->isMutable());
9323
9324 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009325
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009326 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009327 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009328 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009329 CEnd = E->capture_end();
9330 C != CEnd; ++C) {
9331 // When we hit the first implicit capture, tell Sema that we've finished
9332 // the list of explicit captures.
9333 if (!FinishedExplicitCaptures && C->isImplicit()) {
9334 getSema().finishLambdaExplicitCaptures(LSI);
9335 FinishedExplicitCaptures = true;
9336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009337
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009338 // Capturing 'this' is trivial.
9339 if (C->capturesThis()) {
9340 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9341 continue;
9342 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009343 // Captured expression will be recaptured during captured variables
9344 // rebuilding.
9345 if (C->capturesVLAType())
9346 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009347
Richard Smithba71c082013-05-16 06:20:58 +00009348 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009349 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009350 InitCaptureInfoTy InitExprTypePair =
9351 InitCaptureExprsAndTypes[C - E->capture_begin()];
9352 ExprResult Init = InitExprTypePair.first;
9353 QualType InitQualType = InitExprTypePair.second;
9354 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009355 Invalid = true;
9356 continue;
9357 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009358 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009359 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9360 OldVD->getLocation(), InitExprTypePair.second,
9361 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009362 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009363 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009364 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009365 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009366 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009367 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009368 continue;
9369 }
9370
9371 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9372
Douglas Gregor3e308b12012-02-14 19:27:52 +00009373 // Determine the capture kind for Sema.
9374 Sema::TryCaptureKind Kind
9375 = C->isImplicit()? Sema::TryCapture_Implicit
9376 : C->getCaptureKind() == LCK_ByCopy
9377 ? Sema::TryCapture_ExplicitByVal
9378 : Sema::TryCapture_ExplicitByRef;
9379 SourceLocation EllipsisLoc;
9380 if (C->isPackExpansion()) {
9381 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9382 bool ShouldExpand = false;
9383 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009384 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009385 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9386 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009387 Unexpanded,
9388 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009389 NumExpansions)) {
9390 Invalid = true;
9391 continue;
9392 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009393
Douglas Gregor3e308b12012-02-14 19:27:52 +00009394 if (ShouldExpand) {
9395 // The transform has determined that we should perform an expansion;
9396 // transform and capture each of the arguments.
9397 // expansion of the pattern. Do so.
9398 VarDecl *Pack = C->getCapturedVar();
9399 for (unsigned I = 0; I != *NumExpansions; ++I) {
9400 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9401 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009402 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009403 Pack));
9404 if (!CapturedVar) {
9405 Invalid = true;
9406 continue;
9407 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009408
Douglas Gregor3e308b12012-02-14 19:27:52 +00009409 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009410 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9411 }
Richard Smith9467be42014-06-06 17:33:35 +00009412
9413 // FIXME: Retain a pack expansion if RetainExpansion is true.
9414
Douglas Gregor3e308b12012-02-14 19:27:52 +00009415 continue;
9416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009417
Douglas Gregor3e308b12012-02-14 19:27:52 +00009418 EllipsisLoc = C->getEllipsisLoc();
9419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009420
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009421 // Transform the captured variable.
9422 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009423 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009424 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009425 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009426 Invalid = true;
9427 continue;
9428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009429
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009430 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009431 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9432 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009433 }
9434 if (!FinishedExplicitCaptures)
9435 getSema().finishLambdaExplicitCaptures(LSI);
9436
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009437 // Enter a new evaluation context to insulate the lambda from any
9438 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009439 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009440
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009441 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009442 StmtResult Body =
9443 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9444
9445 // ActOnLambda* will pop the function scope for us.
9446 FuncScopeCleanup.disable();
9447
Douglas Gregorb4328232012-02-14 00:00:48 +00009448 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009449 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009450 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009451 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009452 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009453 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009454
Richard Smithc38498f2015-04-27 21:27:54 +00009455 // Copy the LSI before ActOnFinishFunctionBody removes it.
9456 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9457 // the call operator.
9458 auto LSICopy = *LSI;
9459 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9460 /*IsInstantiation*/ true);
9461 SavedContext.pop();
9462
9463 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9464 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009465}
9466
9467template<typename Derived>
9468ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009469TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009470 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009471 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9472 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009473 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009474
Douglas Gregora16548e2009-08-11 05:31:07 +00009475 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009476 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009477 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009478 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009479 &ArgumentChanged))
9480 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009481
Douglas Gregora16548e2009-08-11 05:31:07 +00009482 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009483 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009484 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009485 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009486
Douglas Gregora16548e2009-08-11 05:31:07 +00009487 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009488 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009489 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009490 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009491 E->getRParenLoc());
9492}
Mike Stump11289f42009-09-09 15:08:12 +00009493
Douglas Gregora16548e2009-08-11 05:31:07 +00009494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009495ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009496TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009497 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009498 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009499 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009500 Expr *OldBase;
9501 QualType BaseType;
9502 QualType ObjectType;
9503 if (!E->isImplicitAccess()) {
9504 OldBase = E->getBase();
9505 Base = getDerived().TransformExpr(OldBase);
9506 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009508
John McCall2d74de92009-12-01 22:10:20 +00009509 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009510 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009511 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009512 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009513 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009514 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009515 ObjectTy,
9516 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009517 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009518 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009519
John McCallba7bf592010-08-24 05:47:05 +00009520 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009521 BaseType = ((Expr*) Base.get())->getType();
9522 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009523 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009524 BaseType = getDerived().TransformType(E->getBaseType());
9525 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9526 }
Mike Stump11289f42009-09-09 15:08:12 +00009527
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009528 // Transform the first part of the nested-name-specifier that qualifies
9529 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009530 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009531 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009532 E->getFirstQualifierFoundInScope(),
9533 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009534
Douglas Gregore16af532011-02-28 18:50:33 +00009535 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009536 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009537 QualifierLoc
9538 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9539 ObjectType,
9540 FirstQualifierInScope);
9541 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009542 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009543 }
Mike Stump11289f42009-09-09 15:08:12 +00009544
Abramo Bagnara7945c982012-01-27 09:46:47 +00009545 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9546
John McCall31f82722010-11-12 08:19:04 +00009547 // TODO: If this is a conversion-function-id, verify that the
9548 // destination type name (if present) resolves the same way after
9549 // instantiation as it did in the local scope.
9550
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009551 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009552 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009553 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009554 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009555
John McCall2d74de92009-12-01 22:10:20 +00009556 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009557 // This is a reference to a member without an explicitly-specified
9558 // template argument list. Optimize for this common case.
9559 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009560 Base.get() == OldBase &&
9561 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009562 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009563 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009564 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009565 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009566
John McCallb268a282010-08-23 23:25:46 +00009567 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009568 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009569 E->isArrow(),
9570 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009571 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009572 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009573 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009574 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009575 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009576 }
9577
John McCall6b51f282009-11-23 01:53:49 +00009578 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009579 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9580 E->getNumTemplateArgs(),
9581 TransArgs))
9582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009583
John McCallb268a282010-08-23 23:25:46 +00009584 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009585 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009586 E->isArrow(),
9587 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009588 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009589 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009590 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009591 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009592 &TransArgs);
9593}
9594
9595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009597TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009598 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009599 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009600 QualType BaseType;
9601 if (!Old->isImplicitAccess()) {
9602 Base = getDerived().TransformExpr(Old->getBase());
9603 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009604 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009605 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009606 Old->isArrow());
9607 if (Base.isInvalid())
9608 return ExprError();
9609 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009610 } else {
9611 BaseType = getDerived().TransformType(Old->getBaseType());
9612 }
John McCall10eae182009-11-30 22:42:35 +00009613
Douglas Gregor0da1d432011-02-28 20:01:57 +00009614 NestedNameSpecifierLoc QualifierLoc;
9615 if (Old->getQualifierLoc()) {
9616 QualifierLoc
9617 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9618 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009619 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009620 }
9621
Abramo Bagnara7945c982012-01-27 09:46:47 +00009622 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9623
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009624 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009625 Sema::LookupOrdinaryName);
9626
9627 // Transform all the decls.
9628 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9629 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009630 NamedDecl *InstD = static_cast<NamedDecl*>(
9631 getDerived().TransformDecl(Old->getMemberLoc(),
9632 *I));
John McCall84d87672009-12-10 09:41:52 +00009633 if (!InstD) {
9634 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9635 // This can happen because of dependent hiding.
9636 if (isa<UsingShadowDecl>(*I))
9637 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009638 else {
9639 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009640 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009641 }
John McCall84d87672009-12-10 09:41:52 +00009642 }
John McCall10eae182009-11-30 22:42:35 +00009643
9644 // Expand using declarations.
9645 if (isa<UsingDecl>(InstD)) {
9646 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009647 for (auto *I : UD->shadows())
9648 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009649 continue;
9650 }
9651
9652 R.addDecl(InstD);
9653 }
9654
9655 R.resolveKind();
9656
Douglas Gregor9262f472010-04-27 18:19:34 +00009657 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009658 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009659 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009660 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009661 Old->getMemberLoc(),
9662 Old->getNamingClass()));
9663 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009664 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009665
Douglas Gregorda7be082010-04-27 16:10:10 +00009666 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009668
John McCall10eae182009-11-30 22:42:35 +00009669 TemplateArgumentListInfo TransArgs;
9670 if (Old->hasExplicitTemplateArgs()) {
9671 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9672 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009673 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9674 Old->getNumTemplateArgs(),
9675 TransArgs))
9676 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009677 }
John McCall38836f02010-01-15 08:34:02 +00009678
9679 // FIXME: to do this check properly, we will need to preserve the
9680 // first-qualifier-in-scope here, just in case we had a dependent
9681 // base (and therefore couldn't do the check) and a
9682 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009683 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009684
John McCallb268a282010-08-23 23:25:46 +00009685 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009686 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009687 Old->getOperatorLoc(),
9688 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009689 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009690 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009691 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009692 R,
9693 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009694 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009695}
9696
9697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009698ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009699TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009700 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009701 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9702 if (SubExpr.isInvalid())
9703 return ExprError();
9704
9705 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009706 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009707
9708 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9709}
9710
9711template<typename Derived>
9712ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009713TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009714 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9715 if (Pattern.isInvalid())
9716 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009717
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009718 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009719 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009720
Douglas Gregorb8840002011-01-14 21:20:45 +00009721 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9722 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009723}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009724
9725template<typename Derived>
9726ExprResult
9727TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9728 // If E is not value-dependent, then nothing will change when we transform it.
9729 // Note: This is an instantiation-centric view.
9730 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009731 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009732
9733 // Note: None of the implementations of TryExpandParameterPacks can ever
9734 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009735 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009736 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9737 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009738 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009739 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009740 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009741 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009742 ShouldExpand, RetainExpansion,
9743 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009744 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009745
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009746 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009747 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009748
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009749 NamedDecl *Pack = E->getPack();
9750 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009751 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009752 Pack));
9753 if (!Pack)
9754 return ExprError();
9755 }
9756
Chad Rosier1dcde962012-08-08 18:46:20 +00009757
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009758 // We now know the length of the parameter pack, so build a new expression
9759 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009760 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9761 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009762 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009763}
9764
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009765template<typename Derived>
9766ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009767TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9768 SubstNonTypeTemplateParmPackExpr *E) {
9769 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009770 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009771}
9772
9773template<typename Derived>
9774ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009775TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9776 SubstNonTypeTemplateParmExpr *E) {
9777 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009778 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009779}
9780
9781template<typename Derived>
9782ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009783TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9784 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009785 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009786}
9787
9788template<typename Derived>
9789ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009790TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9791 MaterializeTemporaryExpr *E) {
9792 return getDerived().TransformExpr(E->GetTemporaryExpr());
9793}
Chad Rosier1dcde962012-08-08 18:46:20 +00009794
Douglas Gregorfe314812011-06-21 17:03:29 +00009795template<typename Derived>
9796ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009797TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9798 Expr *Pattern = E->getPattern();
9799
9800 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9801 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9802 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9803
9804 // Determine whether the set of unexpanded parameter packs can and should
9805 // be expanded.
9806 bool Expand = true;
9807 bool RetainExpansion = false;
9808 Optional<unsigned> NumExpansions;
9809 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9810 Pattern->getSourceRange(),
9811 Unexpanded,
9812 Expand, RetainExpansion,
9813 NumExpansions))
9814 return true;
9815
9816 if (!Expand) {
9817 // Do not expand any packs here, just transform and rebuild a fold
9818 // expression.
9819 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9820
9821 ExprResult LHS =
9822 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9823 if (LHS.isInvalid())
9824 return true;
9825
9826 ExprResult RHS =
9827 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9828 if (RHS.isInvalid())
9829 return true;
9830
9831 if (!getDerived().AlwaysRebuild() &&
9832 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9833 return E;
9834
9835 return getDerived().RebuildCXXFoldExpr(
9836 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9837 RHS.get(), E->getLocEnd());
9838 }
9839
9840 // The transform has determined that we should perform an elementwise
9841 // expansion of the pattern. Do so.
9842 ExprResult Result = getDerived().TransformExpr(E->getInit());
9843 if (Result.isInvalid())
9844 return true;
9845 bool LeftFold = E->isLeftFold();
9846
9847 // If we're retaining an expansion for a right fold, it is the innermost
9848 // component and takes the init (if any).
9849 if (!LeftFold && RetainExpansion) {
9850 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9851
9852 ExprResult Out = getDerived().TransformExpr(Pattern);
9853 if (Out.isInvalid())
9854 return true;
9855
9856 Result = getDerived().RebuildCXXFoldExpr(
9857 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9858 Result.get(), E->getLocEnd());
9859 if (Result.isInvalid())
9860 return true;
9861 }
9862
9863 for (unsigned I = 0; I != *NumExpansions; ++I) {
9864 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9865 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9866 ExprResult Out = getDerived().TransformExpr(Pattern);
9867 if (Out.isInvalid())
9868 return true;
9869
9870 if (Out.get()->containsUnexpandedParameterPack()) {
9871 // We still have a pack; retain a pack expansion for this slice.
9872 Result = getDerived().RebuildCXXFoldExpr(
9873 E->getLocStart(),
9874 LeftFold ? Result.get() : Out.get(),
9875 E->getOperator(), E->getEllipsisLoc(),
9876 LeftFold ? Out.get() : Result.get(),
9877 E->getLocEnd());
9878 } else if (Result.isUsable()) {
9879 // We've got down to a single element; build a binary operator.
9880 Result = getDerived().RebuildBinaryOperator(
9881 E->getEllipsisLoc(), E->getOperator(),
9882 LeftFold ? Result.get() : Out.get(),
9883 LeftFold ? Out.get() : Result.get());
9884 } else
9885 Result = Out;
9886
9887 if (Result.isInvalid())
9888 return true;
9889 }
9890
9891 // If we're retaining an expansion for a left fold, it is the outermost
9892 // component and takes the complete expansion so far as its init (if any).
9893 if (LeftFold && RetainExpansion) {
9894 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9895
9896 ExprResult Out = getDerived().TransformExpr(Pattern);
9897 if (Out.isInvalid())
9898 return true;
9899
9900 Result = getDerived().RebuildCXXFoldExpr(
9901 E->getLocStart(), Result.get(),
9902 E->getOperator(), E->getEllipsisLoc(),
9903 Out.get(), E->getLocEnd());
9904 if (Result.isInvalid())
9905 return true;
9906 }
9907
9908 // If we had no init and an empty pack, and we're not retaining an expansion,
9909 // then produce a fallback value or error.
9910 if (Result.isUnset())
9911 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9912 E->getOperator());
9913
9914 return Result;
9915}
9916
9917template<typename Derived>
9918ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009919TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9920 CXXStdInitializerListExpr *E) {
9921 return getDerived().TransformExpr(E->getSubExpr());
9922}
9923
9924template<typename Derived>
9925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009926TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009927 return SemaRef.MaybeBindToTemporary(E);
9928}
9929
9930template<typename Derived>
9931ExprResult
9932TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009933 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009934}
9935
9936template<typename Derived>
9937ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009938TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9939 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9940 if (SubExpr.isInvalid())
9941 return ExprError();
9942
9943 if (!getDerived().AlwaysRebuild() &&
9944 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009945 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009946
9947 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009948}
9949
9950template<typename Derived>
9951ExprResult
9952TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9953 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009954 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009955 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009956 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009957 /*IsCall=*/false, Elements, &ArgChanged))
9958 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009959
Ted Kremeneke65b0862012-03-06 20:05:56 +00009960 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9961 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009962
Ted Kremeneke65b0862012-03-06 20:05:56 +00009963 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9964 Elements.data(),
9965 Elements.size());
9966}
9967
9968template<typename Derived>
9969ExprResult
9970TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009971 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009972 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009973 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009974 bool ArgChanged = false;
9975 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9976 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009977
Ted Kremeneke65b0862012-03-06 20:05:56 +00009978 if (OrigElement.isPackExpansion()) {
9979 // This key/value element is a pack expansion.
9980 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9981 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9982 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9983 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9984
9985 // Determine whether the set of unexpanded parameter packs can
9986 // and should be expanded.
9987 bool Expand = true;
9988 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009989 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9990 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009991 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9992 OrigElement.Value->getLocEnd());
9993 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9994 PatternRange,
9995 Unexpanded,
9996 Expand, RetainExpansion,
9997 NumExpansions))
9998 return ExprError();
9999
10000 if (!Expand) {
10001 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010002 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010003 // expansion.
10004 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10005 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10006 if (Key.isInvalid())
10007 return ExprError();
10008
10009 if (Key.get() != OrigElement.Key)
10010 ArgChanged = true;
10011
10012 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10013 if (Value.isInvalid())
10014 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010015
Ted Kremeneke65b0862012-03-06 20:05:56 +000010016 if (Value.get() != OrigElement.Value)
10017 ArgChanged = true;
10018
Chad Rosier1dcde962012-08-08 18:46:20 +000010019 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010020 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10021 };
10022 Elements.push_back(Expansion);
10023 continue;
10024 }
10025
10026 // Record right away that the argument was changed. This needs
10027 // to happen even if the array expands to nothing.
10028 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010029
Ted Kremeneke65b0862012-03-06 20:05:56 +000010030 // The transform has determined that we should perform an elementwise
10031 // expansion of the pattern. Do so.
10032 for (unsigned I = 0; I != *NumExpansions; ++I) {
10033 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10034 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10035 if (Key.isInvalid())
10036 return ExprError();
10037
10038 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10039 if (Value.isInvalid())
10040 return ExprError();
10041
Chad Rosier1dcde962012-08-08 18:46:20 +000010042 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010043 Key.get(), Value.get(), SourceLocation(), NumExpansions
10044 };
10045
10046 // If any unexpanded parameter packs remain, we still have a
10047 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010048 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010049 if (Key.get()->containsUnexpandedParameterPack() ||
10050 Value.get()->containsUnexpandedParameterPack())
10051 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010052
Ted Kremeneke65b0862012-03-06 20:05:56 +000010053 Elements.push_back(Element);
10054 }
10055
Richard Smith9467be42014-06-06 17:33:35 +000010056 // FIXME: Retain a pack expansion if RetainExpansion is true.
10057
Ted Kremeneke65b0862012-03-06 20:05:56 +000010058 // We've finished with this pack expansion.
10059 continue;
10060 }
10061
10062 // Transform and check key.
10063 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10064 if (Key.isInvalid())
10065 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010066
Ted Kremeneke65b0862012-03-06 20:05:56 +000010067 if (Key.get() != OrigElement.Key)
10068 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010069
Ted Kremeneke65b0862012-03-06 20:05:56 +000010070 // Transform and check value.
10071 ExprResult Value
10072 = getDerived().TransformExpr(OrigElement.Value);
10073 if (Value.isInvalid())
10074 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010075
Ted Kremeneke65b0862012-03-06 20:05:56 +000010076 if (Value.get() != OrigElement.Value)
10077 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010078
10079 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010080 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010081 };
10082 Elements.push_back(Element);
10083 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010084
Ted Kremeneke65b0862012-03-06 20:05:56 +000010085 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10086 return SemaRef.MaybeBindToTemporary(E);
10087
10088 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10089 Elements.data(),
10090 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010091}
10092
Mike Stump11289f42009-09-09 15:08:12 +000010093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010095TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010096 TypeSourceInfo *EncodedTypeInfo
10097 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10098 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010100
Douglas Gregora16548e2009-08-11 05:31:07 +000010101 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010102 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010103 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010104
10105 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010106 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010107 E->getRParenLoc());
10108}
Mike Stump11289f42009-09-09 15:08:12 +000010109
Douglas Gregora16548e2009-08-11 05:31:07 +000010110template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010111ExprResult TreeTransform<Derived>::
10112TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010113 // This is a kind of implicit conversion, and it needs to get dropped
10114 // and recomputed for the same general reasons that ImplicitCastExprs
10115 // do, as well a more specific one: this expression is only valid when
10116 // it appears *immediately* as an argument expression.
10117 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010118}
10119
10120template<typename Derived>
10121ExprResult TreeTransform<Derived>::
10122TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010123 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010124 = getDerived().TransformType(E->getTypeInfoAsWritten());
10125 if (!TSInfo)
10126 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010127
John McCall31168b02011-06-15 23:02:42 +000010128 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010129 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010130 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010131
John McCall31168b02011-06-15 23:02:42 +000010132 if (!getDerived().AlwaysRebuild() &&
10133 TSInfo == E->getTypeInfoAsWritten() &&
10134 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010135 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010136
John McCall31168b02011-06-15 23:02:42 +000010137 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010138 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010139 Result.get());
10140}
10141
10142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010144TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010145 // Transform arguments.
10146 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010147 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010148 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010149 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010150 &ArgChanged))
10151 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010152
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010153 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10154 // Class message: transform the receiver type.
10155 TypeSourceInfo *ReceiverTypeInfo
10156 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10157 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010158 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010159
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010160 // If nothing changed, just retain the existing message send.
10161 if (!getDerived().AlwaysRebuild() &&
10162 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010163 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010164
10165 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010166 SmallVector<SourceLocation, 16> SelLocs;
10167 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010168 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10169 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010170 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010171 E->getMethodDecl(),
10172 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010173 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010174 E->getRightLoc());
10175 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010176 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10177 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10178 // Build a new class message send to 'super'.
10179 SmallVector<SourceLocation, 16> SelLocs;
10180 E->getSelectorLocs(SelLocs);
10181 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10182 E->getSelector(),
10183 SelLocs,
10184 E->getMethodDecl(),
10185 E->getLeftLoc(),
10186 Args,
10187 E->getRightLoc());
10188 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010189
10190 // Instance message: transform the receiver
10191 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10192 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010193 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010194 = getDerived().TransformExpr(E->getInstanceReceiver());
10195 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010196 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010197
10198 // If nothing changed, just retain the existing message send.
10199 if (!getDerived().AlwaysRebuild() &&
10200 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010201 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010202
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010203 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010204 SmallVector<SourceLocation, 16> SelLocs;
10205 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010206 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010207 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010208 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010209 E->getMethodDecl(),
10210 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010211 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010212 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010213}
10214
Mike Stump11289f42009-09-09 15:08:12 +000010215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010217TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010218 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010219}
10220
Mike Stump11289f42009-09-09 15:08:12 +000010221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010223TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010224 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010225}
10226
Mike Stump11289f42009-09-09 15:08:12 +000010227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010229TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010230 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010231 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010232 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010233 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010234
10235 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010236
Douglas Gregord51d90d2010-04-26 20:11:03 +000010237 // If nothing changed, just retain the existing expression.
10238 if (!getDerived().AlwaysRebuild() &&
10239 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010240 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010241
John McCallb268a282010-08-23 23:25:46 +000010242 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010243 E->getLocation(),
10244 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010245}
10246
Mike Stump11289f42009-09-09 15:08:12 +000010247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010249TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010250 // 'super' and types never change. Property never changes. Just
10251 // retain the existing expression.
10252 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010253 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010254
Douglas Gregor9faee212010-04-26 20:47:02 +000010255 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010256 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010257 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010258 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010259
Douglas Gregor9faee212010-04-26 20:47:02 +000010260 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010261
Douglas Gregor9faee212010-04-26 20:47:02 +000010262 // If nothing changed, just retain the existing expression.
10263 if (!getDerived().AlwaysRebuild() &&
10264 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010265 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010266
John McCallb7bd14f2010-12-02 01:19:52 +000010267 if (E->isExplicitProperty())
10268 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10269 E->getExplicitProperty(),
10270 E->getLocation());
10271
10272 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010273 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010274 E->getImplicitPropertyGetter(),
10275 E->getImplicitPropertySetter(),
10276 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010277}
10278
Mike Stump11289f42009-09-09 15:08:12 +000010279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010280ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010281TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10282 // Transform the base expression.
10283 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10284 if (Base.isInvalid())
10285 return ExprError();
10286
10287 // Transform the key expression.
10288 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10289 if (Key.isInvalid())
10290 return ExprError();
10291
10292 // If nothing changed, just retain the existing expression.
10293 if (!getDerived().AlwaysRebuild() &&
10294 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010295 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010296
Chad Rosier1dcde962012-08-08 18:46:20 +000010297 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010298 Base.get(), Key.get(),
10299 E->getAtIndexMethodDecl(),
10300 E->setAtIndexMethodDecl());
10301}
10302
10303template<typename Derived>
10304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010305TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010306 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010307 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010308 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010309 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010310
Douglas Gregord51d90d2010-04-26 20:11:03 +000010311 // If nothing changed, just retain the existing expression.
10312 if (!getDerived().AlwaysRebuild() &&
10313 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010314 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010315
John McCallb268a282010-08-23 23:25:46 +000010316 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010317 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010318 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010319}
10320
Mike Stump11289f42009-09-09 15:08:12 +000010321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010323TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010324 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010325 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010326 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010327 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010328 SubExprs, &ArgumentChanged))
10329 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010330
Douglas Gregora16548e2009-08-11 05:31:07 +000010331 if (!getDerived().AlwaysRebuild() &&
10332 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010333 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010334
Douglas Gregora16548e2009-08-11 05:31:07 +000010335 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010336 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010337 E->getRParenLoc());
10338}
10339
Mike Stump11289f42009-09-09 15:08:12 +000010340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010341ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010342TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10343 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10344 if (SrcExpr.isInvalid())
10345 return ExprError();
10346
10347 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10348 if (!Type)
10349 return ExprError();
10350
10351 if (!getDerived().AlwaysRebuild() &&
10352 Type == E->getTypeSourceInfo() &&
10353 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010354 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010355
10356 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10357 SrcExpr.get(), Type,
10358 E->getRParenLoc());
10359}
10360
10361template<typename Derived>
10362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010363TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010364 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010365
Craig Topperc3ec1492014-05-26 06:22:03 +000010366 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010367 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10368
10369 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010370 blockScope->TheDecl->setBlockMissingReturnType(
10371 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010372
Chris Lattner01cf8db2011-07-20 06:58:45 +000010373 SmallVector<ParmVarDecl*, 4> params;
10374 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010375
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010376 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010377 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10378 oldBlock->param_begin(),
10379 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010380 nullptr, paramTypes, &params)) {
10381 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010382 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010383 }
John McCall490112f2011-02-04 18:33:18 +000010384
Jordan Rosea0a86be2013-03-08 22:25:36 +000010385 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010386 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010387 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010388
Jordan Rose5c382722013-03-08 21:51:21 +000010389 QualType functionType =
10390 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010391 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010392 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010393
10394 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010395 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010396 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010397
10398 if (!oldBlock->blockMissingReturnType()) {
10399 blockScope->HasImplicitReturnType = false;
10400 blockScope->ReturnType = exprResultType;
10401 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010402
John McCall3882ace2011-01-05 12:14:39 +000010403 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010404 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010405 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010406 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010407 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010408 }
John McCall3882ace2011-01-05 12:14:39 +000010409
John McCall490112f2011-02-04 18:33:18 +000010410#ifndef NDEBUG
10411 // In builds with assertions, make sure that we captured everything we
10412 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010413 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010414 for (const auto &I : oldBlock->captures()) {
10415 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010416
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010417 // Ignore parameter packs.
10418 if (isa<ParmVarDecl>(oldCapture) &&
10419 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10420 continue;
John McCall490112f2011-02-04 18:33:18 +000010421
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010422 VarDecl *newCapture =
10423 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10424 oldCapture));
10425 assert(blockScope->CaptureMap.count(newCapture));
10426 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010427 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010428 }
10429#endif
10430
10431 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010432 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010433}
10434
Mike Stump11289f42009-09-09 15:08:12 +000010435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010436ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010437TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010438 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010439}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010440
10441template<typename Derived>
10442ExprResult
10443TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010444 QualType RetTy = getDerived().TransformType(E->getType());
10445 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010446 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010447 SubExprs.reserve(E->getNumSubExprs());
10448 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10449 SubExprs, &ArgumentChanged))
10450 return ExprError();
10451
10452 if (!getDerived().AlwaysRebuild() &&
10453 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010454 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010455
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010456 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010457 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010458}
Chad Rosier1dcde962012-08-08 18:46:20 +000010459
Douglas Gregora16548e2009-08-11 05:31:07 +000010460//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010461// Type reconstruction
10462//===----------------------------------------------------------------------===//
10463
Mike Stump11289f42009-09-09 15:08:12 +000010464template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010465QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10466 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010467 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010468 getDerived().getBaseEntity());
10469}
10470
Mike Stump11289f42009-09-09 15:08:12 +000010471template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010472QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10473 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010474 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010475 getDerived().getBaseEntity());
10476}
10477
Mike Stump11289f42009-09-09 15:08:12 +000010478template<typename Derived>
10479QualType
John McCall70dd5f62009-10-30 00:06:24 +000010480TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10481 bool WrittenAsLValue,
10482 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010483 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010484 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010485}
10486
10487template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010488QualType
John McCall70dd5f62009-10-30 00:06:24 +000010489TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10490 QualType ClassType,
10491 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010492 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10493 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010494}
10495
10496template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010497QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010498TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10499 ArrayType::ArraySizeModifier SizeMod,
10500 const llvm::APInt *Size,
10501 Expr *SizeExpr,
10502 unsigned IndexTypeQuals,
10503 SourceRange BracketsRange) {
10504 if (SizeExpr || !Size)
10505 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10506 IndexTypeQuals, BracketsRange,
10507 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010508
10509 QualType Types[] = {
10510 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10511 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10512 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010513 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010514 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010515 QualType SizeType;
10516 for (unsigned I = 0; I != NumTypes; ++I)
10517 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10518 SizeType = Types[I];
10519 break;
10520 }
Mike Stump11289f42009-09-09 15:08:12 +000010521
Eli Friedman9562f392012-01-25 23:20:27 +000010522 // Note that we can return a VariableArrayType here in the case where
10523 // the element type was a dependent VariableArrayType.
10524 IntegerLiteral *ArraySize
10525 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10526 /*FIXME*/BracketsRange.getBegin());
10527 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010528 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010529 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010530}
Mike Stump11289f42009-09-09 15:08:12 +000010531
Douglas Gregord6ff3322009-08-04 16:50:30 +000010532template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010533QualType
10534TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010535 ArrayType::ArraySizeModifier SizeMod,
10536 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010537 unsigned IndexTypeQuals,
10538 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010539 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010540 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010541}
10542
10543template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010544QualType
Mike Stump11289f42009-09-09 15:08:12 +000010545TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010546 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010547 unsigned IndexTypeQuals,
10548 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010549 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010550 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010551}
Mike Stump11289f42009-09-09 15:08:12 +000010552
Douglas Gregord6ff3322009-08-04 16:50:30 +000010553template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010554QualType
10555TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010556 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010557 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010558 unsigned IndexTypeQuals,
10559 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010560 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010561 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010562 IndexTypeQuals, BracketsRange);
10563}
10564
10565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010566QualType
10567TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010568 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010569 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010570 unsigned IndexTypeQuals,
10571 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010572 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010573 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010574 IndexTypeQuals, BracketsRange);
10575}
10576
10577template<typename Derived>
10578QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010579 unsigned NumElements,
10580 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010581 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010582 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010583}
Mike Stump11289f42009-09-09 15:08:12 +000010584
Douglas Gregord6ff3322009-08-04 16:50:30 +000010585template<typename Derived>
10586QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10587 unsigned NumElements,
10588 SourceLocation AttributeLoc) {
10589 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10590 NumElements, true);
10591 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010592 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10593 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010594 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010595}
Mike Stump11289f42009-09-09 15:08:12 +000010596
Douglas Gregord6ff3322009-08-04 16:50:30 +000010597template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010598QualType
10599TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010600 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010601 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010602 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010603}
Mike Stump11289f42009-09-09 15:08:12 +000010604
Douglas Gregord6ff3322009-08-04 16:50:30 +000010605template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010606QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10607 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010608 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010609 const FunctionProtoType::ExtProtoInfo &EPI) {
10610 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010611 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010612 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010613 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010614}
Mike Stump11289f42009-09-09 15:08:12 +000010615
Douglas Gregord6ff3322009-08-04 16:50:30 +000010616template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010617QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10618 return SemaRef.Context.getFunctionNoProtoType(T);
10619}
10620
10621template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010622QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10623 assert(D && "no decl found");
10624 if (D->isInvalidDecl()) return QualType();
10625
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010626 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010627 TypeDecl *Ty;
10628 if (isa<UsingDecl>(D)) {
10629 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010630 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010631 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10632
10633 // A valid resolved using typename decl points to exactly one type decl.
10634 assert(++Using->shadow_begin() == Using->shadow_end());
10635 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010636
John McCallb96ec562009-12-04 22:46:56 +000010637 } else {
10638 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10639 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10640 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10641 }
10642
10643 return SemaRef.Context.getTypeDeclType(Ty);
10644}
10645
10646template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010647QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10648 SourceLocation Loc) {
10649 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010650}
10651
10652template<typename Derived>
10653QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10654 return SemaRef.Context.getTypeOfType(Underlying);
10655}
10656
10657template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010658QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10659 SourceLocation Loc) {
10660 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010661}
10662
10663template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010664QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10665 UnaryTransformType::UTTKind UKind,
10666 SourceLocation Loc) {
10667 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10668}
10669
10670template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010671QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010672 TemplateName Template,
10673 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010674 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010675 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010676}
Mike Stump11289f42009-09-09 15:08:12 +000010677
Douglas Gregor1135c352009-08-06 05:28:30 +000010678template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010679QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10680 SourceLocation KWLoc) {
10681 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10682}
10683
10684template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010685TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010686TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010687 bool TemplateKW,
10688 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010689 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010690 Template);
10691}
10692
10693template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010694TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010695TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10696 const IdentifierInfo &Name,
10697 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010698 QualType ObjectType,
10699 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010700 UnqualifiedId TemplateName;
10701 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010702 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010703 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010704 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010705 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010706 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010707 /*EnteringContext=*/false,
10708 Template);
John McCall31f82722010-11-12 08:19:04 +000010709 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010710}
Mike Stump11289f42009-09-09 15:08:12 +000010711
Douglas Gregora16548e2009-08-11 05:31:07 +000010712template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010713TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010714TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010715 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010716 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010717 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010718 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010719 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010720 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010721 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010722 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010723 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010724 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010725 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010726 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010727 /*EnteringContext=*/false,
10728 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010729 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010730}
Chad Rosier1dcde962012-08-08 18:46:20 +000010731
Douglas Gregor71395fa2009-11-04 00:56:37 +000010732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010733ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010734TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10735 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010736 Expr *OrigCallee,
10737 Expr *First,
10738 Expr *Second) {
10739 Expr *Callee = OrigCallee->IgnoreParenCasts();
10740 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010741
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010742 if (First->getObjectKind() == OK_ObjCProperty) {
10743 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10744 if (BinaryOperator::isAssignmentOp(Opc))
10745 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10746 First, Second);
10747 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10748 if (Result.isInvalid())
10749 return ExprError();
10750 First = Result.get();
10751 }
10752
10753 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10754 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10755 if (Result.isInvalid())
10756 return ExprError();
10757 Second = Result.get();
10758 }
10759
Douglas Gregora16548e2009-08-11 05:31:07 +000010760 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010761 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010762 if (!First->getType()->isOverloadableType() &&
10763 !Second->getType()->isOverloadableType())
10764 return getSema().CreateBuiltinArraySubscriptExpr(First,
10765 Callee->getLocStart(),
10766 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010767 } else if (Op == OO_Arrow) {
10768 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010769 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10770 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010771 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010772 // The argument is not of overloadable type, so try to create a
10773 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010774 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010775 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010776
John McCallb268a282010-08-23 23:25:46 +000010777 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010778 }
10779 } else {
John McCallb268a282010-08-23 23:25:46 +000010780 if (!First->getType()->isOverloadableType() &&
10781 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010782 // Neither of the arguments is an overloadable type, so try to
10783 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010784 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010785 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010786 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010787 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010789
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010790 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010791 }
10792 }
Mike Stump11289f42009-09-09 15:08:12 +000010793
10794 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010795 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010796 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010797
John McCallb268a282010-08-23 23:25:46 +000010798 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010799 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010800 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010801 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010802 // If we've resolved this to a particular non-member function, just call
10803 // that function. If we resolved it to a member function,
10804 // CreateOverloaded* will find that function for us.
10805 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10806 if (!isa<CXXMethodDecl>(ND))
10807 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010808 }
Mike Stump11289f42009-09-09 15:08:12 +000010809
Douglas Gregora16548e2009-08-11 05:31:07 +000010810 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010811 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010812 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010813
Douglas Gregora16548e2009-08-11 05:31:07 +000010814 // Create the overloaded operator invocation for unary operators.
10815 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010816 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010817 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010818 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010819 }
Mike Stump11289f42009-09-09 15:08:12 +000010820
Douglas Gregore9d62932011-07-15 16:25:15 +000010821 if (Op == OO_Subscript) {
10822 SourceLocation LBrace;
10823 SourceLocation RBrace;
10824
10825 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010826 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010827 LBrace = SourceLocation::getFromRawEncoding(
10828 NameLoc.CXXOperatorName.BeginOpNameLoc);
10829 RBrace = SourceLocation::getFromRawEncoding(
10830 NameLoc.CXXOperatorName.EndOpNameLoc);
10831 } else {
10832 LBrace = Callee->getLocStart();
10833 RBrace = OpLoc;
10834 }
10835
10836 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10837 First, Second);
10838 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010839
Douglas Gregora16548e2009-08-11 05:31:07 +000010840 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010841 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010842 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010843 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10844 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010846
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010847 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010848}
Mike Stump11289f42009-09-09 15:08:12 +000010849
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010850template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010851ExprResult
John McCallb268a282010-08-23 23:25:46 +000010852TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010853 SourceLocation OperatorLoc,
10854 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010855 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010856 TypeSourceInfo *ScopeType,
10857 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010858 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010859 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010860 QualType BaseType = Base->getType();
10861 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010862 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010863 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010864 !BaseType->getAs<PointerType>()->getPointeeType()
10865 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010866 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000010867 return SemaRef.BuildPseudoDestructorExpr(
10868 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
10869 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010870 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010871
Douglas Gregor678f90d2010-02-25 01:56:36 +000010872 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010873 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10874 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10875 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10876 NameInfo.setNamedTypeInfo(DestroyedType);
10877
Richard Smith8e4a3862012-05-15 06:15:11 +000010878 // The scope type is now known to be a valid nested name specifier
10879 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010880 if (ScopeType) {
10881 if (!ScopeType->getType()->getAs<TagType>()) {
10882 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10883 diag::err_expected_class_or_namespace)
10884 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10885 return ExprError();
10886 }
10887 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10888 CCLoc);
10889 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010890
Abramo Bagnara7945c982012-01-27 09:46:47 +000010891 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010892 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010893 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010894 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010895 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010896 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010897 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010898}
10899
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010900template<typename Derived>
10901StmtResult
10902TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010903 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010904 CapturedDecl *CD = S->getCapturedDecl();
10905 unsigned NumParams = CD->getNumParams();
10906 unsigned ContextParamPos = CD->getContextParamPosition();
10907 SmallVector<Sema::CapturedParamNameType, 4> Params;
10908 for (unsigned I = 0; I < NumParams; ++I) {
10909 if (I != ContextParamPos) {
10910 Params.push_back(
10911 std::make_pair(
10912 CD->getParam(I)->getName(),
10913 getDerived().TransformType(CD->getParam(I)->getType())));
10914 } else {
10915 Params.push_back(std::make_pair(StringRef(), QualType()));
10916 }
10917 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010918 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010919 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010920 StmtResult Body;
10921 {
10922 Sema::CompoundScopeRAII CompoundScope(getSema());
10923 Body = getDerived().TransformStmt(S->getCapturedStmt());
10924 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010925
10926 if (Body.isInvalid()) {
10927 getSema().ActOnCapturedRegionError();
10928 return StmtError();
10929 }
10930
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010931 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010932}
10933
Douglas Gregord6ff3322009-08-04 16:50:30 +000010934} // end namespace clang
10935
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010936#endif